From 2698f8b357a802ac789e7d4ca57d0cecc4aebcc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Sat, 1 Aug 2009 16:21:58 -0700 Subject: [PATCH] Bug 507032 - "Set As Desktop Background..." doesn't work on Windows CE, r=robert.bugzilla --- .../shell/content/setDesktopBackground.xul | 2 ++ .../shell/src/nsWindowsShellService.cpp | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/browser/components/shell/content/setDesktopBackground.xul b/browser/components/shell/content/setDesktopBackground.xul index cc96733bc19d..fe74424f5297 100644 --- a/browser/components/shell/content/setDesktopBackground.xul +++ b/browser/components/shell/content/setDesktopBackground.xul @@ -77,7 +77,9 @@ +#ifndef WINCE +#endif diff --git a/browser/components/shell/src/nsWindowsShellService.cpp b/browser/components/shell/src/nsWindowsShellService.cpp index 5b44692cd05d..664d9840d813 100644 --- a/browser/components/shell/src/nsWindowsShellService.cpp +++ b/browser/components/shell/src/nsWindowsShellService.cpp @@ -26,6 +26,7 @@ * Robert Strong * Asaf Romano * Ryan Jones + * Paul O'Shannessy * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -215,9 +216,11 @@ typedef struct { #define APP_REG_NAME L"Firefox" #define CLS_HTML "FirefoxHTML" #define CLS_URL "FirefoxURL" +#define CPL_DESKTOP L"\\Control Panel\\Desktop" #define VAL_OPEN "\"%APPPATH%\" -requestPending -osint -url \"%1\"" #define VAL_FILE_ICON "%APPPATH%,1" #else +#define CPL_DESKTOP L"\\ControlPanel\\Desktop" #define VAL_OPEN "\"%APPPATH%\" -osint -url \"%1\"" #define VAL_FILE_ICON "%APPPATH%,-2" #endif @@ -656,12 +659,12 @@ nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement, PRBool result = PR_FALSE; DWORD dwDisp = 0; HKEY key; - // Try to create/open a subkey under HKLM. - DWORD res = ::RegCreateKeyExW(HKEY_CURRENT_USER, - L"Control Panel\\Desktop", + // Try to create/open a subkey under HKCU. + DWORD res = ::RegCreateKeyExW(HKEY_CURRENT_USER, CPL_DESKTOP, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, &dwDisp); if (REG_SUCCEEDED(res)) { +#ifndef WINCE PRUnichar tile[2], style[2]; switch (aPosition) { case BACKGROUND_TILE: @@ -688,8 +691,25 @@ nsWindowsShellService::SetDesktopBackground(nsIDOMElement* aElement, 0, REG_SZ, (const BYTE *)style, size); ::SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (PVOID)path.get(), SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); +#else + DWORD tile = (aPosition == BACKGROUND_TILE); + ::RegSetValueExW(key, L"Tile", + 0, REG_DWORD, (const BYTE *)&tile, sizeof(DWORD)); + // On WinCE SPI_SETDESKWALLPAPER isn't available, so set the registry + // entry ourselves and then broadcast UI change + PRInt32 size = (path.Length() + 1) * sizeof(PRUnichar); + ::RegSetValueExW(key, L"Wallpaper", + 0, REG_SZ, (const BYTE *)path.get(), size); + ::SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, NULL, 0); +#endif + // Close the key we opened. ::RegCloseKey(key); + +#ifdef WINCE + // Ensure that the writes are flushed in case of hard reboot + ::RegFlushKey(HKEY_CURRENT_USER); +#endif } } return rv; @@ -815,10 +835,13 @@ nsWindowsShellService::SetDesktopBackgroundColor(PRUint32 aColor) ::SetSysColors(sizeof(aParameters) / sizeof(int), aParameters, colors); + // SetSysColors is persisting across sessions on Windows CE, so no need to + // write to registry +#ifndef WINCE PRBool result = PR_FALSE; DWORD dwDisp = 0; HKEY key; - // Try to create/open a subkey under HKLM. + // Try to create/open a subkey under HKCU. DWORD rv = ::RegCreateKeyExW(HKEY_CURRENT_USER, L"Control Panel\\Colors", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, @@ -836,6 +859,7 @@ nsWindowsShellService::SetDesktopBackgroundColor(PRUint32 aColor) // Close the key we opened. ::RegCloseKey(key); +#endif return NS_OK; }