Author: tfaber
Date: Sat Jan 18 13:26:47 2014
New Revision: 61673
URL: 
http://svn.reactos.org/svn/reactos?rev=61673&view=rev
Log:
[RAPPS]
- Implement search feature. Based on patch by David Quintana.
CORE-7268 #resolve
CORE-7786 #comment rapps contains a hack to load StrStrIW using GetProcAddress. That
should be removed once this issue is fixed.
Modified:
    trunk/reactos/base/applications/rapps/winmain.c
Modified: trunk/reactos/base/applications/rapps/winmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/rapps/wi…
==============================================================================
--- trunk/reactos/base/applications/rapps/winmain.c     [iso-8859-1] (original)
+++ trunk/reactos/base/applications/rapps/winmain.c     [iso-8859-1] Sat Jan 18 13:26:47
2014
@@ -10,11 +10,27 @@
 #include <shellapi.h>
+#define SEARCH_TIMER_ID 'SR'
+
 HWND hMainWnd;
 HINSTANCE hInst;
 HIMAGELIST hImageTreeView = NULL;
 INT SelectedEnumType = ENUM_ALL_COMPONENTS;
 SETTINGS_INFO SettingsInfo;
+
+PCWSTR (WINAPI *pStrStrIW)(PCWSTR, PCWSTR);
+
+WCHAR szSearchPattern[MAX_STR_LEN] = L"";
+BOOL SearchEnabled = TRUE;
+
+BOOL
+SearchPatternMatch(PCWSTR szHaystack, PCWSTR szNeedle)
+{
+    if (!*szNeedle)
+        return TRUE;
+    /* TODO: Improve pattern search beyond a simple case-insensitive substring search. */
+    return pStrStrIW(szHaystack, szNeedle) != NULL;
+}
 VOID
 FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
@@ -107,6 +123,9 @@
     WCHAR szText[MAX_PATH];
     INT Index;
+    if (!SearchPatternMatch(lpName, szSearchPattern))
+        return TRUE;
+
     ItemInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(INSTALLED_INFO));
     if (!ItemInfo) return FALSE;
@@ -145,6 +164,12 @@
 {
     PAPPLICATION_INFO ItemInfo;
     INT Index;
+
+    if (!SearchPatternMatch(Info.szName, szSearchPattern) &&
+        !SearchPatternMatch(Info.szDesc, szSearchPattern))
+    {
+        return TRUE;
+    }
     /* Only add a ListView entry if...
          - no RegName was supplied (so we cannot determine whether the application is
installed or not) or
@@ -344,6 +369,13 @@
     return FALSE;
 }
+VOID CALLBACK
+SearchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+{
+    KillTimer(hwnd, SEARCH_TIMER_ID);
+    UpdateApplicationsList(-1);
+}
+
 VOID
 MainWndOnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
 {
@@ -361,7 +393,11 @@
                 LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, sizeof(szBuf) /
sizeof(WCHAR));
                 GetWindowTextW(hSearchBar, szWndText, MAX_STR_LEN);
-                if (wcscmp(szBuf, szWndText) == 0) SetWindowTextW(hSearchBar,
L"");
+                if (wcscmp(szBuf, szWndText) == 0)
+                {
+                    SearchEnabled = FALSE;
+                    SetWindowTextW(hSearchBar, L"");
+                }
             }
             break;
@@ -371,14 +407,37 @@
                 if (wcslen(szBuf) < 1)
                 {
                     LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, sizeof(szBuf) /
sizeof(WCHAR));
+                    SearchEnabled = FALSE;
                     SetWindowTextW(hSearchBar, szBuf);
                 }
             }
             break;
             case EN_CHANGE:
-                /* TODO: Implement search */
-                break;
+            {
+                WCHAR szWndText[MAX_STR_LEN];
+
+                if (!SearchEnabled)
+                {
+                    SearchEnabled = TRUE;
+                    break;
+                }
+
+                LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, sizeof(szBuf) /
sizeof(WCHAR));
+                GetWindowTextW(hSearchBar, szWndText, MAX_STR_LEN);
+                if (wcscmp(szBuf, szWndText) != 0)
+                {
+                    StringCbCopy(szSearchPattern, sizeof(szSearchPattern),
+                                 szWndText);
+                }
+                else
+                {
+                    szSearchPattern[0] = UNICODE_NULL;
+                }
+
+                SetTimer(hwnd, SEARCH_TIMER_ID, 250, SearchTimerProc);
+            }
+            break;
         }
         return;
@@ -778,6 +837,10 @@
     HANDLE hMutex = NULL;
     MSG Msg;
+    /* FIXME: CORE-7786 requires this to be loaded at runtime because we
+     *        would get comctl32's version otherwise */
+    pStrStrIW = (PVOID)GetProcAddress(GetModuleHandle(L"shlwapi"),
"StrStrIW");
+
     switch (GetUserDefaultUILanguage())
     {
         case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):