[DESK.CPL] -Addendum to 74506 which was a bit rushed. Make it possible to apply a...
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Tue, 9 May 2017 08:13:49 +0000 (08:13 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Tue, 9 May 2017 08:13:49 +0000 (08:13 +0000)
svn path=/trunk/; revision=74511

reactos/dll/cpl/desk/appearance.c
reactos/dll/cpl/desk/appearance.h
reactos/dll/cpl/desk/theme.c

index ed2acaa..653b30b 100644 (file)
@@ -117,40 +117,27 @@ AppearancePage_OnInit(HWND hwndDlg)
     g->pThemes = LoadThemes();
     if (g->pThemes)
     {
-        PTHEME pLoadedTheme = NULL;
-        
+        BOOL bLoadedTheme = FALSE;
+
         if (g_GlobalData.pwszAction && 
             g_GlobalData.pwszFile && 
             wcscmp(g_GlobalData.pwszAction, L"OpenMSTheme") == 0)
         {
-            /* Check if the theme specified was already loaded */
-            for (pTheme = g->pThemes; pTheme; pTheme = pTheme->NextTheme)
-            {
-                if (pTheme->ThemeFileName && wcsicmp(pTheme->ThemeFileName, g_GlobalData.pwszFile) == 0)
-                {
-                    pLoadedTheme = pTheme;
-                    break;
-                }
-
-                if (!pTheme->NextTheme)
-                    break;
-            }
-
-            if (!pLoadedTheme)
-            {
-                /* Load it now and insert it in the list */
-                pLoadedTheme = LoadTheme(g_GlobalData.pwszFile, g_GlobalData.pwszFile);
-                if (pLoadedTheme)
-                    pTheme->NextTheme = pLoadedTheme;
-            }
+            bLoadedTheme = FindOrAppendTheme(g->pThemes, 
+                                             g_GlobalData.pwszFile,
+                                             NULL,
+                                             NULL,
+                                             &g->ActiveTheme);
         }
 
-        if (pLoadedTheme)
+        if (bLoadedTheme)
         {
-            g->ActiveTheme.ThemeActive = TRUE;
-            g->ActiveTheme.Theme = pLoadedTheme;
-            g->ActiveTheme.Color = pLoadedTheme->ColoursList;
-            g->ActiveTheme.Size = pLoadedTheme->SizesList;
+            g->bThemeChanged = TRUE;
+            g->bSchemeChanged = TRUE;
+
+            PostMessageW(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
+
+            AppearancePage_LoadSelectedScheme(hwndDlg, g);
         }
         else
         {
index c261624..7bbdb26 100644 (file)
@@ -137,6 +137,7 @@ int SchemeGetMetric(COLOR_SCHEME *scheme, int id);
 PLOGFONTW SchemeGetFont(COLOR_SCHEME *scheme, int id);
 PTHEME LoadTheme(IN LPCWSTR pszThemeFileName,IN LPCWSTR pszThemeName);
 PTHEME LoadThemes(VOID);
+BOOL FindOrAppendTheme(IN PTHEME pThemeList, IN LPCWSTR pwszThemeFileName, IN LPCWSTR pwszColorBuff, IN LPCWSTR pwszSizeBuff, OUT PTHEME_SELECTION pSelectedTheme);
 BOOL GetActiveTheme(PTHEME pThemeList, PTHEME_SELECTION pSelectedTheme);
 BOOL GetActiveClassicTheme(PTHEME pThemeList, PTHEME_SELECTION pSelectedTheme);
 BOOL LoadCurrentScheme(PCOLOR_SCHEME scheme);
index f46ae44..e541d06 100644 (file)
@@ -784,48 +784,83 @@ LoadThemes(VOID)
 }
 
 /*
- * GetActiveTheme: Gets the active theme and populates pSelectedTheme
- *                 with entries from the list of loaded themes
+ * FindSelectedTheme: Finds the specified theme in the list of themes 
+ *                    or loads it if it was not loaded already.
  */
 BOOL
-GetActiveTheme(IN PTHEME pThemeList, OUT PTHEME_SELECTION pSelectedTheme)
+FindOrAppendTheme(IN PTHEME pThemeList, 
+                  IN LPCWSTR pwszThemeFileName,
+                  IN LPCWSTR pwszColorBuff,
+                  IN LPCWSTR pwszSizeBuff,
+                  OUT PTHEME_SELECTION pSelectedTheme)
 {
-    WCHAR szThemeFileName[MAX_PATH];
-    WCHAR szColorBuff[MAX_PATH];
-    WCHAR szSizeBuff[MAX_PATH];
     PTHEME pTheme;
-    HRESULT hret;
+    PTHEME pFoundTheme = NULL;
 
     ZeroMemory(pSelectedTheme, sizeof(THEME_SELECTION));
 
-    /* Retrieve the name of the current theme */
-    hret = GetCurrentThemeName(szThemeFileName,
-                               MAX_PATH,
-                               szColorBuff,
-                               MAX_PATH,
-                               szSizeBuff,
-                               MAX_PATH);
-    if (FAILED(hret))  return FALSE;
-
     for (pTheme = pThemeList; pTheme; pTheme = pTheme->NextTheme)
     {
         if (pTheme->ThemeFileName &&
-           _wcsicmp(pTheme->ThemeFileName, szThemeFileName) == 0)
+           _wcsicmp(pTheme->ThemeFileName, pwszThemeFileName) == 0)
         {
+            pFoundTheme = pTheme;
             break;
         }
+
+        if (pTheme->NextTheme == NULL)
+            break;
     }
 
-    if (pTheme == NULL) return FALSE;
+    if (!pFoundTheme)
+    {
+        pFoundTheme = LoadTheme(pwszThemeFileName, pwszThemeFileName);
+        if (!pFoundTheme)
+            return FALSE;
+
+        pTheme->NextTheme = pFoundTheme;
+    }
 
     pSelectedTheme->ThemeActive = TRUE;
-    pSelectedTheme->Theme = pTheme;
-    pSelectedTheme->Color = FindStyle(pTheme->ColoursList, szColorBuff);
-    pSelectedTheme->Size = FindStyle(pTheme->SizesList, szSizeBuff);
+    pSelectedTheme->Theme = pFoundTheme;
+    if (pwszColorBuff)
+        pSelectedTheme->Color = FindStyle(pFoundTheme->ColoursList, pwszColorBuff);
+    else
+        pSelectedTheme->Color = pFoundTheme->ColoursList;
+
+    if (pwszSizeBuff)
+        pSelectedTheme->Size = FindStyle(pFoundTheme->SizesList, pwszSizeBuff);
+    else
+        pSelectedTheme->Size = pFoundTheme->SizesList;
 
     return TRUE;
 }
 
+/*
+ * GetActiveTheme: Gets the active theme and populates pSelectedTheme
+ *                 with entries from the list of loaded themes.
+ */
+BOOL
+GetActiveTheme(IN PTHEME pThemeList, OUT PTHEME_SELECTION pSelectedTheme)
+{
+    WCHAR szThemeFileName[MAX_PATH];
+    WCHAR szColorBuff[MAX_PATH];
+    WCHAR szSizeBuff[MAX_PATH];
+    HRESULT hret;
+
+    /* Retrieve the name of the current theme */
+    hret = GetCurrentThemeName(szThemeFileName,
+                               MAX_PATH,
+                               szColorBuff,
+                               MAX_PATH,
+                               szSizeBuff,
+                               MAX_PATH);
+    if (FAILED(hret))  
+        return FALSE;
+
+    return FindOrAppendTheme(pThemeList, szThemeFileName, szColorBuff, szSizeBuff, pSelectedTheme);
+}
+
 /*
  * GetActiveTheme: Gets the active classic theme and populates pSelectedTheme
  *                 with entries from the list of loaded themes