Author: winesync Date: Tue Jul 25 01:24:10 2006 New Revision: 23271
URL: http://svn.reactos.org/svn/reactos?rev=23271&view=rev Log: Alexey Minnekhanov: - Registry keys are created if they don't exist - "Custom colors" are stored in the registry too now (tested to work under Windows XP) - Fixed a check during adding of a new wallpaper to the list. Now it will actually deny addition of the same wallpaper image more than once - Some TAB -> Spaces fixes
Modified: trunk/reactos/dll/cpl/desk/background.c
Modified: trunk/reactos/dll/cpl/desk/background.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/background.c?r... ============================================================================== --- trunk/reactos/dll/cpl/desk/background.c (original) +++ trunk/reactos/dll/cpl/desk/background.c Tue Jul 25 01:24:10 2006 @@ -32,7 +32,11 @@
int g_placementSelection = 0; int g_backgroundSelection = 0; + +/* this holds current selection of background color */ COLORREF g_backgroundDesktopColor = 0; +/* this holds selection of custom colors in dialog box */ +COLORREF custom_colors[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
int g_listViewItemCount = 0;
@@ -147,75 +151,70 @@
/* Add all the images in the C:\ReactOS directory. */
- LoadString(hApplet, IDS_SUPPORTED_EXT, szFileTypes, sizeof(szFileTypes) / sizeof(TCHAR)); + LoadString(hApplet, IDS_SUPPORTED_EXT, szFileTypes, sizeof(szFileTypes) / sizeof(TCHAR));
- token = _tcstok ( szFileTypes, separators ); - while ( token != NULL ) - { - GetWindowsDirectory(szSearchPath, MAX_PATH); - _tcscat(szSearchPath, TEXT("\")); - _tcscat(szSearchPath, token); + token = _tcstok ( szFileTypes, separators ); + while ( token != NULL ) + { + GetWindowsDirectory(szSearchPath, MAX_PATH); + _tcscat(szSearchPath, TEXT("\")); + _tcscat(szSearchPath, token); - hFind = FindFirstFile(szSearchPath, &fd); - while(hFind != INVALID_HANDLE_VALUE) - { - /* Don't add any hidden bitmaps */ - if((fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) - { - TCHAR filename[MAX_PATH]; + hFind = FindFirstFile(szSearchPath, &fd); + while(hFind != INVALID_HANDLE_VALUE) + { + /* Don't add any hidden bitmaps */ + if((fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) + { + TCHAR filename[MAX_PATH]; - GetWindowsDirectory(filename, MAX_PATH); - - _tcscat(filename, TEXT("\")); - _tcscat(filename, fd.cFileName); + GetWindowsDirectory(filename, MAX_PATH); + + _tcscat(filename, TEXT("\")); + _tcscat(filename, fd.cFileName); - himl = (HIMAGELIST)SHGetFileInfo(filename, - 0, - &sfi, - sizeof(sfi), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON | - SHGFI_DISPLAYNAME); - - if(himl == NULL) - { - break; - } + himl = (HIMAGELIST)SHGetFileInfo(filename, + 0, + &sfi, + sizeof(sfi), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON | + SHGFI_DISPLAYNAME); + + if(himl == NULL) break; - if(i++ == 0) - { - g_hShellImageList = himl; - (void)ListView_SetImageList(g_hBackgroundList, himl, LVSIL_SMALL); - } - - backgroundItem = &g_backgroundItems[g_listViewItemCount]; - - backgroundItem->bWallpaper = TRUE; + if(i++ == 0) + { + g_hShellImageList = himl; + (void)ListView_SetImageList(g_hBackgroundList, himl, LVSIL_SMALL); + } + + backgroundItem = &g_backgroundItems[g_listViewItemCount]; + + backgroundItem->bWallpaper = TRUE; - _tcscpy(backgroundItem->szDisplayName, sfi.szDisplayName); - _tcscpy(backgroundItem->szFilename, filename); - - ZeroMemory(&listItem, sizeof(LV_ITEM)); - listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE; - listItem.pszText = backgroundItem->szDisplayName; - listItem.state = 0; - listItem.iImage = sfi.iIcon; - listItem.iItem = g_listViewItemCount; - listItem.lParam = g_listViewItemCount; + _tcscpy(backgroundItem->szDisplayName, sfi.szDisplayName); + _tcscpy(backgroundItem->szFilename, filename); + + ZeroMemory(&listItem, sizeof(LV_ITEM)); + listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE; + listItem.pszText = backgroundItem->szDisplayName; + listItem.state = 0; + listItem.iImage = sfi.iIcon; + listItem.iItem = g_listViewItemCount; + listItem.lParam = g_listViewItemCount; - (void)ListView_InsertItem(g_hBackgroundList, &listItem); + (void)ListView_InsertItem(g_hBackgroundList, &listItem); - g_listViewItemCount++; - } + g_listViewItemCount++; + } - if(!FindNextFile(hFind, &fd)) - hFind = INVALID_HANDLE_VALUE; - } - - token = _tcstok ( NULL, separators ); - } - - + if(!FindNextFile(hFind, &fd)) + hFind = INVALID_HANDLE_VALUE; + } + + token = _tcstok ( NULL, separators ); + } }
void InitBackgroundDialog() @@ -229,8 +228,7 @@ BITMAP bitmap;
g_backgroundDesktopColor = GetSysColor( COLOR_BACKGROUND ); - - g_hBackgroundList = GetDlgItem(g_hBackgroundPage, IDC_BACKGROUND_LIST); + g_hBackgroundList = GetDlgItem(g_hBackgroundPage, IDC_BACKGROUND_LIST); g_hBackgroundPreview = GetDlgItem(g_hBackgroundPage, IDC_BACKGROUND_PREVIEW); g_hPlacementCombo = GetDlgItem(g_hBackgroundPage, IDC_PLACEMENT_COMBO); g_hColorButton = GetDlgItem(g_hBackgroundPage, IDC_COLOR_BUTTON); @@ -247,7 +245,17 @@ SendMessage(g_hPlacementCombo, CB_INSERTSTRING, PLACEMENT_TILE, (LPARAM)szString);
/* Load the default settings from the registry */ - RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\Desktop"), 0, KEY_ALL_ACCESS, ®Key); + result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\Desktop"), 0, KEY_ALL_ACCESS, ®Key); + if( result != ERROR_SUCCESS ) + { + /* reg key open failed; maybe it does not exist? create it! */ + DWORD dwDisposition = 0; + result = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Desktop"), 0, NULL, 0, KEY_ALL_ACCESS, NULL, + ®Key, &dwDisposition ); + /* now the key must be created & opened and regKey points to opened key */ + /* On error result will not contain ERROR_SUCCESS. I don't know how to handle */ + /* this case :( */ + }
result = RegQueryValueEx(regKey, TEXT("WallpaperStyle"), 0, &varType, (LPBYTE)szBuffer, &bufferSize);
@@ -296,37 +304,69 @@
void OnColorButton() { + /* Load custom colors from Registry */ + HKEY hKey = NULL; + LONG res = ERROR_SUCCESS; + res = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Appearance"), 0, NULL, 0, + KEY_ALL_ACCESS, NULL, &hKey, NULL ); + /* Now the key is either created or opened existing, if res == ERROR_SUCCESS */ + if( res == ERROR_SUCCESS ) + { + /* Key opened */ + DWORD dwType = REG_BINARY; + DWORD cbData = sizeof(custom_colors); + res = RegQueryValueEx( hKey, TEXT("CustomColors"), NULL, &dwType, + (LPBYTE)custom_colors, &cbData ); + RegCloseKey( hKey ); + hKey = NULL; + } + + /* Launch ChooseColor() dialog */ CHOOSECOLOR cc; - COLORREF custom_colors[16]; - cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = g_hBackgroundPage; cc.hInstance = NULL; cc.rgbResult = g_backgroundDesktopColor; - - memset(custom_colors, RGB(255,255,255), sizeof(custom_colors)); - cc.lpCustColors = custom_colors; cc.Flags = CC_ANYCOLOR | /* Causes the dialog box to display all available colors in the set of basic colors. */ - CC_FULLOPEN | /* opens dialog in full size */ - CC_RGBINIT ; /* init chosen color by rgbResult value */ + CC_FULLOPEN | /* opens dialog in full size */ + CC_RGBINIT ; /* init chosen color by rgbResult value */ cc.lCustData = 0; cc.lpfnHook = NULL; cc.lpTemplateName = NULL; - if( ChooseColor( &cc ) ) { - g_backgroundDesktopColor = cc.rgbResult; /* save selected color to var */ - PropSheet_Changed( GetParent( g_hBackgroundPage ), g_hBackgroundPage ); /* Apply button will be activated */ - InvalidateRect(g_hBackgroundPreview, NULL, TRUE); /* window will be updated :) */ - } -} - -BOOL CheckListBoxFilename(HWND list, TCHAR *filename) -{ - UNREFERENCED_PARAMETER(filename); - UNREFERENCED_PARAMETER(list); - return FALSE; + /* Save selected color to var */ + g_backgroundDesktopColor = cc.rgbResult; + /* Allpy buuton will be activated */ + PropSheet_Changed( GetParent( g_hBackgroundPage ), g_hBackgroundPage ); + /* Window will be updated :) */ + InvalidateRect(g_hBackgroundPreview, NULL, TRUE); + /* Save custom colors to reg. To this moment key must be ceated already. See above */ + res = RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Appearance"), 0, + KEY_WRITE, &hKey ); + if( res == ERROR_SUCCESS ) + { + /* Key opened */ + RegSetValueEx( hKey, TEXT("CustomColors"), 0, REG_BINARY, + (const BYTE *)custom_colors, sizeof(custom_colors) ); + RegCloseKey( hKey ); + hKey = NULL; + } + } +} + +BOOL CheckListViewFilenameExists(HWND hWndList, LPCTSTR tszFileName) +{ + /* ListView_FindItem() Macro: Searches for a list-view item with the specified * + * characteristics. Returns the index of the item if successful, or -1 otherwise */ + LVFINDINFO lvfi; + lvfi.flags = LVFI_STRING; /* search item by EXACT string */ + lvfi.psz = tszFileName; /* string to search */ + /* other items of this structure are not valid, besacuse flags are not set. */ + int retVal = ListView_FindItem( hWndList, -1, &lvfi ); + if( retVal != -1 ) return TRUE; /* item found! */ + return FALSE; /* item not found. */ }
void OnBrowseButton() @@ -361,7 +401,7 @@ if(GetOpenFileName(&ofn) == TRUE) { /* Check if there is already a entry that holds this filename */ - if(CheckListBoxFilename(g_hBackgroundList, filename) == TRUE) + if(CheckListViewFilenameExists(g_hBackgroundList, ofn.lpstrFileTitle) == TRUE) return;
if(g_listViewItemCount > (MAX_BACKGROUNDS - 1)) @@ -419,7 +459,7 @@
InvalidateRect(g_hBackgroundPreview, NULL, TRUE);
- EnableWindow(g_hColorButton, (backgroundItem->bWallpaper == FALSE ? TRUE : FALSE)); + EnableWindow(g_hColorButton, (backgroundItem->bWallpaper == FALSE ? TRUE : FALSE)); EnableWindow(g_hPlacementCombo, backgroundItem->bWallpaper);
PropSheet_Changed(GetParent(g_hBackgroundPage), g_hBackgroundPage); @@ -427,19 +467,18 @@
void DrawBackgroundPreview(LPDRAWITEMSTRUCT draw) { - float scaleX; - float scaleY; - int scaledWidth; - int scaledHeight; - int posX; - int posY; + float scaleX; + float scaleY; + int scaledWidth; + int scaledHeight; + int posX; + int posY;
if(g_backgroundItems[g_backgroundSelection].bWallpaper == FALSE) { + /* update desktop background color image */ HBRUSH hBrush = CreateSolidBrush( g_backgroundDesktopColor ); - //HBRUSH hBrushOld = SelectObject( draw->hDC, hBrush ); FillRect(draw->hDC, &draw->rcItem, hBrush ); - //SelectObject( draw->hDC, hBrushOld ); DeleteObject( hBrush ); return; } @@ -562,26 +601,31 @@
void SetDesktopBackColor() { - /* change system color */ + /* Change system color */ INT iElement = COLOR_BACKGROUND; - if(!SetSysColors(1, &iElement, &g_backgroundDesktopColor)) - { - MessageBox(g_hBackgroundPage, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */ - TEXT("Error!"), MB_ICONSTOP ); - } - - /* write color to registry key: HKEY_CURRENT_USER\Control Panel\Colors\Background */ + if( !SetSysColors( 1, &iElement, &g_backgroundDesktopColor ) ) + MessageBox( g_hBackgroundPage, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */ + TEXT("Error!"), MB_ICONSTOP ); + /* Write color to registry key: HKEY_CURRENT_USER\Control Panel\Colors\Background */ HKEY hKey = NULL; - if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Colors"), 0, KEY_WRITE, &hKey ) == ERROR_SUCCESS ) - { - TCHAR clText[16] = {0}; // COLORREF(DWORD) holds colors as := 0x00BBGGRR - DWORD red = (g_backgroundDesktopColor & 0x000000FF); - DWORD green = (g_backgroundDesktopColor & 0x0000FF00) >> 8; - DWORD blue = (g_backgroundDesktopColor & 0x00FF0000) >> 16; - wsprintf( clText, TEXT("%d %d %d"), red, green, blue ); /* format string to be set to registry */ - RegSetValueEx( hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText, lstrlen( clText )*sizeof(TCHAR) + sizeof(TCHAR) ); - RegCloseKey( hKey ); - } + LONG result = ERROR_SUCCESS; + result = RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Colors"), 0, KEY_WRITE, &hKey ); + if( result != ERROR_SUCCESS ) + { + /* Key open failed; maybe it does not exist? create it! */ + result = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\Colors"), 0, NULL, 0, + KEY_ALL_ACCESS, NULL, &hKey, NULL ); + /* Now key must be created and opened and hKey must point at newly created key */ + /* On error result will not contain ERROR_SUCCESS. I don't know how to handle */ + /* this case :( */ + } + TCHAR clText[16] = {0}; + DWORD red = GetRValue( g_backgroundDesktopColor ); + DWORD green = GetGValue( g_backgroundDesktopColor ); + DWORD blue = GetBValue( g_backgroundDesktopColor ); + wsprintf( clText, TEXT("%d %d %d"), red, green, blue ); /* format string to be set to registry */ + RegSetValueEx( hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText, lstrlen( clText )*sizeof(TCHAR) + sizeof(TCHAR) ); + RegCloseKey( hKey ); }
INT_PTR CALLBACK BackgroundPageProc(HWND hwndDlg,