[DESK.CPL]
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Fri, 4 Aug 2017 08:53:06 +0000 (08:53 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Fri, 4 Aug 2017 08:53:06 +0000 (08:53 +0000)
-Improve the hack that lets it process arguments by using the process command line instead of the one shell32 gives to the cpl.
-Implement a new action called ActivateMSTheme that activates an msstyle file without showing any gui. If no file is passed, the classic theme is activated thus making it possible to switch themes from command line (or any other application may need to switch themes by launching desk.cpl).

svn path=/trunk/; revision=75476

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

index 7bbdb26..9f56ad3 100644 (file)
@@ -147,6 +147,7 @@ VOID ApplyScheme(PCOLOR_SCHEME scheme, PTHEME_SELECTION pSelectedTheme);
 BOOL ActivateTheme(PTHEME_SELECTION pSelectedTheme);
 void CleanupThemes(IN PTHEME pThemeList);
 BOOL DrawThemePreview(HDC hdcMem, PCOLOR_SCHEME scheme, PTHEME_SELECTION pSelectedTheme, PRECT prcWindow);
+BOOL ActivateThemeFile(LPCWSTR pwszFile);
 
 /* prototypes for appearance.c */
 INT_PTR CALLBACK AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
index 3bb931e..fa59d17 100644 (file)
@@ -124,7 +124,7 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
 {
     HPROPSHEETPAGE hpsp[MAX_DESK_PAGES];
     PROPSHEETHEADER psh;
-    HPSXA hpsxa;
+    HPSXA hpsxa = NULL;
     TCHAR Caption[1024];
     UINT i;
     LPWSTR *argv = NULL;
@@ -140,36 +140,38 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
     {
         int argc;
         int i;
-        LPCWSTR pszCommandLine = (LPCWSTR)lParam;
 
-        argv = CommandLineToArgvW(pszCommandLine, &argc);
+#if 0
+        argv = CommandLineToArgvW((LPCWSTR)lParam, &argc);
+#else
+        argv = CommandLineToArgvW(GetCommandLineW(), &argc);
+#endif
 
         if (argv && argc)
         {
             for (i = 0; i<argc; i++)
             {
+#if 0
                 if (argv[i][0] == L'@')
                     pwszSelectedTab = &argv[i][1];
+#else
+                if (wcsncmp(argv[i], L"desk,@", 6) == 0)
+                    pwszSelectedTab = &argv[i][6];
+#endif
                 else if (wcsncmp(argv[i], L"/Action:", 8) == 0)
                     pwszAction = &argv[i][8];
                 else if (wcsncmp(argv[i], L"/file:", 6) == 0)
                     pwszFile = &argv[i][6];
             }
         }
-
-        /* HACK: shell32 doesn't give the correct params to CPL_STARTWPARMSW so we need to ... improvise */
-        if (wcsncmp(pszCommandLine, L"/file:", 6) == 0)
-        {
-            LPCWSTR pwszType = wcsrchr(pszCommandLine, L'.');
-            if (pwszType && wcsicmp(pwszType, L".msstyles") == 0)
-            {
-                pwszFile = &pszCommandLine[6];
-                pwszSelectedTab = L"Appearance";
-                pwszAction = L"OpenMSTheme";
-            }
-        }
     }
 
+    if(pwszAction && wcsncmp(pwszAction, L"ActivateMSTheme", 15) == 0)
+    {
+        ActivateThemeFile(pwszFile);
+        goto cleanup;
+    }
+    
     g_GlobalData.pwszFile = pwszFile;
     g_GlobalData.pwszAction = pwszAction;
     g_GlobalData.desktop_color = GetSysColor(COLOR_DESKTOP);
@@ -212,6 +214,7 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
 
     PropertySheet(&psh);
 
+cleanup:
     if (hpsxa != NULL)
         SHDestroyPropSheetExtArray(hpsxa);
 
index e541d06..858033c 100644 (file)
@@ -1010,3 +1010,51 @@ DrawThemePreview(IN HDC hdcMem, IN PCOLOR_SCHEME scheme, IN PTHEME_SELECTION pSe
 
     return SUCCEEDED(hres);
 }
+
+BOOL ActivateThemeFile(LPCWSTR pwszFile)
+{
+    PTHEME pThemes;
+    THEME_SELECTION selection;
+    COLOR_SCHEME scheme;
+    BOOL ret = FALSE;
+
+    pThemes = LoadThemes();
+    if (!pThemes)
+        return FALSE;
+
+    LoadCurrentScheme(&scheme);
+
+    if (pwszFile)
+    {
+        ret = FindOrAppendTheme(pThemes, pwszFile, NULL, NULL, &selection);
+        if (!ret)
+            goto cleanup;
+
+        ret = LoadSchemeFromTheme(&scheme, &selection);
+        if (!ret)
+            goto cleanup;
+    }
+    else
+    {
+        ret = GetActiveClassicTheme(pThemes, &selection);
+        if (!ret)
+            goto cleanup;
+
+        ret = LoadSchemeFromReg(&scheme, &selection);
+        if (!ret)
+            goto cleanup;
+    }
+
+    ret = ActivateTheme(&selection);
+    if (!ret)
+        goto cleanup;
+
+    ApplyScheme(&scheme, &selection);
+
+    ret = TRUE;
+
+cleanup:
+    CleanupThemes(pThemes);
+
+    return ret;
+}