>From 6dc7a289ccf1567a87dfca66a86ace0f509621ff Mon Sep 17 00:00:00 2001
From: Elias Benali <elptr(a)users.sourceforge.net>
Date: Sat, 25 Oct 2008 21:09:27 -0400
Subject: wordpad: Make the Replace function work and the Find/Replace dialogs
behave like expected.
The "Find What" field is filled from the current selection in the
document, if any.
---
programs/wordpad/wordpad.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/programs/wordpad/wordpad.c b/programs/wordpad/wordpad.c
index d06b2d9..434b6fd 100644
--- a/programs/wordpad/wordpad.c
+++ b/programs/wordpad/wordpad.c
@@ -49,6 +49,10 @@
# define U3(x) (x)
#endif
+#ifndef MIN
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
/* use LoadString */
static const WCHAR wszAppTitle[] = {'W','i','n','e','
','W','o','r','d','p','a','d',0};
@@ -1281,12 +1285,29 @@ static LRESULT handle_findmsg(LPFINDREPLACEW pFr)
static void dialog_find(LPFINDREPLACEW fr, BOOL replace)
{
static WCHAR findBuffer[MAX_STRING_LEN];
+ static WCHAR replaceBuffer[MAX_STRING_LEN];
+ CHARRANGE cr;
+ TEXTRANGE tr;
+
+ SendMessage(hEditorWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
+ if (cr.cpMax > cr.cpMin) {
+ cr.cpMax = cr.cpMin +
MIN(sizeof(findBuffer)/sizeof(WCHAR)-1, cr.cpMax-cr.cpMin);
+ tr.chrg = cr;
+ tr.lpstrText = (LPSTR)findBuffer;
+ SendMessage(hEditorWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
+ } else
+ findBuffer[0] = '\0';
+
+ replaceBuffer[0] = '\0';
ZeroMemory(fr, sizeof(FINDREPLACEW));
fr->lStructSize = sizeof(FINDREPLACEW);
fr->hwndOwner = hMainWnd;
fr->Flags = FR_HIDEUPDOWN;
fr->lpstrFindWhat = findBuffer;
+ fr->wFindWhatLen = sizeof(findBuffer);
+ fr->wReplaceWithLen = sizeof(replaceBuffer); /* ignored by FindTextW() */
+ fr->lpstrReplaceWith = replaceBuffer; /* ignored by FindTextW() */
fr->lCustData = -1;
fr->wFindWhatLen = MAX_STRING_LEN*sizeof(WCHAR);
--
1.6.0.2