Notepad enhancements:
1. Removed the 30k limit
2. Implemented Replace and Replace All
Modified: trunk/reactos/subsys/system/notepad/main.c
_____
Modified: trunk/reactos/subsys/system/notepad/main.c
--- trunk/reactos/subsys/system/notepad/main.c 2005-09-27 21:49:18 UTC
(rev 18130)
+++ trunk/reactos/subsys/system/notepad/main.c 2005-09-27 23:29:35 UTC
(rev 18131)
@@ -102,13 +102,14 @@
* NOTEPAD_FindNext
*/
-static VOID NOTEPAD_FindNext(FINDREPLACE *pFindReplace)
+static BOOL NOTEPAD_FindNext(FINDREPLACE *pFindReplace, BOOL
bShowAlert)
{
int iTextLength, iTargetLength;
LPTSTR pszText = NULL;
DWORD dwPosition, dwDummy;
BOOL bMatches = FALSE;
TCHAR szResource[128], szText[128];
+ BOOL bSuccess;
iTargetLength = _tcslen(pFindReplace->lpstrFindWhat);
@@ -118,7 +119,7 @@
{
pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength
+ 1) * sizeof(TCHAR));
if (!pszText)
- return;
+ return FALSE;
GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
}
@@ -155,22 +156,57 @@
/* Found target */
SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition +
iTargetLength);
SendMessage(Globals.hEdit, EM_SCROLLCARET, 0, 0);
+ bSuccess = TRUE;
}
else
{
/* Can't find target */
- 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.hEdit, szText, szResource, MB_OK);
+ 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.hEdit, szText, szResource, MB_OK);
+ }
+ bSuccess = FALSE;
}
if (pszText)
HeapFree(GetProcessHeap(), 0, pszText);
+ return bSuccess;
}
/***********************************************************************
*
+ * NOTEPAD_Replace
+ */
+
+static VOID NOTEPAD_Replace(FINDREPLACE *pFindReplace)
+{
+ if (NOTEPAD_FindNext(pFindReplace, TRUE))
+ SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)
pFindReplace->lpstrReplaceWith);
+}
+
+/**********************************************************************
*
+ *
+ * NOTEPAD_ReplaceAll
+ */
+
+static VOID NOTEPAD_ReplaceAll(FINDREPLACE *pFindReplace)
+{
+ BOOL bShowAlert = TRUE;
+
+ SendMessage(Globals.hEdit, EM_SETSEL, 0, 0);
+
+ while (NOTEPAD_FindNext(pFindReplace, bShowAlert))
+ {
+ SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)
pFindReplace->lpstrReplaceWith);
+ bShowAlert = FALSE;
+ }
+}
+
+/**********************************************************************
*
+ *
* NOTEPAD_FindTerm
*/
@@ -237,6 +273,9 @@
Globals.hEdit = CreateWindowEx(EDIT_EXSTYLE, editW, NULL,
EDIT_STYLE,
0, 0, rc.right, rc.bottom, hWnd,
NULL, Globals.hInstance, NULL);
+ if (!Globals.hEdit)
+ return -1;
+ SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0);
break;
}
@@ -294,7 +333,11 @@
FINDREPLACE *pFindReplace = (FINDREPLACE *) lParam;
if (pFindReplace->Flags & FR_FINDNEXT)
- NOTEPAD_FindNext(pFindReplace);
+ NOTEPAD_FindNext(pFindReplace, TRUE);
+ else if (pFindReplace->Flags & FR_REPLACE)
+ NOTEPAD_Replace(pFindReplace);
+ else if (pFindReplace->Flags & FR_REPLACEALL)
+ NOTEPAD_ReplaceAll(pFindReplace);
else if (pFindReplace->Flags & FR_DIALOGTERM)
NOTEPAD_FindTerm();
break;