*
*/
-#define UNICODE
-#define _UNICODE
-
-#define _CRT_SECURE_NO_DEPRECATE
-
-#include <windows.h>
-#include <stdio.h>
-#include <tchar.h>
-
-#include "main.h"
-#include "dialog.h"
-#include "notepad_res.h"
+#include <notepad.h>
NOTEPAD_GLOBALS Globals;
static ATOM aFINDMSGSTRING;
case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
default:
- break;
+ break;
}
return 0;
}
{
BOOL bMatches;
int iTargetLength;
-
+
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
/* Make proper comparison */
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
+ /* Retrieve the window text */
iTextLength = GetWindowTextLength(Globals.hEdit);
-
if (iTextLength > 0)
{
pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
if (bReplace && ((dwEnd - dwBegin) == iTargetLength))
- {
+ {
if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
- {
+ {
SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM) pFindReplace->lpstrReplaceWith);
iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
- }
- }
+ }
+ }
- dwPosition = dwEnd;
- while(dwPosition < iTextLength)
+ if (pFindReplace->Flags & FR_DOWN)
{
- bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
- if (bMatches)
- break;
-
- if (pFindReplace->Flags & FR_DOWN)
+ /* Find Down */
+ dwPosition = dwEnd;
+ while(dwPosition < iTextLength)
+ {
+ bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
+ if (bMatches)
+ break;
dwPosition++;
- else
+ }
+ }
+ else
+ {
+ /* Find Up */
+ dwPosition = dwBegin;
+ while(dwPosition > 0)
+ {
dwPosition--;
+ bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
+ if (bMatches)
+ break;
+ }
}
if (bMatches)
SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
bSuccess = TRUE;
}
- else
- {
+ else
+ {
/* Can't find target */
if (bShowAlert)
- {
+ {
LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, SIZEOF(szResource));
_sntprintf(szText, SIZEOF(szText), szResource, pFindReplace->lpstrFindWhat);
LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
- }
+ }
bSuccess = FALSE;
- }
+ }
if (pszText)
HeapFree(GetProcessHeap(), 0, pszText);
while (NOTEPAD_FindNext(pFindReplace, TRUE, bShowAlert))
{
bShowAlert = FALSE;
- }
+ }
}
/***********************************************************************
if (*cmdline)
{
/* file name is passed in the command line */
- LPCWSTR file_name;
- BOOL file_exists;
+ LPCWSTR file_name = NULL;
+ BOOL file_exists = FALSE;
WCHAR buf[MAX_PATH];
if (cmdline[0] == '"')
cmdline[lstrlen(cmdline) - 1] = 0;
}
- if (FileExists(cmdline))
+ file_name = cmdline;
+ if (FileExists(file_name))
{
file_exists = TRUE;
- file_name = cmdline;
}
- else
+ else if (!HasFileExtension(cmdline))
{
static const WCHAR txtW[] = { '.','t','x','t',0 };
if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW)))
{
file_exists = FALSE;
- file_name = cmdline;
}
else
{
lstrcpyn(buf, cmdline, MAX_PATH - lstrlen(txtW) - 1);
lstrcat(buf, txtW);
file_name = buf;
- file_exists = FileExists(buf);
+ file_exists = FileExists(file_name);
}
}