mirror of
git://source.winehq.org/git/wine.git
synced 2024-08-31 23:33:38 +00:00
notepad: Implement Find and Find Next.
This commit is contained in:
parent
b0905acb6e
commit
84fc75c3d2
|
@ -663,7 +663,7 @@ VOID DIALOG_Search(VOID)
|
||||||
Globals.find.hInstance = Globals.hInstance;
|
Globals.find.hInstance = Globals.hInstance;
|
||||||
Globals.find.lpstrFindWhat = Globals.szFindText;
|
Globals.find.lpstrFindWhat = Globals.szFindText;
|
||||||
Globals.find.wFindWhatLen = SIZEOF(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 */
|
/* We only need to create the modal FindReplace dialog which will */
|
||||||
/* notify us of incoming events using hMainWnd Window Messages */
|
/* notify us of incoming events using hMainWnd Window Messages */
|
||||||
|
@ -674,8 +674,10 @@ VOID DIALOG_Search(VOID)
|
||||||
|
|
||||||
VOID DIALOG_SearchNext(VOID)
|
VOID DIALOG_SearchNext(VOID)
|
||||||
{
|
{
|
||||||
/* FIXME: Search Next */
|
if (Globals.lastFind.lpstrFindWhat == NULL)
|
||||||
DIALOG_Search();
|
DIALOG_Search();
|
||||||
|
else /* use the last find data */
|
||||||
|
NOTEPAD_DoFind(&Globals.lastFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID DIALOG_HelpContents(VOID)
|
VOID DIALOG_HelpContents(VOID)
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <shlwapi.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -314,6 +315,65 @@ static VOID NOTEPAD_InitMenuPopup(HMENU menu, int index)
|
||||||
GetWindowTextLength(Globals.hEdit) ? MF_ENABLED : MF_GRAYED);
|
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
|
* NOTEPAD_WndProc
|
||||||
|
@ -321,13 +381,27 @@ static VOID NOTEPAD_InitMenuPopup(HMENU menu, int index)
|
||||||
static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
|
static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
|
||||||
LPARAM lParam)
|
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) {
|
switch (msg) {
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
{
|
{
|
||||||
static const WCHAR editW[] = { 'e','d','i','t',0 };
|
static const WCHAR editW[] = { 'e','d','i','t',0 };
|
||||||
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
|
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
|
||||||
ES_AUTOVSCROLL | ES_MULTILINE;
|
ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL;
|
||||||
RECT rc;
|
RECT rc;
|
||||||
GetClientRect(hWnd, &rc);
|
GetClientRect(hWnd, &rc);
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ typedef struct
|
||||||
INT iWindowPosDY;
|
INT iWindowPosDY;
|
||||||
|
|
||||||
FINDREPLACE find;
|
FINDREPLACE find;
|
||||||
|
FINDREPLACE lastFind;
|
||||||
HGLOBAL hDevMode; /* printer mode */
|
HGLOBAL hDevMode; /* printer mode */
|
||||||
HGLOBAL hDevNames; /* printer names */
|
HGLOBAL hDevNames; /* printer names */
|
||||||
} NOTEPAD_GLOBALS;
|
} NOTEPAD_GLOBALS;
|
||||||
|
@ -58,3 +59,4 @@ typedef struct
|
||||||
extern NOTEPAD_GLOBALS Globals;
|
extern NOTEPAD_GLOBALS Globals;
|
||||||
|
|
||||||
VOID SetFileName(LPCWSTR szFileName);
|
VOID SetFileName(LPCWSTR szFileName);
|
||||||
|
void NOTEPAD_DoFind(FINDREPLACE *fr);
|
||||||
|
|
Loading…
Reference in a new issue