2004-12-15 05:07:53 +00:00
|
|
|
/*
|
|
|
|
* Notepad
|
|
|
|
*
|
|
|
|
* Copyright 2000 Mike McCormack <Mike_McCormack@looksmart.com.au>
|
|
|
|
* Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
|
|
|
|
* Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-10-27 10:34:16 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-12-15 05:07:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "notepad.h"
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2015-03-01 22:35:47 +00:00
|
|
|
#include <strsafe.h>
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
NOTEPAD_GLOBALS Globals;
|
|
|
|
static ATOM aFINDMSGSTRING;
|
|
|
|
|
2008-01-30 17:20:47 +00:00
|
|
|
VOID NOTEPAD_EnableSearchMenu()
|
|
|
|
{
|
2010-10-06 22:11:12 +00:00
|
|
|
EnableMenuItem(Globals.hMenu, CMD_SEARCH,
|
2008-01-30 17:20:47 +00:00
|
|
|
MF_BYCOMMAND | ((GetWindowTextLength(Globals.hEdit) == 0) ? MF_DISABLED | MF_GRAYED : MF_ENABLED));
|
2010-10-06 22:11:12 +00:00
|
|
|
EnableMenuItem(Globals.hMenu, CMD_SEARCH_NEXT,
|
2008-01-30 17:20:47 +00:00
|
|
|
MF_BYCOMMAND | ((GetWindowTextLength(Globals.hEdit) == 0) ? MF_DISABLED | MF_GRAYED : MF_ENABLED));
|
|
|
|
}
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* SetFileName
|
|
|
|
*
|
|
|
|
* Sets Global File Name.
|
|
|
|
*/
|
2007-10-09 08:53:25 +00:00
|
|
|
VOID SetFileName(LPCTSTR szFileName)
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2015-03-14 20:00:39 +00:00
|
|
|
StringCchCopy(Globals.szFileName, ARRAY_SIZE(Globals.szFileName), szFileName);
|
2004-12-15 05:07:53 +00:00
|
|
|
Globals.szFileTitle[0] = 0;
|
2015-03-14 20:00:39 +00:00
|
|
|
GetFileTitle(szFileName, Globals.szFileTitle, ARRAY_SIZE(Globals.szFileTitle));
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* NOTEPAD_MenuCommand
|
|
|
|
*
|
|
|
|
* All handling of main menu events
|
|
|
|
*/
|
|
|
|
static int NOTEPAD_MenuCommand(WPARAM wParam)
|
|
|
|
{
|
|
|
|
switch (wParam)
|
|
|
|
{
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_NEW: DIALOG_FileNew(); break;
|
|
|
|
case CMD_OPEN: DIALOG_FileOpen(); break;
|
|
|
|
case CMD_SAVE: DIALOG_FileSave(); break;
|
|
|
|
case CMD_SAVE_AS: DIALOG_FileSaveAs(); break;
|
|
|
|
case CMD_PRINT: DIALOG_FilePrint(); break;
|
2015-01-08 13:20:02 +00:00
|
|
|
case CMD_PAGE_SETUP: DIALOG_FilePageSetup(); break;
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_EXIT: DIALOG_FileExit(); break;
|
2015-01-08 13:20:02 +00:00
|
|
|
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_UNDO: DIALOG_EditUndo(); break;
|
|
|
|
case CMD_CUT: DIALOG_EditCut(); break;
|
|
|
|
case CMD_COPY: DIALOG_EditCopy(); break;
|
|
|
|
case CMD_PASTE: DIALOG_EditPaste(); break;
|
|
|
|
case CMD_DELETE: DIALOG_EditDelete(); break;
|
2015-01-08 13:20:02 +00:00
|
|
|
case CMD_SELECT_ALL: DIALOG_EditSelectAll(); break;
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_TIME_DATE: DIALOG_EditTimeDate(); break;
|
2015-01-08 13:20:02 +00:00
|
|
|
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_SEARCH: DIALOG_Search(); break;
|
2015-01-08 13:20:02 +00:00
|
|
|
case CMD_SEARCH_NEXT: DIALOG_SearchNext(); break;
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_REPLACE: DIALOG_Replace(); break;
|
|
|
|
case CMD_GOTO: DIALOG_GoTo(); break;
|
2015-01-08 13:20:02 +00:00
|
|
|
|
|
|
|
case CMD_WRAP: DIALOG_EditWrap(); break;
|
|
|
|
case CMD_FONT: DIALOG_SelectFont(); break;
|
|
|
|
|
|
|
|
case CMD_STATUSBAR: DIALOG_ViewStatusBar(); break;
|
|
|
|
|
|
|
|
case CMD_HELP_CONTENTS: DIALOG_HelpContents(); break;
|
2015-03-14 20:00:39 +00:00
|
|
|
case CMD_HELP_ABOUT_NOTEPAD: DIALOG_HelpAboutNotepad(); break;
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
default:
|
2015-01-08 13:20:02 +00:00
|
|
|
break;
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
2015-01-08 13:20:02 +00:00
|
|
|
return 0;
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
|
2005-09-28 13:20:10 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* NOTEPAD_FindTextAt
|
|
|
|
*/
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
static BOOL
|
|
|
|
NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
|
2005-09-28 13:20:10 +00:00
|
|
|
{
|
|
|
|
BOOL bMatches;
|
2006-06-29 22:32:06 +00:00
|
|
|
size_t iTargetLength;
|
2005-10-23 21:19:34 +00:00
|
|
|
|
2015-03-08 13:16:46 +00:00
|
|
|
if ((!pFindReplace) || (!pszText))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-09-28 13:20:10 +00:00
|
|
|
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
|
|
|
|
|
|
|
|
/* Make proper comparison */
|
|
|
|
if (pFindReplace->Flags & FR_MATCHCASE)
|
|
|
|
bMatches = !_tcsncmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
|
|
|
|
else
|
|
|
|
bMatches = !_tcsnicmp(&pszText[dwPosition], pFindReplace->lpstrFindWhat, iTargetLength);
|
|
|
|
|
|
|
|
if (bMatches && pFindReplace->Flags & FR_WHOLEWORD)
|
|
|
|
{
|
|
|
|
if ((dwPosition > 0) && !_istspace(pszText[dwPosition-1]))
|
|
|
|
bMatches = FALSE;
|
2006-06-29 22:32:06 +00:00
|
|
|
if ((dwPosition < (DWORD) iTextLength - 1) && !_istspace(pszText[dwPosition+1]))
|
2005-09-28 13:20:10 +00:00
|
|
|
bMatches = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bMatches;
|
|
|
|
}
|
|
|
|
|
2005-09-24 23:45:05 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* NOTEPAD_FindNext
|
|
|
|
*/
|
|
|
|
|
2006-03-29 14:51:37 +00:00
|
|
|
BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bShowAlert)
|
2005-09-24 23:45:05 +00:00
|
|
|
{
|
|
|
|
int iTextLength, iTargetLength;
|
2006-06-29 22:32:06 +00:00
|
|
|
size_t iAdjustment = 0;
|
2005-09-24 23:45:05 +00:00
|
|
|
LPTSTR pszText = NULL;
|
2005-09-28 13:20:10 +00:00
|
|
|
DWORD dwPosition, dwBegin, dwEnd;
|
2005-09-24 23:45:05 +00:00
|
|
|
BOOL bMatches = FALSE;
|
2005-09-27 00:46:19 +00:00
|
|
|
TCHAR szResource[128], szText[128];
|
2005-09-27 23:29:35 +00:00
|
|
|
BOOL bSuccess;
|
2005-09-24 23:45:05 +00:00
|
|
|
|
2006-06-29 22:32:06 +00:00
|
|
|
iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
|
2005-09-24 23:45:05 +00:00
|
|
|
|
2005-10-23 21:19:34 +00:00
|
|
|
/* Retrieve the window text */
|
2005-09-24 23:45:05 +00:00
|
|
|
iTextLength = GetWindowTextLength(Globals.hEdit);
|
|
|
|
if (iTextLength > 0)
|
|
|
|
{
|
|
|
|
pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
|
|
|
|
if (!pszText)
|
2005-09-27 23:29:35 +00:00
|
|
|
return FALSE;
|
2005-09-24 23:45:05 +00:00
|
|
|
|
|
|
|
GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
|
|
|
|
}
|
|
|
|
|
2005-09-28 13:20:10 +00:00
|
|
|
SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
|
2006-06-29 22:32:06 +00:00
|
|
|
if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
|
2005-10-23 21:19:34 +00:00
|
|
|
{
|
2005-09-28 13:20:10 +00:00
|
|
|
if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
|
2005-10-23 21:19:34 +00:00
|
|
|
{
|
2005-09-28 13:20:10 +00:00
|
|
|
SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM) pFindReplace->lpstrReplaceWith);
|
|
|
|
iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
|
2005-10-23 21:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2005-09-24 23:45:05 +00:00
|
|
|
|
2005-10-23 21:19:34 +00:00
|
|
|
if (pFindReplace->Flags & FR_DOWN)
|
2005-09-24 23:45:05 +00:00
|
|
|
{
|
2005-10-23 21:19:34 +00:00
|
|
|
/* Find Down */
|
|
|
|
dwPosition = dwEnd;
|
2006-06-29 22:32:06 +00:00
|
|
|
while(dwPosition < (DWORD) iTextLength)
|
2005-10-23 21:19:34 +00:00
|
|
|
{
|
|
|
|
bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
|
|
|
|
if (bMatches)
|
|
|
|
break;
|
2005-09-24 23:45:05 +00:00
|
|
|
dwPosition++;
|
2005-10-23 21:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Find Up */
|
|
|
|
dwPosition = dwBegin;
|
|
|
|
while(dwPosition > 0)
|
|
|
|
{
|
2005-09-24 23:45:05 +00:00
|
|
|
dwPosition--;
|
2005-10-23 21:19:34 +00:00
|
|
|
bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
|
|
|
|
if (bMatches)
|
|
|
|
break;
|
|
|
|
}
|
2005-09-24 23:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bMatches)
|
|
|
|
{
|
2005-09-27 00:46:19 +00:00
|
|
|
/* Found target */
|
2005-09-28 13:20:10 +00:00
|
|
|
if (dwPosition > dwBegin)
|
2006-06-29 22:32:06 +00:00
|
|
|
dwPosition += (DWORD) iAdjustment;
|
2005-09-24 23:45:05 +00:00
|
|
|
SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
|
|
|
|
SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
|
2005-09-27 23:29:35 +00:00
|
|
|
bSuccess = TRUE;
|
2005-09-24 23:45:05 +00:00
|
|
|
}
|
2005-10-23 21:19:34 +00:00
|
|
|
else
|
|
|
|
{
|
2005-09-27 00:46:19 +00:00
|
|
|
/* Can't find target */
|
2005-09-27 23:29:35 +00:00
|
|
|
if (bShowAlert)
|
2005-10-23 21:19:34 +00:00
|
|
|
{
|
2015-03-14 20:00:39 +00:00
|
|
|
LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, ARRAY_SIZE(szResource));
|
|
|
|
_sntprintf(szText, ARRAY_SIZE(szText), szResource, pFindReplace->lpstrFindWhat);
|
|
|
|
LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
|
2005-09-28 22:57:21 +00:00
|
|
|
MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
|
2005-10-23 21:19:34 +00:00
|
|
|
}
|
2005-09-27 23:29:35 +00:00
|
|
|
bSuccess = FALSE;
|
2005-10-23 21:19:34 +00:00
|
|
|
}
|
2005-09-24 23:45:05 +00:00
|
|
|
|
|
|
|
if (pszText)
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszText);
|
2005-09-27 23:29:35 +00:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* NOTEPAD_ReplaceAll
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VOID NOTEPAD_ReplaceAll(FINDREPLACE *pFindReplace)
|
|
|
|
{
|
|
|
|
BOOL bShowAlert = TRUE;
|
|
|
|
|
|
|
|
SendMessage(Globals.hEdit, EM_SETSEL, 0, 0);
|
|
|
|
|
2005-09-28 13:20:10 +00:00
|
|
|
while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert))
|
2005-09-27 23:29:35 +00:00
|
|
|
{
|
|
|
|
bShowAlert = FALSE;
|
2005-10-23 21:19:34 +00:00
|
|
|
}
|
2005-09-24 23:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* NOTEPAD_FindTerm
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VOID NOTEPAD_FindTerm(VOID)
|
|
|
|
{
|
|
|
|
Globals.hFindReplaceDlg = NULL;
|
|
|
|
}
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Data Initialization
|
|
|
|
*/
|
|
|
|
static VOID NOTEPAD_InitData(VOID)
|
|
|
|
{
|
2007-10-09 08:53:25 +00:00
|
|
|
LPTSTR p = Globals.szFilter;
|
|
|
|
static const TCHAR txt_files[] = _T("*.txt");
|
|
|
|
static const TCHAR all_files[] = _T("*.*");
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
p += LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN) + 1;
|
2007-10-09 08:53:25 +00:00
|
|
|
_tcscpy(p, txt_files);
|
2015-03-14 20:00:39 +00:00
|
|
|
p += ARRAY_SIZE(txt_files);
|
2007-10-09 08:53:25 +00:00
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
p += LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN) + 1;
|
2007-10-09 08:53:25 +00:00
|
|
|
_tcscpy(p, all_files);
|
2015-03-14 20:00:39 +00:00
|
|
|
p += ARRAY_SIZE(all_files);
|
2004-12-15 05:07:53 +00:00
|
|
|
*p = '\0';
|
2006-03-29 14:51:37 +00:00
|
|
|
Globals.find.lpstrFindWhat = NULL;
|
2015-03-14 20:00:39 +00:00
|
|
|
|
|
|
|
Globals.hDevMode = NULL;
|
|
|
|
Globals.hDevNames = NULL;
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
|
2005-09-23 06:02:23 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Enable/disable items on the menu based on control state
|
|
|
|
*/
|
2006-06-29 22:32:06 +00:00
|
|
|
static VOID NOTEPAD_InitMenuPopup(HMENU menu, LPARAM index)
|
2005-09-23 06:02:23 +00:00
|
|
|
{
|
|
|
|
int enable;
|
|
|
|
|
2006-06-29 22:32:06 +00:00
|
|
|
UNREFERENCED_PARAMETER(index);
|
|
|
|
|
2005-10-01 00:36:17 +00:00
|
|
|
CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
|
|
|
|
MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
|
2015-03-14 20:00:39 +00:00
|
|
|
if (!Globals.bWrapLongLines)
|
2006-05-03 16:17:12 +00:00
|
|
|
{
|
|
|
|
CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_STATUSBAR,
|
|
|
|
MF_BYCOMMAND | (Globals.bShowStatusBar ? MF_CHECKED : MF_UNCHECKED));
|
|
|
|
}
|
2005-09-23 06:02:23 +00:00
|
|
|
EnableMenuItem(menu, CMD_UNDO,
|
|
|
|
SendMessage(Globals.hEdit, EM_CANUNDO, 0, 0) ? MF_ENABLED : MF_GRAYED);
|
|
|
|
EnableMenuItem(menu, CMD_PASTE,
|
|
|
|
IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED);
|
2006-06-29 22:32:06 +00:00
|
|
|
enable = (int) SendMessage(Globals.hEdit, EM_GETSEL, 0, 0);
|
2005-09-23 06:02:23 +00:00
|
|
|
enable = (HIWORD(enable) == LOWORD(enable)) ? MF_GRAYED : MF_ENABLED;
|
|
|
|
EnableMenuItem(menu, CMD_CUT, enable);
|
|
|
|
EnableMenuItem(menu, CMD_COPY, enable);
|
|
|
|
EnableMenuItem(menu, CMD_DELETE, enable);
|
2006-05-03 16:17:12 +00:00
|
|
|
|
2005-09-23 06:02:23 +00:00
|
|
|
EnableMenuItem(menu, CMD_SELECT_ALL,
|
|
|
|
GetWindowTextLength(Globals.hEdit) ? MF_ENABLED : MF_GRAYED);
|
2006-05-03 16:17:12 +00:00
|
|
|
DrawMenuBar(Globals.hMainWnd);
|
2005-09-23 06:02:23 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 08:49:48 +00:00
|
|
|
LRESULT CALLBACK EDIT_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
2008-11-03 21:23:57 +00:00
|
|
|
case WM_KEYDOWN:
|
2008-01-30 08:49:48 +00:00
|
|
|
case WM_KEYUP:
|
|
|
|
{
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_UP:
|
|
|
|
case VK_DOWN:
|
|
|
|
case VK_LEFT:
|
|
|
|
case VK_RIGHT:
|
|
|
|
DIALOG_StatusBarUpdateCaretPos();
|
|
|
|
break;
|
2015-11-29 18:13:33 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
UpdateWindowCaption(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
2008-01-30 08:49:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
{
|
|
|
|
DIALOG_StatusBarUpdateCaretPos();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 12:39:50 +00:00
|
|
|
return CallWindowProc( Globals.EditProc, hWnd, msg, wParam, lParam);
|
2008-01-30 08:49:48 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* NOTEPAD_WndProc
|
|
|
|
*/
|
2015-01-08 13:20:02 +00:00
|
|
|
static LRESULT
|
|
|
|
WINAPI
|
|
|
|
NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2015-01-08 13:20:02 +00:00
|
|
|
switch (msg)
|
|
|
|
{
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
case WM_CREATE:
|
2010-10-06 22:11:12 +00:00
|
|
|
Globals.hMenu = GetMenu(hWnd);
|
2018-04-24 17:58:46 +00:00
|
|
|
|
|
|
|
// For now, the "Help" dialog is disabled due to the lack of HTML Help support
|
|
|
|
EnableMenuItem(Globals.hMenu, CMD_HELP_CONTENTS, MF_BYCOMMAND | MF_GRAYED);
|
2004-12-15 05:07:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
2006-05-03 16:17:12 +00:00
|
|
|
if (HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == EN_HSCROLL || HIWORD(wParam) == EN_VSCROLL)
|
|
|
|
DIALOG_StatusBarUpdateCaretPos();
|
2008-01-30 17:20:47 +00:00
|
|
|
if ((HIWORD(wParam) == EN_CHANGE))
|
|
|
|
NOTEPAD_EnableSearchMenu();
|
2004-12-15 05:07:53 +00:00
|
|
|
NOTEPAD_MenuCommand(LOWORD(wParam));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROYCLIPBOARD:
|
|
|
|
/*MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
if (DoCloseFile()) {
|
2008-01-30 09:25:54 +00:00
|
|
|
if (Globals.hFont)
|
|
|
|
DeleteObject(Globals.hFont);
|
2015-01-20 12:12:40 +00:00
|
|
|
if (Globals.hDevMode)
|
|
|
|
GlobalFree(Globals.hDevMode);
|
|
|
|
if (Globals.hDevNames)
|
|
|
|
GlobalFree(Globals.hDevNames);
|
2004-12-15 05:07:53 +00:00
|
|
|
DestroyWindow(hWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_QUERYENDSESSION:
|
|
|
|
if (DoCloseFile()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
2008-01-30 08:49:48 +00:00
|
|
|
SetWindowLongPtr(Globals.hEdit, GWLP_WNDPROC, (LONG_PTR)Globals.EditProc);
|
2015-03-14 20:00:39 +00:00
|
|
|
NOTEPAD_SaveSettingsToRegistry();
|
2004-12-15 05:07:53 +00:00
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
2006-06-27 10:02:33 +00:00
|
|
|
{
|
2017-10-01 14:42:04 +00:00
|
|
|
if ((Globals.bShowStatusBar != FALSE) && (Globals.bWrapLongLines == FALSE))
|
2006-06-27 10:02:33 +00:00
|
|
|
{
|
|
|
|
RECT rcStatusBar;
|
|
|
|
HDWP hdwp;
|
|
|
|
|
|
|
|
if (!GetWindowRect(Globals.hStatusBar, &rcStatusBar))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hdwp = BeginDeferWindowPos(2);
|
|
|
|
if (hdwp == NULL)
|
|
|
|
break;
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
hdwp = DeferWindowPos(hdwp,
|
|
|
|
Globals.hEdit,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
LOWORD(lParam),
|
|
|
|
HIWORD(lParam) - (rcStatusBar.bottom - rcStatusBar.top),
|
|
|
|
SWP_NOZORDER | SWP_NOMOVE);
|
|
|
|
|
2006-06-27 10:02:33 +00:00
|
|
|
if (hdwp == NULL)
|
|
|
|
break;
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
hdwp = DeferWindowPos(hdwp,
|
|
|
|
Globals.hStatusBar,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
LOWORD(lParam),
|
|
|
|
LOWORD(wParam),
|
|
|
|
SWP_NOZORDER);
|
2006-06-27 10:02:33 +00:00
|
|
|
|
|
|
|
if (hdwp != NULL)
|
|
|
|
EndDeferWindowPos(hdwp);
|
|
|
|
}
|
|
|
|
else
|
2015-01-08 13:20:02 +00:00
|
|
|
SetWindowPos(Globals.hEdit,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
LOWORD(lParam),
|
|
|
|
HIWORD(lParam),
|
|
|
|
SWP_NOZORDER | SWP_NOMOVE);
|
2006-06-27 10:02:33 +00:00
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
break;
|
2006-06-27 10:02:33 +00:00
|
|
|
}
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
/* The entire client area is covered by edit control and by
|
|
|
|
* the status bar. So there is no need to erase main background.
|
|
|
|
* This resolves the horrible flicker effect during windows resizes. */
|
2010-10-06 22:11:12 +00:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
return 1;
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
case WM_SETFOCUS:
|
|
|
|
SetFocus(Globals.hEdit);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DROPFILES:
|
|
|
|
{
|
2007-10-09 08:53:25 +00:00
|
|
|
TCHAR szFileName[MAX_PATH];
|
2006-12-22 21:49:18 +00:00
|
|
|
HDROP hDrop = (HDROP) wParam;
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2015-03-14 20:00:39 +00:00
|
|
|
DragQueryFile(hDrop, 0, szFileName, ARRAY_SIZE(szFileName));
|
2004-12-15 05:07:53 +00:00
|
|
|
DragFinish(hDrop);
|
|
|
|
DoOpenFile(szFileName);
|
|
|
|
break;
|
|
|
|
}
|
2006-05-03 16:17:12 +00:00
|
|
|
case WM_CHAR:
|
2005-09-23 06:02:23 +00:00
|
|
|
case WM_INITMENUPOPUP:
|
|
|
|
NOTEPAD_InitMenuPopup((HMENU)wParam, lParam);
|
|
|
|
break;
|
2004-12-15 05:07:53 +00:00
|
|
|
default:
|
2005-09-24 23:45:05 +00:00
|
|
|
if (msg == aFINDMSGSTRING)
|
|
|
|
{
|
|
|
|
FINDREPLACE *pFindReplace = (FINDREPLACE *) lParam;
|
2006-03-29 14:51:37 +00:00
|
|
|
Globals.find = *(FINDREPLACE *) lParam;
|
2005-09-24 23:45:05 +00:00
|
|
|
|
|
|
|
if (pFindReplace->Flags & FR_FINDNEXT)
|
2005-09-28 13:20:10 +00:00
|
|
|
NOTEPAD_FindNext(pFindReplace, FALSE, TRUE);
|
2005-09-27 23:29:35 +00:00
|
|
|
else if (pFindReplace->Flags & FR_REPLACE)
|
2005-09-28 13:20:10 +00:00
|
|
|
NOTEPAD_FindNext(pFindReplace, TRUE, TRUE);
|
2005-09-27 23:29:35 +00:00
|
|
|
else if (pFindReplace->Flags & FR_REPLACEALL)
|
|
|
|
NOTEPAD_ReplaceAll(pFindReplace);
|
2005-09-24 23:45:05 +00:00
|
|
|
else if (pFindReplace->Flags & FR_DIALOGTERM)
|
|
|
|
NOTEPAD_FindTerm();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-09 08:53:25 +00:00
|
|
|
static int AlertFileDoesNotExist(LPCTSTR szFileName)
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2015-03-14 20:00:39 +00:00
|
|
|
return DIALOG_StringMsgBox(Globals.hMainWnd, STRING_DOESNOTEXIST,
|
|
|
|
szFileName,
|
|
|
|
MB_ICONEXCLAMATION | MB_YESNO);
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-12-01 14:22:29 +00:00
|
|
|
static BOOL HandleCommandLine(LPTSTR cmdline)
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2015-05-12 10:11:31 +00:00
|
|
|
BOOL opt_print = FALSE;
|
2005-05-08 04:07:56 +00:00
|
|
|
|
2007-10-09 08:53:25 +00:00
|
|
|
while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/'))
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2007-10-09 08:53:25 +00:00
|
|
|
TCHAR option;
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2007-10-09 08:53:25 +00:00
|
|
|
if (*cmdline++ == _T(' ')) continue;
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
option = *cmdline;
|
|
|
|
if (option) cmdline++;
|
2007-10-09 08:53:25 +00:00
|
|
|
while (*cmdline == _T(' ')) cmdline++;
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
switch(option)
|
|
|
|
{
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
2015-05-12 10:11:31 +00:00
|
|
|
opt_print = TRUE;
|
2004-12-15 05:07:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cmdline)
|
|
|
|
{
|
|
|
|
/* file name is passed in the command line */
|
2007-10-09 08:53:25 +00:00
|
|
|
LPCTSTR file_name = NULL;
|
2005-10-24 23:44:07 +00:00
|
|
|
BOOL file_exists = FALSE;
|
2007-10-09 08:53:25 +00:00
|
|
|
TCHAR buf[MAX_PATH];
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2007-10-09 08:53:25 +00:00
|
|
|
if (cmdline[0] == _T('"'))
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
|
|
|
cmdline++;
|
|
|
|
cmdline[lstrlen(cmdline) - 1] = 0;
|
|
|
|
}
|
|
|
|
|
2005-10-28 01:29:55 +00:00
|
|
|
file_name = cmdline;
|
|
|
|
if (FileExists(file_name))
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
|
|
|
file_exists = TRUE;
|
|
|
|
}
|
2005-10-24 23:44:07 +00:00
|
|
|
else if (!HasFileExtension(cmdline))
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2007-10-09 08:53:25 +00:00
|
|
|
static const TCHAR txt[] = _T(".txt");
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
/* try to find file with ".txt" extension */
|
2007-10-09 08:53:25 +00:00
|
|
|
if (!_tcscmp(txt, cmdline + _tcslen(cmdline) - _tcslen(txt)))
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
|
|
|
file_exists = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-09 08:53:25 +00:00
|
|
|
_tcsncpy(buf, cmdline, MAX_PATH - _tcslen(txt) - 1);
|
|
|
|
_tcscat(buf, txt);
|
2004-12-15 05:07:53 +00:00
|
|
|
file_name = buf;
|
2005-10-28 01:29:55 +00:00
|
|
|
file_exists = FileExists(file_name);
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_exists)
|
|
|
|
{
|
|
|
|
DoOpenFile(file_name);
|
|
|
|
InvalidateRect(Globals.hMainWnd, NULL, FALSE);
|
|
|
|
if (opt_print)
|
2013-12-01 14:22:29 +00:00
|
|
|
{
|
2004-12-15 05:07:53 +00:00
|
|
|
DIALOG_FilePrint();
|
2013-12-01 14:22:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (AlertFileDoesNotExist(file_name)) {
|
|
|
|
case IDYES:
|
|
|
|
DoOpenFile(file_name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDNO:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-12-01 14:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* WinMain
|
|
|
|
*/
|
2007-10-09 08:53:25 +00:00
|
|
|
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show)
|
2004-12-15 05:07:53 +00:00
|
|
|
{
|
2015-01-08 13:20:02 +00:00
|
|
|
MSG msg;
|
|
|
|
HACCEL hAccel;
|
|
|
|
WNDCLASSEX wndclass;
|
|
|
|
HMONITOR monitor;
|
2008-01-30 09:25:54 +00:00
|
|
|
MONITORINFO info;
|
2015-01-08 13:20:02 +00:00
|
|
|
INT x, y;
|
2013-12-01 14:22:29 +00:00
|
|
|
|
2015-09-15 07:26:09 +00:00
|
|
|
static const TCHAR className[] = _T("Notepad");
|
2015-01-08 13:20:02 +00:00
|
|
|
static const TCHAR winName[] = _T("Notepad");
|
2013-12-01 14:22:29 +00:00
|
|
|
|
2013-06-16 22:04:48 +00:00
|
|
|
switch (GetUserDefaultUILanguage())
|
2015-01-08 13:20:02 +00:00
|
|
|
{
|
2013-06-16 22:04:48 +00:00
|
|
|
case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
|
2015-01-08 13:20:02 +00:00
|
|
|
SetProcessDefaultLayout(LAYOUT_RTL);
|
|
|
|
break;
|
2008-01-30 09:25:54 +00:00
|
|
|
|
2013-06-16 22:04:48 +00:00
|
|
|
default:
|
2015-01-08 13:20:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2006-06-29 22:32:06 +00:00
|
|
|
UNREFERENCED_PARAMETER(prev);
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
aFINDMSGSTRING = (ATOM)RegisterWindowMessage(FINDMSGSTRING);
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
ZeroMemory(&Globals, sizeof(Globals));
|
2015-01-08 13:20:02 +00:00
|
|
|
Globals.hInstance = hInstance;
|
2015-03-14 20:00:39 +00:00
|
|
|
NOTEPAD_LoadSettingsFromRegistry();
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2006-12-22 21:49:18 +00:00
|
|
|
ZeroMemory(&wndclass, sizeof(wndclass));
|
2015-01-08 13:20:02 +00:00
|
|
|
wndclass.cbSize = sizeof(wndclass);
|
|
|
|
wndclass.lpfnWndProc = NOTEPAD_WndProc;
|
|
|
|
wndclass.hInstance = Globals.hInstance;
|
|
|
|
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NPICON));
|
|
|
|
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
|
2006-12-22 21:49:18 +00:00
|
|
|
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
2015-01-08 13:20:02 +00:00
|
|
|
wndclass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);
|
2006-12-22 21:49:18 +00:00
|
|
|
wndclass.lpszClassName = className;
|
2015-01-08 13:20:02 +00:00
|
|
|
wndclass.hIconSm = (HICON)LoadImage(hInstance,
|
|
|
|
MAKEINTRESOURCE(IDI_NPICON),
|
|
|
|
IMAGE_ICON,
|
|
|
|
16,
|
|
|
|
16,
|
|
|
|
0);
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2006-12-22 21:49:18 +00:00
|
|
|
if (!RegisterClassEx(&wndclass)) return FALSE;
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
/* Setup windows */
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
monitor = MonitorFromRect(&Globals.main_rect, MONITOR_DEFAULTTOPRIMARY);
|
2008-01-30 09:25:54 +00:00
|
|
|
info.cbSize = sizeof(info);
|
2015-01-08 13:20:02 +00:00
|
|
|
GetMonitorInfoW(monitor, &info);
|
2008-01-30 09:25:54 +00:00
|
|
|
|
|
|
|
x = Globals.main_rect.left;
|
|
|
|
y = Globals.main_rect.top;
|
|
|
|
if (Globals.main_rect.left >= info.rcWork.right ||
|
|
|
|
Globals.main_rect.top >= info.rcWork.bottom ||
|
|
|
|
Globals.main_rect.right < info.rcWork.left ||
|
|
|
|
Globals.main_rect.bottom < info.rcWork.top)
|
|
|
|
x = y = CW_USEDEFAULT;
|
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
Globals.hMainWnd = CreateWindow(className,
|
|
|
|
winName,
|
|
|
|
WS_OVERLAPPEDWINDOW,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
Globals.main_rect.right - Globals.main_rect.left,
|
|
|
|
Globals.main_rect.bottom - Globals.main_rect.top,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
Globals.hInstance,
|
|
|
|
NULL);
|
2004-12-15 05:07:53 +00:00
|
|
|
if (!Globals.hMainWnd)
|
|
|
|
{
|
|
|
|
ShowLastError();
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
2010-10-06 22:11:12 +00:00
|
|
|
DoCreateEditWindow();
|
|
|
|
|
2004-12-15 05:07:53 +00:00
|
|
|
NOTEPAD_InitData();
|
|
|
|
DIALOG_FileNew();
|
|
|
|
|
|
|
|
ShowWindow(Globals.hMainWnd, show);
|
|
|
|
UpdateWindow(Globals.hMainWnd);
|
|
|
|
DragAcceptFiles(Globals.hMainWnd, TRUE);
|
|
|
|
|
2008-01-30 08:49:48 +00:00
|
|
|
DIALOG_ViewStatusBar();
|
|
|
|
|
2013-12-01 14:22:29 +00:00
|
|
|
if (!HandleCommandLine(cmdline))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-15 05:07:53 +00:00
|
|
|
|
2015-01-08 13:20:02 +00:00
|
|
|
hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));
|
2004-12-15 05:07:53 +00:00
|
|
|
|
|
|
|
while (GetMessage(&msg, 0, 0, 0))
|
|
|
|
{
|
2005-09-23 18:15:39 +00:00
|
|
|
if (!IsDialogMessage(Globals.hFindReplaceDlg, &msg) &&
|
|
|
|
!TranslateAccelerator(Globals.hMainWnd, hAccel, &msg))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|
2006-06-29 22:32:06 +00:00
|
|
|
return (int) msg.wParam;
|
2004-12-15 05:07:53 +00:00
|
|
|
}
|