[RAPPS]
authorAlexander Shaposhnikov <sanchaez@reactos.org>
Fri, 23 Jun 2017 07:04:43 +0000 (07:04 +0000)
committerAlexander Shaposhnikov <sanchaez@reactos.org>
Fri, 23 Jun 2017 07:04:43 +0000 (07:04 +0000)
* Added individual icons loading for each app
  The icons are loaded by the Name field in the DB for the proof-of-concept.
  It falls back to default icon if none present.
  TODO: It would be best to make another entry there for icon name.

svn path=/branches/GSoC_2017/rapps/; revision=75168

reactos/base/applications/rapps/gui.cpp

index 49db003..5e51ce9 100644 (file)
@@ -1,4 +1,4 @@
-/* PROJECT:     ReactOS CE Applications Manager
+/* PROJECT:     ReactOS CE Applications Manager
  * LICENSE:     GPL - See COPYING in the top level directory
  * AUTHORS:     David Quintana <gigaherz@gmail.com>
  */
@@ -1126,71 +1126,72 @@ private:
     static BOOL CALLBACK s_EnumAvailableAppProc(PAPPLICATION_INFO Info)
     {
         INT Index;
+        HICON hIcon = NULL;
+        bool failed = false;
+        WCHAR szIconPath[MAX_PATH] = L"";
+        HIMAGELIST hImageListView = NULL;
+        hImageListView = ListView_GetImageList(hListView, LVSIL_SMALL);
 
         if (!SearchPatternMatch(Info->szName, szSearchPattern) &&
             !SearchPatternMatch(Info->szDesc, szSearchPattern))
         {
             return TRUE;
         }
+        //TODO: Define another field for icon name in the DB
+        failed = !GetStorageDirectory(szIconPath, _countof(szIconPath)) 
+          || FAILED(StringCbPrintfW(szIconPath, sizeof(szIconPath), L"%ls\\rapps\\icons\\%ls.ico", szIconPath, Info->szName));
+        if (!failed) {
+          //Load icon from file
+          hIcon = (HICON)LoadImage(NULL,
+            szIconPath,
+            IMAGE_ICON,
+            LISTVIEW_ICON_SIZE,
+            LISTVIEW_ICON_SIZE,
+            LR_LOADFROMFILE);
+        }
+        if (GetLastError() != ERROR_SUCCESS) {
+          //Load default icon
+          hIcon = (HICON)LoadIcon(hInst, MAKEINTRESOURCE(IDI_MAIN));
+        }
+        Index = ImageList_AddIcon(hImageListView, hIcon);
+        DestroyIcon(hIcon);
 
-        Index = ListViewAddItem(Info->Category, 0, Info->szName, (LPARAM) Info);
+        Index = ListViewAddItem(Info->Category, Index, Info->szName, (LPARAM) Info);
+        hImageListView = ListView_SetImageList(hListView, hImageListView, LVSIL_SMALL);
 
         ListView_SetItemText(hListView, Index, 1, Info->szVersion);
         ListView_SetItemText(hListView, Index, 2, Info->szDesc);
-
         return TRUE;
     }
 
+
     VOID UpdateApplicationsList(INT EnumType)
     {
         WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN];
-        HICON hIcon;
-        HIMAGELIST hImageListView;
+        HIMAGELIST hImageListView = NULL;
 
         m_ListView->SendMessage(WM_SETREDRAW, FALSE, 0);
 
-        if (EnumType == -1) EnumType = SelectedEnumType;
+        if (EnumType < 0) EnumType = SelectedEnumType;
 
         if (IS_INSTALLED_ENUM(SelectedEnumType))
             FreeInstalledAppList();
 
         (VOID) ListView_DeleteAllItems(hListView);
-
-        /* Create image list */
+        //Create new ImageList
         hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE,
-            LISTVIEW_ICON_SIZE,
-            GetSystemColorDepth() | ILC_MASK,
-            0, 1);
-
-        hIcon = (HICON) LoadImage(hInst,
-            MAKEINTRESOURCE(IDI_MAIN),
-            IMAGE_ICON,
-            LISTVIEW_ICON_SIZE,
-            LISTVIEW_ICON_SIZE,
-            LR_CREATEDIBSECTION);
-
-        ImageList_AddIcon(hImageListView, hIcon);
-        DestroyIcon(hIcon);
-        /*
-        if (IS_INSTALLED_ENUM(EnumType))
-        {
-            / Enum installed applications and updates 
-            EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc);
-            EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc);
-        }
-
-        else */if (IS_AVAILABLE_ENUM(EnumType))
-        {
-            /* Enum available applications */
-            EnumAvailableApplications(EnumType, s_EnumAvailableAppProc);
-        }
-
-        /* Set image list for ListView */
+          LISTVIEW_ICON_SIZE,
+          GetSystemColorDepth() | ILC_MASK,
+          0, 1000);
         hImageListView = ListView_SetImageList(hListView, hImageListView, LVSIL_SMALL);
 
-        /* Destroy old image list */
         if (hImageListView)
-            ImageList_Destroy(hImageListView);
+          ImageList_Destroy(hImageListView);
+
+        if (IS_AVAILABLE_ENUM(EnumType)) {
+          /* Enum available applications */
+          EnumAvailableApplications(EnumType, s_EnumAvailableAppProc);
+        }
 
         SelectedEnumType = EnumType;
 
@@ -1212,7 +1213,7 @@ private:
 public:
     static ATL::CWndClassInfo& GetWndClassInfo()
     {
-        DWORD csStyle = CS_VREDRAW |CS_HREDRAW;
+        DWORD csStyle = CS_VREDRAW | CS_HREDRAW;
         static ATL::CWndClassInfo wc =
         {
             { sizeof(WNDCLASSEX), csStyle, StartWindowProc,