Notepad: Fixed "Find Up"

svn path=/trunk/; revision=18726
This commit is contained in:
Nathan Woods 2005-10-23 21:19:34 +00:00
parent fd37360789
commit 1184c4d49e

View file

@ -94,7 +94,7 @@ static int NOTEPAD_MenuCommand(WPARAM wParam)
case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break; case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
default: default:
break; break;
} }
return 0; return 0;
} }
@ -108,7 +108,7 @@ static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int i
{ {
BOOL bMatches; BOOL bMatches;
int iTargetLength; int iTargetLength;
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat); iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
/* Make proper comparison */ /* Make proper comparison */
@ -145,8 +145,8 @@ static BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bSho
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat); iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
/* Retrieve the window text */
iTextLength = GetWindowTextLength(Globals.hEdit); iTextLength = GetWindowTextLength(Globals.hEdit);
if (iTextLength > 0) if (iTextLength > 0)
{ {
pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR)); pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
@ -158,25 +158,37 @@ static BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bSho
SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd); SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
if (bReplace && ((dwEnd - dwBegin) == iTargetLength)) if (bReplace && ((dwEnd - dwBegin) == iTargetLength))
{ {
if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin)) if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
{ {
SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM) pFindReplace->lpstrReplaceWith); SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM) pFindReplace->lpstrReplaceWith);
iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin); iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
} }
} }
dwPosition = dwEnd; if (pFindReplace->Flags & FR_DOWN)
while(dwPosition < iTextLength)
{ {
bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition); /* Find Down */
if (bMatches) dwPosition = dwEnd;
break; while(dwPosition < iTextLength)
{
if (pFindReplace->Flags & FR_DOWN) bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
if (bMatches)
break;
dwPosition++; dwPosition++;
else }
}
else
{
/* Find Up */
dwPosition = dwBegin;
while(dwPosition > 0)
{
dwPosition--; dwPosition--;
bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
if (bMatches)
break;
}
} }
if (bMatches) if (bMatches)
@ -188,18 +200,18 @@ static BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL bReplace, BOOL bSho
SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0); SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
bSuccess = TRUE; bSuccess = TRUE;
} }
else else
{ {
/* Can't find target */ /* Can't find target */
if (bShowAlert) if (bShowAlert)
{ {
LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, SIZEOF(szResource)); LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, SIZEOF(szResource));
_sntprintf(szText, SIZEOF(szText), szResource, pFindReplace->lpstrFindWhat); _sntprintf(szText, SIZEOF(szText), szResource, pFindReplace->lpstrFindWhat);
LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK); MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
} }
bSuccess = FALSE; bSuccess = FALSE;
} }
if (pszText) if (pszText)
HeapFree(GetProcessHeap(), 0, pszText); HeapFree(GetProcessHeap(), 0, pszText);
@ -220,7 +232,7 @@ static VOID NOTEPAD_ReplaceAll(FINDREPLACE *pFindReplace)
while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert)) while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert))
{ {
bShowAlert = FALSE; bShowAlert = FALSE;
} }
} }
/*********************************************************************** /***********************************************************************