From 96c892841aa2e85cf0cd9b9f773cd3527d230b8d Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Mon, 30 Mar 2009 19:08:16 +0000 Subject: [PATCH] Create the system and device imagelists with the correct bpp Do the same with the explorer stuff svn path=/trunk/; revision=40297 --- .../base/shell/explorer/shell/mainframe.cpp | 25 +++- .../shell/explorer/shell/shellbrowser.cpp | 27 ++++- reactos/dll/win32/setupapi/devclass.c | 33 ++++- reactos/dll/win32/setupapi/setupapi.rbuild | 1 + reactos/dll/win32/shell32/iconcache.c | 113 +++++++++++++----- 5 files changed, 161 insertions(+), 38 deletions(-) diff --git a/reactos/base/shell/explorer/shell/mainframe.cpp b/reactos/base/shell/explorer/shell/mainframe.cpp index 5be76d65580..c83655323ae 100644 --- a/reactos/base/shell/explorer/shell/mainframe.cpp +++ b/reactos/base/shell/explorer/shell/mainframe.cpp @@ -152,7 +152,30 @@ int MainFrameBase::OpenShellFolders(LPIDA pida, HWND hFrameWnd) MainFrameBase::MainFrameBase(HWND hwnd) : super(hwnd) { - _himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK|ILC_COLOR24, 2, 0); + HDC hDC = GetDC(NULL); + if (hDC) + { + DWORD ilMask; + INT bpp = GetDeviceCaps(hDC, BITSPIXEL); + ReleaseDC(NULL, hDC); + + if (bpp <= 4) + ilMask = ILC_COLOR4; + else if (bpp <= 8) + ilMask = ILC_COLOR8; + else if (bpp <= 16) + ilMask = ILC_COLOR16; + else if (bpp <= 24) + ilMask = ILC_COLOR24; + else if (bpp <= 32) + ilMask = ILC_COLOR32; + else + ilMask = ILC_COLOR; + + ilMask |= ILC_MASK; + + _himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ilMask, 2, 0); + } _hMenuFrame = GetMenu(hwnd); _hMenuWindow = GetSubMenu(_hMenuFrame, GetMenuItemCount(_hMenuFrame)-3); diff --git a/reactos/base/shell/explorer/shell/shellbrowser.cpp b/reactos/base/shell/explorer/shell/shellbrowser.cpp index b77411ffda2..26a41532ec5 100644 --- a/reactos/base/shell/explorer/shell/shellbrowser.cpp +++ b/reactos/base/shell/explorer/shell/shellbrowser.cpp @@ -58,8 +58,31 @@ ShellBrowser::ShellBrowser(HWND hwnd, HWND hwndFrame, HWND left_hwnd, WindowHand _cur_dir = NULL; - _himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK|ILC_COLOR24, 2, 0); - ImageList_SetBkColor(_himl, GetSysColor(COLOR_WINDOW)); + HDC hDC = GetDC(NULL); + if (hDC) + { + INT bpp = GetDeviceCaps(hDC, BITSPIXEL); + ReleaseDC(NULL, hDC); + + DWORD ilMask; + if (bpp <= 4) + ilMask = ILC_COLOR4; + else if (bpp <= 8) + ilMask = ILC_COLOR8; + else if (bpp <= 16) + ilMask = ILC_COLOR16; + else if (bpp <= 24) + ilMask = ILC_COLOR24; + else if (bpp <= 32) + ilMask = ILC_COLOR32; + else + ilMask = ILC_COLOR; + + ilMask |= ILC_MASK; + + _himl = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ilMask, 2, 0); + ImageList_SetBkColor(_himl, GetSysColor(COLOR_WINDOW)); + } } ShellBrowser::~ShellBrowser() diff --git a/reactos/dll/win32/setupapi/devclass.c b/reactos/dll/win32/setupapi/devclass.c index a4dd3f1a74c..9fb62bf8cd3 100644 --- a/reactos/dll/win32/setupapi/devclass.c +++ b/reactos/dll/win32/setupapi/devclass.c @@ -480,10 +480,12 @@ SetupDiGetClassImageListExW( else { struct ClassImageList *list = NULL; + HDC hDC; DWORD RequiredSize; + DWORD ilMask, bkColor; HICON hIcon; DWORD size; - INT i; + INT i, bpp; /* Get list of all class GUIDs in given computer */ ret = SetupDiBuildClassInfoListExW( @@ -529,12 +531,39 @@ SetupDiGetClassImageListExW( /* Prepare a HIMAGELIST */ InitCommonControls(); - ClassImageListData->ImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 100, 10); + + hDC = GetDC(NULL); + if (!hDC) + goto cleanup; + + bpp = GetDeviceCaps(hDC, BITSPIXEL); + ReleaseDC(NULL, hDC); + + if (bpp <= 4) + ilMask = ILC_COLOR4; + else if (bpp <= 8) + ilMask = ILC_COLOR8; + else if (bpp <= 16) + ilMask = ILC_COLOR16; + else if (bpp <= 24) + ilMask = ILC_COLOR24; + else if (bpp <= 32) + ilMask = ILC_COLOR32; + else + ilMask = ILC_COLOR; + + ilMask |= ILC_MASK; + + ClassImageListData->ImageList = ImageList_Create(16, 16, ilMask, 100, 10); if (!ClassImageListData->ImageList) goto cleanup; ClassImageListData->Reserved = (ULONG_PTR)list; + /* For some reason, Windows sets the list background to COLOR_WINDOW */ + bkColor = GetSysColor(COLOR_WINDOW); + ImageList_SetBkColor(ClassImageListData->ImageList, bkColor); + /* Now, we "simply" need to load icons associated with all class guids, * and put their index in the image list in the IconIndexes array */ for (i = 0; i < list->NumberOfGuids; i++) diff --git a/reactos/dll/win32/setupapi/setupapi.rbuild b/reactos/dll/win32/setupapi/setupapi.rbuild index 68bbb2d4032..2741eb68824 100644 --- a/reactos/dll/win32/setupapi/setupapi.rbuild +++ b/reactos/dll/win32/setupapi/setupapi.rbuild @@ -10,6 +10,7 @@ uuid wine ntdll + gdi32 comctl32 kernel32 advapi32 diff --git a/reactos/dll/win32/shell32/iconcache.c b/reactos/dll/win32/shell32/iconcache.c index 9e1ade7d438..a9ab1035811 100644 --- a/reactos/dll/win32/shell32/iconcache.c +++ b/reactos/dll/win32/shell32/iconcache.c @@ -375,51 +375,98 @@ INT SIC_GetIconIndex (LPCWSTR sSourceFile, INT dwSourceIndex, DWORD dwFlags ) */ BOOL SIC_Initialize(void) { - HICON hSm, hLg; - int cx_small, cy_small; - int cx_large, cy_large; + HICON hSm = NULL, hLg = NULL; + INT cx_small, cy_small; + INT cx_large, cy_large; + HDC hDC; + INT bpp; + DWORD ilMask; - cx_small = GetSystemMetrics(SM_CXSMICON); - cy_small = GetSystemMetrics(SM_CYSMICON); - cx_large = GetSystemMetrics(SM_CXICON); - cy_large = GetSystemMetrics(SM_CYICON); + TRACE("Entered SIC_Initialize\n"); - TRACE("\n"); + if (sic_hdpa) /* already initialized?*/ + { + return TRUE; + } - if (sic_hdpa) /* already initialized?*/ - return TRUE; + sic_hdpa = DPA_Create(16); + if (!sic_hdpa) + { + return FALSE; + } - sic_hdpa = DPA_Create(16); + hDC = GetDC(NULL); + if (!hDC) + { + return FALSE; + } - if (!sic_hdpa) - { - return(FALSE); - } + bpp = GetDeviceCaps(hDC, BITSPIXEL); + ReleaseDC(NULL, hDC); - ShellSmallIconList = ImageList_Create(cx_small,cy_small,ILC_COLOR32|ILC_MASK,0,0x20); - ShellBigIconList = ImageList_Create(cx_large,cy_large,ILC_COLOR32|ILC_MASK,0,0x20); + if (bpp <= 4) + ilMask = ILC_COLOR4; + else if (bpp <= 8) + ilMask = ILC_COLOR8; + else if (bpp <= 16) + ilMask = ILC_COLOR16; + else if (bpp <= 24) + ilMask = ILC_COLOR24; + else if (bpp <= 32) + ilMask = ILC_COLOR32; + else + ilMask = ILC_COLOR; - ImageList_SetBkColor(ShellSmallIconList, CLR_NONE); - ImageList_SetBkColor(ShellBigIconList, CLR_NONE); + ilMask |= ILC_MASK; - /* Load the document icon, which is used as the default if an icon isn't found. */ - hSm = (HICON)LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT), - IMAGE_ICON, cx_small, cy_small, LR_SHARED); - hLg = (HICON)LoadImageA(shell32_hInstance, MAKEINTRESOURCEA(IDI_SHELL_DOCUMENT), - IMAGE_ICON, cx_large, cy_large, LR_SHARED); + cx_small = GetSystemMetrics(SM_CXSMICON); + cy_small = GetSystemMetrics(SM_CYSMICON); + cx_large = GetSystemMetrics(SM_CXICON); + cy_large = GetSystemMetrics(SM_CYICON); - if (!hSm || !hLg) - { - FIXME("Failed to load IDI_SHELL_DOCUMENT icon!\n"); - return FALSE; - } + ShellSmallIconList = ImageList_Create(cx_small, + cy_small, + ilMask, + 100, + 100); + if (ShellSmallIconList) + { + /* Load the document icon, which is used as the default if an icon isn't found. */ + hSm = (HICON)LoadImageW(shell32_hInstance, + MAKEINTRESOURCEW(IDI_SHELL_DOCUMENT), + IMAGE_ICON, + cx_small, + cy_small, + LR_SHARED | LR_DEFAULTCOLOR); + } - SIC_IconAppend (swShell32Name, IDI_SHELL_DOCUMENT-1, hSm, hLg, 0); - SIC_IconAppend (swShell32Name, -IDI_SHELL_DOCUMENT, hSm, hLg, 0); + ShellBigIconList = ImageList_Create(cx_large, + cy_large, + ilMask, + 100, + 100); + if (!ShellSmallIconList) + { + hLg = (HICON)LoadImageW(shell32_hInstance, + MAKEINTRESOURCEW(IDI_SHELL_DOCUMENT), + IMAGE_ICON, + cx_large, + cy_large, + LR_SHARED | LR_DEFAULTCOLOR); + } - TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList); + if (!hSm || !hLg) + { + FIXME("Failed to load IDI_SHELL_DOCUMENT icon!\n"); + return FALSE; + } - return TRUE; + SIC_IconAppend(swShell32Name, IDI_SHELL_DOCUMENT-1, hSm, hLg, 0); + SIC_IconAppend(swShell32Name, -IDI_SHELL_DOCUMENT, hSm, hLg, 0); + + TRACE("hIconSmall=%p hIconBig=%p\n",ShellSmallIconList, ShellBigIconList); + + return TRUE; } /************************************************************************* * SIC_Destroy