Add search/find support (issue #513).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1482 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-10-23 22:44:12 +00:00
parent bc1ea4974a
commit c7d7b9fbbf
10 changed files with 212 additions and 0 deletions

View File

@ -31,6 +31,8 @@ TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
TCHAR szOSRWindowClass[MAX_LOADSTRING]; // the OSR window class name
char szWorkingDir[MAX_PATH]; // The current working directory
UINT uFindMsg; // Message identifier for find events.
HWND hFindDlg = NULL; // Handle for the find dialog.
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
@ -104,6 +106,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT));
// Register the find event message.
uFindMsg = RegisterWindowMessage(FINDMSGSTRING);
int result = 0;
if (!settings.multi_threaded_message_loop) {
@ -119,6 +124,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
// Run the application message loop.
while (GetMessage(&msg, NULL, 0, 0)) {
// Allow processing of find dialog messages.
if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
continue;
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
@ -251,6 +260,47 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
lParam);
} else if (message == uFindMsg) {
// Find event.
LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;
if (lpfr->Flags & FR_DIALOGTERM) {
// The find dialog box has been dismissed so invalidate the handle and
// reset the search results.
hFindDlg = NULL;
if (g_handler.get()) {
g_handler->GetBrowser()->GetHost()->StopFinding(true);
szLastFindWhat[0] = 0;
findNext = false;
}
return 0;
}
if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get()) {
// Search for the requested string.
bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false);
if (matchCase != lastMatchCase ||
(matchCase && wcsncmp(szFindWhat, szLastFindWhat,
sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) ||
(!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat,
sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) {
// The search string has changed, so reset the search results.
if (szLastFindWhat[0] != 0) {
g_handler->GetBrowser()->GetHost()->StopFinding(true);
findNext = false;
}
lastMatchCase = matchCase;
wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR),
szFindWhat);
}
g_handler->GetBrowser()->GetHost()->Find(0, lpfr->lpstrFindWhat,
(lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext);
if (!findNext)
findNext = true;
}
return 0;
} else {
// Callback for the main window
switch (message) {
@ -376,6 +426,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
MB_OK | MB_ICONINFORMATION);
}
return 0;
case ID_FIND:
if (!hFindDlg) {
// Create the find dialog.
ZeroMemory(&fr, sizeof(fr));
fr.lStructSize = sizeof(fr);
fr.hwndOwner = hWnd;
fr.lpstrFindWhat = szFindWhat;
fr.wFindWhatLen = sizeof(szFindWhat);
fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN;
hFindDlg = FindText(&fr);
} else {
// Give focus to the existing find dialog.
::SetFocus(hFindDlg);
}
return 0;
case IDC_NAV_BACK: // Back button
if (browser.get())
browser->GoBack();