[DESK.CPL] -Implement opening msstyles files.
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Mon, 8 May 2017 18:45:35 +0000 (18:45 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Mon, 8 May 2017 18:45:35 +0000 (18:45 +0000)
svn path=/trunk/; revision=74506

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

index 40dfc3e..ed2acaa 100644 (file)
@@ -117,8 +117,48 @@ AppearancePage_OnInit(HWND hwndDlg)
     g->pThemes = LoadThemes();
     if (g->pThemes)
     {
-        if (!GetActiveTheme(g->pThemes, &g->ActiveTheme))
-            g->ActiveTheme.ThemeActive = FALSE;
+        PTHEME pLoadedTheme = NULL;
+        
+        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;
+            }
+        }
+
+        if (pLoadedTheme)
+        {
+            g->ActiveTheme.ThemeActive = TRUE;
+            g->ActiveTheme.Theme = pLoadedTheme;
+            g->ActiveTheme.Color = pLoadedTheme->ColoursList;
+            g->ActiveTheme.Size = pLoadedTheme->SizesList;
+        }
+        else
+        {
+            if (!GetActiveTheme(g->pThemes, &g->ActiveTheme))
+            {
+                g->ActiveTheme.ThemeActive = FALSE;
+            }
+        }
 
         /*
          * Keep a copy of the selected classic theme in order to select this
index 2a454a8..c261624 100644 (file)
@@ -135,6 +135,7 @@ typedef struct tagGLOBALS
 VOID SchemeSetMetric(COLOR_SCHEME *scheme, int id, int value);
 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 GetActiveTheme(PTHEME pThemeList, PTHEME_SELECTION pSelectedTheme);
 BOOL GetActiveClassicTheme(PTHEME pThemeList, PTHEME_SELECTION pSelectedTheme);
index 0506bf9..57a4b77 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "desk.h"
-
+#include <Shellapi.h>
 #include <cplext.h>
 #include <debug.h>
 
@@ -109,12 +109,13 @@ static const struct
     WORD idDlg;
     DLGPROC DlgProc;
     LPFNPSPCALLBACK Callback;
+    LPWSTR Name;
 } PropPages[] =
 {
-    { IDD_BACKGROUND, BackgroundPageProc, NULL },
-    { IDD_SCREENSAVER, ScreenSaverPageProc, NULL },
-    { IDD_APPEARANCE, AppearancePageProc, NULL },
-    { IDD_SETTINGS, SettingsPageProc, SettingsPageCallbackProc },
+    { IDD_BACKGROUND, BackgroundPageProc, NULL, L"Desktop" },
+    { IDD_SCREENSAVER, ScreenSaverPageProc, NULL, L"Screen Saver" },
+    { IDD_APPEARANCE, AppearancePageProc, NULL, L"Appearance" },
+    { IDD_SETTINGS, SettingsPageProc, SettingsPageCallbackProc, L"Settings" },
 };
 
 /* Display Applet */
@@ -127,12 +128,51 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
     TCHAR Caption[1024];
     LONG ret;
     UINT i;
+    LPWSTR *argv = NULL;
+    LPCWSTR pwszSelectedTab = NULL;
+    LPCWSTR pwszFile = NULL;
+    LPCWSTR pwszAction = NULL;
 
-    UNREFERENCED_PARAMETER(lParam);
     UNREFERENCED_PARAMETER(wParam);
-    UNREFERENCED_PARAMETER(uMsg);
-    UNREFERENCED_PARAMETER(hwnd);
 
+    hCPLWindow = hwnd;
+
+    if (uMsg == CPL_STARTWPARMSW && lParam)
+    {
+        int argc;
+        int i;
+        LPCWSTR pszCommandLine = (LPCWSTR)lParam;
+
+        argv = CommandLineToArgvW(pszCommandLine, &argc);
+
+        if (argv && argc)
+        {
+            for (i = 0; i<argc; i++)
+            {
+                if (argv[i][0] == L'@')
+                    pwszSelectedTab = &argv[i][1];
+                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";
+            }
+        }
+    }
+
+    g_GlobalData.pwszFile = pwszFile;
+    g_GlobalData.pwszAction = pwszAction;
     g_GlobalData.desktop_color = GetSysColor(COLOR_DESKTOP);
 
     LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
@@ -153,6 +193,9 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
 
     for (i = 0; i != sizeof(PropPages) / sizeof(PropPages[0]); i++)
     {
+        if (pwszSelectedTab && wcsicmp(pwszSelectedTab, PropPages[i].Name) == 0)
+            psh.nStartPage = i;
+
         /* Override the background page if requested by a shell extension */
         if (PropPages[i].idDlg == IDD_BACKGROUND && hpsxa != NULL &&
             SHReplaceFromPropSheetExtArray(hpsxa, CPLPAGE_DISPLAY_BACKGROUND, PropSheetAddPage, (LPARAM)&psh) != 0)
@@ -173,7 +216,10 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
     if (hpsxa != NULL)
         SHDestroyPropSheetExtArray(hpsxa);
 
-    return ret;
+    if (argv)
+        LocalFree(argv);
+
+    return TRUE;
 }
 
 
@@ -202,9 +248,10 @@ CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
             break;
 
         case CPL_DBLCLK:
-            hCPLWindow = hwndCPl;
             Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
             break;
+        case CPL_STARTWPARMSW:
+            return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
     }
 
     return FALSE;
index 10772fc..3c47925 100644 (file)
@@ -104,6 +104,8 @@ typedef struct _DISPLAY_DEVICE_ENTRY
 typedef struct _GLOBAL_DATA
 {
     COLORREF desktop_color;
+    LPCWSTR pwszFile;
+    LPCWSTR pwszAction;
 } GLOBAL_DATA, *PGLOBAL_DATA;
 
 extern GLOBAL_DATA g_GlobalData;
index b2e5b7f..f46ae44 100644 (file)
@@ -704,6 +704,23 @@ EnumThemeStyles(IN LPCWSTR pszThemeFileName, IN ENUMTHEMESTYLE pfnEnumTheme)
     return List;
 }
 
+PTHEME LoadTheme(IN LPCWSTR pszThemeFileName,IN LPCWSTR pszThemeName)
+{
+    PTHEME pTheme = CreateTheme(pszThemeFileName, pszThemeName);
+    if (pTheme == NULL) 
+        return NULL;
+
+    pTheme->SizesList = EnumThemeStyles( pszThemeFileName, (ENUMTHEMESTYLE)EnumThemeSizes);
+    pTheme->ColoursList = EnumThemeStyles( pszThemeFileName, (ENUMTHEMESTYLE)EnumThemeColors);
+    if(pTheme->SizesList == NULL || pTheme->ColoursList == NULL)
+    {
+        CleanupThemes(pTheme);
+        return NULL;
+    }
+
+    return pTheme;
+}
+
 BOOL CALLBACK
 EnumThemeProc(IN LPVOID lpReserved,
               IN LPCWSTR pszThemeFileName,
@@ -715,18 +732,9 @@ EnumThemeProc(IN LPVOID lpReserved,
     PTHEME *List, pTheme;
 
     List = (PTHEME*)lpData;
-
-    pTheme = CreateTheme(pszThemeFileName, pszThemeName);
+    pTheme = LoadTheme(pszThemeFileName, pszThemeName);
     if (pTheme == NULL) return FALSE;
 
-    pTheme->SizesList = EnumThemeStyles( pszThemeFileName, (ENUMTHEMESTYLE)EnumThemeSizes);
-    pTheme->ColoursList = EnumThemeStyles( pszThemeFileName, (ENUMTHEMESTYLE)EnumThemeColors);
-    if(pTheme->SizesList == NULL || pTheme->ColoursList == NULL)
-    {
-        CleanupThemes(pTheme);
-        return FALSE;
-    }
-
     pTheme->NextTheme = *List;
     *List = pTheme;