Mikołaj Zalewski : notepad: Implement Find and Find Next.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Oct 23 10:01:37 CDT 2006


Module: wine
Branch: master
Commit: 84fc75c3d2910902a5c53e86caa5bc58a99b851c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=84fc75c3d2910902a5c53e86caa5bc58a99b851c

Author: Mikołaj Zalewski <mikolaj at zalewski.pl>
Date:   Sun Oct 22 18:58:12 2006 +0200

notepad: Implement Find and Find Next.

---

 programs/notepad/dialog.c |    8 +++--
 programs/notepad/main.c   |   76 ++++++++++++++++++++++++++++++++++++++++++++-
 programs/notepad/main.h   |    2 +
 3 files changed, 82 insertions(+), 4 deletions(-)

diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c
index 9f822d4..c72e01f 100644
--- a/programs/notepad/dialog.c
+++ b/programs/notepad/dialog.c
@@ -663,7 +663,7 @@ VOID DIALOG_Search(VOID)
         Globals.find.hInstance        = Globals.hInstance;
         Globals.find.lpstrFindWhat    = Globals.szFindText;
         Globals.find.wFindWhatLen     = SIZEOF(Globals.szFindText);
-        Globals.find.Flags            = FR_DOWN;
+        Globals.find.Flags            = FR_DOWN|FR_HIDEWHOLEWORD;
 
         /* We only need to create the modal FindReplace dialog which will */
         /* notify us of incoming events using hMainWnd Window Messages    */
@@ -674,8 +674,10 @@ VOID DIALOG_Search(VOID)
 
 VOID DIALOG_SearchNext(VOID)
 {
-    /* FIXME: Search Next */
-    DIALOG_Search();
+    if (Globals.lastFind.lpstrFindWhat == NULL)
+        DIALOG_Search();
+    else                /* use the last find data */
+        NOTEPAD_DoFind(&Globals.lastFind);
 }
 
 VOID DIALOG_HelpContents(VOID)
diff --git a/programs/notepad/main.c b/programs/notepad/main.c
index 33c82b2..3ffa14b 100644
--- a/programs/notepad/main.c
+++ b/programs/notepad/main.c
@@ -25,6 +25,7 @@
 #define UNICODE
 
 #include <windows.h>
+#include <shlwapi.h>
 #include <stdio.h>
 
 #include "main.h"
@@ -314,6 +315,65 @@ static VOID NOTEPAD_InitMenuPopup(HMENU 
         GetWindowTextLength(Globals.hEdit) ? MF_ENABLED : MF_GRAYED);
 }
 
+static LPTSTR NOTEPAD_StrRStr(LPTSTR pszSource, LPTSTR pszLast, LPTSTR pszSrch)
+{
+    int len = lstrlen(pszSrch);
+    pszLast--;
+    while (pszLast >= pszSource)
+    {
+        if (StrCmpN(pszLast, pszSrch, len) == 0)
+            return pszLast;
+        pszLast--;
+    }
+    return NULL;
+}
+
+/***********************************************************************
+ * The user activated the Find dialog
+ */
+void NOTEPAD_DoFind(FINDREPLACE *fr)
+{
+    LPTSTR content;
+    LPTSTR found;
+    int len = lstrlen(fr->lpstrFindWhat);
+    int fileLen;
+    DWORD pos;
+    
+    fileLen = GetWindowTextLength(Globals.hEdit) + 1;
+    content = HeapAlloc(GetProcessHeap(), 0, fileLen * sizeof(TCHAR));
+    if (!content) return;
+    GetWindowText(Globals.hEdit, content, fileLen);
+
+    SendMessage(Globals.hEdit, EM_GETSEL, 0, (LPARAM)&pos);        
+    switch (fr->Flags & (FR_DOWN|FR_MATCHCASE))
+    {
+        case 0:
+            found = StrRStrI(content, content+pos-len, fr->lpstrFindWhat);
+            break;
+        case FR_DOWN:
+            found = StrStrI(content+pos, fr->lpstrFindWhat);
+            break;
+        case FR_MATCHCASE:
+            found = NOTEPAD_StrRStr(content, content+pos-len, fr->lpstrFindWhat);
+            break;
+        case FR_DOWN|FR_MATCHCASE:
+            found = StrStr(content+pos, fr->lpstrFindWhat);
+            break;
+        default:    /* shouldn't happen */
+            return;
+    }
+    HeapFree(GetProcessHeap(), 0, content);
+
+    if (found == NULL)
+    {
+        DIALOG_StringMsgBox(Globals.hFindReplaceDlg, STRING_NOTFOUND, fr->lpstrFindWhat,
+            MB_ICONINFORMATION|MB_OK);
+        return;
+    }
+
+    SendMessage(Globals.hEdit, EM_SETSEL, found - content, found - content + len);
+}
+
 /***********************************************************************
  *
  *           NOTEPAD_WndProc
@@ -321,13 +381,27 @@ static VOID NOTEPAD_InitMenuPopup(HMENU 
 static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
                                LPARAM lParam)
 {
+    if (msg == aFINDMSGSTRING)      /* not a constant so can't be used in switch */
+    {
+        FINDREPLACE *fr = (FINDREPLACE *)lParam;
+        
+        if (fr->Flags & FR_DIALOGTERM)
+            Globals.hFindReplaceDlg = NULL;
+        if (fr->Flags & FR_FINDNEXT)
+        {
+            Globals.lastFind = *fr;
+            NOTEPAD_DoFind(fr);
+        }
+        return 0;
+    }
+    
     switch (msg) {
 
     case WM_CREATE:
     {
         static const WCHAR editW[] = { 'e','d','i','t',0 };
         DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
-                        ES_AUTOVSCROLL | ES_MULTILINE;
+                        ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL;
         RECT rc;
         GetClientRect(hWnd, &rc);
 
diff --git a/programs/notepad/main.h b/programs/notepad/main.h
index 3dd6bb0..075a248 100644
--- a/programs/notepad/main.h
+++ b/programs/notepad/main.h
@@ -51,6 +51,7 @@ typedef struct
   INT     iWindowPosDY;
 
   FINDREPLACE find;
+  FINDREPLACE lastFind;
   HGLOBAL hDevMode; /* printer mode */
   HGLOBAL hDevNames; /* printer names */
 } NOTEPAD_GLOBALS;
@@ -58,3 +59,4 @@ typedef struct
 extern NOTEPAD_GLOBALS Globals;
 
 VOID SetFileName(LPCWSTR szFileName);
+void NOTEPAD_DoFind(FINDREPLACE *fr);




More information about the wine-cvs mailing list