More build fixes.
[reactos.git] / reactos / dll / cpl / desk / desk.c
index 0f37271..3bb931e 100644 (file)
@@ -8,8 +8,11 @@
  */
 
 #include "desk.h"
+#include <shellapi.h>
+#include <cplext.h>
+#include <debug.h>
 
-#define NUM_APPLETS    (1)
+#define NUM_APPLETS    (1)
 
 static LONG APIENTRY DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
 
@@ -106,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 */
@@ -122,14 +126,52 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
     PROPSHEETHEADER psh;
     HPSXA hpsxa;
     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));
@@ -150,6 +192,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)
@@ -165,12 +210,15 @@ DisplayApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
     /* NOTE: Don't call SHAddFromPropSheetExtArray here because this applet only allows
              replacing the background page but not extending the applet by more pages */
 
-    ret = (LONG)(PropertySheet(&psh) != -1);
+    PropertySheet(&psh);
 
     if (hpsxa != NULL)
         SHDestroyPropSheetExtArray(hpsxa);
 
-    return ret;
+    if (argv)
+        LocalFree(argv);
+
+    return TRUE;
 }
 
 
@@ -199,14 +247,91 @@ 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;
 }
 
+void
+WINAPI
+InstallScreenSaverW(
+    IN HWND hWindow,
+    IN HANDLE hInstance,
+    IN LPCWSTR pszFile,
+    IN UINT nCmdShow)
+{
+    WCHAR pszSystemDir[MAX_PATH];
+    WCHAR pszDrive[3];
+    WCHAR pszPath[MAX_PATH];
+    WCHAR pszFilename[MAX_PATH];
+    WCHAR pszExt[MAX_PATH];
+    LPWSTR pszOutName;
+    UINT uCompressionType=FILE_COMPRESSION_NONE;
+    DWORD dwSourceSize;
+    DWORD dwTargetSize;
+    DWORD rc;
+
+    if (!pszFile)
+    {
+        DPRINT("InstallScreenSaver() null file\n");
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return;
+    }
+    DPRINT("InstallScreenSaver() Installing screensaver %ls\n", pszFile);
+
+    rc = SetupGetFileCompressionInfoW(pszFile, &pszOutName, &dwSourceSize, &dwTargetSize, &uCompressionType);
+    if (ERROR_SUCCESS != rc)
+    {
+        DPRINT("InstallScreenSaver() SetupGetFileCompressionInfo failed with error 0x%lx\n", rc);
+        SetLastError(rc);
+        return;
+    }
+    if (!GetSystemDirectoryW((LPWSTR)pszSystemDir, sizeof(pszSystemDir)/sizeof(WCHAR)))
+    {
+        MyFree(pszOutName);
+        DPRINT("InstallScreenSaver() GetSystemDirectory failed with error 0x%lx\n", GetLastError());
+        return;
+    }
+    _wsplitpath(pszOutName, pszDrive, pszPath, pszFilename, pszExt);
+    MyFree(pszOutName);
+    StringCbCatW(pszSystemDir, sizeof(pszSystemDir), L"\\");
+    StringCbCatW(pszSystemDir, sizeof(pszSystemDir), pszFilename);
+    StringCbCatW(pszSystemDir, sizeof(pszSystemDir), pszExt);
+    rc = SetupDecompressOrCopyFileW(pszFile, pszSystemDir, &uCompressionType);
+    DPRINT("InstallScreenSaver() Copying to %ls, compression type %d return 0x%lx\n", pszFile, uCompressionType, rc);
+}
+
+void
+WINAPI
+InstallScreenSaverA(
+    IN HWND hWindow,
+    IN HANDLE hInstance,
+    IN LPCSTR pszFile,
+    IN UINT nCmdShow)
+{
+    LPWSTR lpwString;
+
+    if (!pszFile)
+    {
+        DPRINT("InstallScreenSaver() null file\n");
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return;
+    }
+    DPRINT("InstallScreenSaver() Install from file %s\n", pszFile);
+    lpwString = pSetupMultiByteToUnicode(pszFile, 0);
+    if (!lpwString)
+    {
+        DPRINT("InstallScreenSaver() not enough memory to convert string to unicode\n");
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return;
+    }
+    InstallScreenSaverW(hWindow, hInstance, lpwString, nCmdShow);
+    MyFree(lpwString);
+}
 
 BOOL WINAPI
 DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpvReserved)