Author: gedmurphy
Date: Fri Jan 11 20:17:19 2008
New Revision: 31727
URL:
http://svn.reactos.org/svn/reactos?rev=31727&view=rev
Log:
Start to reorganize and rewrite parts of the usermode code for handling icons.
Rewrite the CopyImage code for icons following the same call chain as Vista uses. The rest
of the UM code will follow suit.
Modified:
branches/curicon_rewrite/dll/win32/user32/windows/bitmap.c
branches/curicon_rewrite/dll/win32/user32/windows/cursor.c
branches/curicon_rewrite/dll/win32/user32/windows/icon.c
Modified: branches/curicon_rewrite/dll/win32/user32/windows/bitmap.c
URL:
http://svn.reactos.org/svn/reactos/branches/curicon_rewrite/dll/win32/user3…
==============================================================================
--- branches/curicon_rewrite/dll/win32/user32/windows/bitmap.c (original)
+++ branches/curicon_rewrite/dll/win32/user32/windows/bitmap.c Fri Jan 11 20:17:19 2008
@@ -1,29 +1,10 @@
/*
- * ReactOS kernel
- * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- *
- * PROJECT: ReactOS user32.dll
- * FILE: lib/user32/windows/input.c
- * PURPOSE: Input
- * PROGRAMMER: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- * UPDATE HISTORY:
- * 09-05-2001 CSH Created
+ * PROJECT: ReactOS User32 dll
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: dll/win32/user32/bitmap.c
+ * PURPOSE: Bitmap handling code
+ * PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
+ * Ged Murphy (gedmurphy(a)reactos.org)
*/
/* INCLUDES ******************************************************************/
@@ -32,6 +13,8 @@
#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(user32);
+
+/* TYPES *********************************************************************/
#include "pshpack1.h"
@@ -62,40 +45,8 @@
CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width, int height,
int colors);
CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir, int width, int height,
int colors);
-/* FUNCTIONS *****************************************************************/
-
-/*
- * @implemented
- */
-HANDLE STDCALL
-LoadImageA(HINSTANCE hinst,
- LPCSTR lpszName,
- UINT uType,
- int cxDesired,
- int cyDesired,
- UINT fuLoad)
-{
- LPWSTR lpszWName;
- HANDLE Handle;
- UNICODE_STRING NameString;
-
- if (HIWORD(lpszName))
- {
- RtlCreateUnicodeStringFromAsciiz(&NameString, (LPSTR)lpszName);
- lpszWName = NameString.Buffer;
- Handle = LoadImageW(hinst, lpszWName, uType, cxDesired,
- cyDesired, fuLoad);
- RtlFreeUnicodeString(&NameString);
- }
- else
- {
- Handle = LoadImageW(hinst, (LPCWSTR)lpszName, uType, cxDesired,
- cyDesired, fuLoad);
- }
-
- return Handle;
-}
-
+
+/* PRIVATE FUNCTIONS *********************************************************/
/*
* The following macro functions account for the irregularities of
@@ -505,68 +456,6 @@
UnmapViewOfFile(BitmapInfo);
return hBitmap;
-}
-
-HANDLE STDCALL
-LoadImageW(
- IN HINSTANCE hinst,
- IN LPCWSTR lpszName,
- IN UINT uType,
- IN INT cxDesired,
- IN INT cyDesired,
- IN UINT fuLoad)
-{
- if (fuLoad & LR_DEFAULTSIZE)
- {
- if (uType == IMAGE_ICON)
- {
- if (cxDesired == 0)
- cxDesired = GetSystemMetrics(SM_CXICON);
- if (cyDesired == 0)
- cyDesired = GetSystemMetrics(SM_CYICON);
- }
- else if (uType == IMAGE_CURSOR)
- {
- if (cxDesired == 0)
- cxDesired = GetSystemMetrics(SM_CXCURSOR);
- if (cyDesired == 0)
- cyDesired = GetSystemMetrics(SM_CYCURSOR);
- }
- }
-
- switch (uType)
- {
- case IMAGE_BITMAP:
- return LoadBitmapImage(hinst, lpszName, fuLoad);
- case IMAGE_CURSOR:
- case IMAGE_ICON:
- return LoadCursorIconImage(hinst, lpszName, cxDesired, cyDesired,
- fuLoad, uType);
- default:
- break;
- }
-
- return NULL;
-}
-
-
-/*
- * @implemented
- */
-HBITMAP STDCALL
-LoadBitmapA(HINSTANCE hInstance, LPCSTR lpBitmapName)
-{
- return LoadImageA(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0, 0);
-}
-
-
-/*
- * @implemented
- */
-HBITMAP STDCALL
-LoadBitmapW(HINSTANCE hInstance, LPCWSTR lpBitmapName)
-{
- return LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0, 0);
}
@@ -764,28 +653,27 @@
return pbi->bmiHeader.biBitCount;
}
-#if 0
+#if 1
static BOOL
SetCursorIconData(
HANDLE Handle,
- HINSTANCE hMod,
+ LPWSTR lpMod,
LPWSTR lpResName,
PICONINFO pIconInfo)
{
-
- UNICODE_STRING Res;
+ UNICODE_STRING Mod, Res;
+ POINT p = {pIconInfo->xHotspot, pIconInfo->yHotspot}; // remove
if (!Handle || !pIconInfo)
return FALSE;
+ RtlInitUnicodeString(&Mod, lpResName);
RtlInitUnicodeString(&Res, lpResName);
- return NtUserSetCursorIconData(Handle, hMod, &Res, pIconInfo);
-
-}
-
-
-/* bare bones icon copy implementation */
+ //return NtUserSetCursorIconData(Handle, &Mod, &Res, pIconInfo);
+ return NtUserSetCursorIconData(Handle, &pIconInfo->fIcon, &p, NULL, NULL,
NULL);
+}
+
static HANDLE
CopyIcoCur(HANDLE hIconCur,
UINT type,
@@ -794,57 +682,228 @@
UINT flags)
{
HANDLE hNewIcon = NULL;
- ICONINFO origIconInfo, newIconInfo;
+ ICONINFO IconInfo;
SIZE origSize;
DWORD origBpp;
if (!hIconCur)
return NULL;
+ if ((desiredx < 0) || (desiredy < 0))
+ return NULL;
+
if (flags & LR_COPYFROMRESOURCE)
{
TRACE("FIXME: LR_COPYFROMRESOURCE is yet not implemented for
icons\n");
}
+ /* Get the original icon size */
if (NtUserGetIconSize(hIconCur, 0, &origSize.cx, &origSize.cy))
{
+ /* use the original size 0 was passed in */
if (desiredx == 0) desiredx = origSize.cx;
- if (desiredx == 0) desiredy = origSize.cy;
-
- if (NtUserGetIconInfo(hIconCur, &origIconInfo, NULL, NULL, &origBpp,
TRUE))
- {
- hNewIcon = (HANDLE)NtUserCallOneParam(0,
ONEPARAM_ROUTINE_CREATECURICONHANDLE);
-
- if (hNewIcon)
+ if (desiredy == 0) desiredy = origSize.cy;
+ }
+ else
+ {
+ TRACE("Failed to retrieve original icon dimensions\n");
+ return NULL;
+ }
+
+ /* get the original icon info */
+ if (NtUserGetIconInfo(hIconCur, &IconInfo, NULL, NULL, &origBpp, TRUE))
+ {
+ /* stretch the bitmap if required */
+ if ((desiredx != origSize.cx) || (desiredy != origSize.cy))
+ {
+ HBITMAP hBitmap;
+ BOOL bSuccess = FALSE;
+
+ /* create a stretched copy of the color bitmap */
+ hBitmap = CopyBmp(IconInfo.hbmColor, IMAGE_BITMAP, desiredx, desiredy,
flags);
+ if (hBitmap)
{
- /* the bitmaps returned from the NtUserGetIconInfo are copies of the
original,
- * so we can use these directly to build up our icon/cursor copy */
- RtlCopyMemory(&newIconInfo, &origIconInfo, sizeof(ICONINFO));
-
- if (!SetCursorIconData(hNewIcon, NULL, NULL, &newIconInfo))
+ /* delete the original bitmap and set the new one */
+ DeleteObject(IconInfo.hbmColor);
+ IconInfo.hbmColor = hBitmap;
+
+ /* create a stretched copy of the mask bitmap */
+ hBitmap = CopyBmp(IconInfo.hbmMask, IMAGE_BITMAP, desiredx, desiredy,
flags);
+ if (hBitmap)
{
- if (newIconInfo.fIcon)
- DestroyIcon(hNewIcon);
- else
- DestroyCursor(hNewIcon);
-
- hNewIcon = NULL;
+ /* delete the original bitmap and set the new one */
+ DeleteObject(IconInfo.hbmMask);
+ IconInfo.hbmMask = hBitmap;
+ bSuccess = TRUE;
}
}
- DeleteObject(origIconInfo.hbmMask);
- DeleteObject(origIconInfo.hbmColor);
- }
+ if (!bSuccess) goto error;
+ }
+
+ /* create a new icon handle */
+ hNewIcon = (HANDLE)NtUserCallOneParam(0, ONEPARAM_ROUTINE_CREATECURICONHANDLE);
+ if (hNewIcon)
+ {
+ /* set the icon data */
+ if (!SetCursorIconData(hNewIcon, NULL, NULL, &IconInfo))
+ {
+ goto error;
+ }
+ }
+
+ /* delete the bitmaps, we're done with them now */
+ DeleteObject(IconInfo.hbmMask);
+ DeleteObject(IconInfo.hbmColor);
}
if (hNewIcon && (flags & LR_COPYDELETEORG))
{
+ /* delete the icon we copied from */
DestroyCursor((HCURSOR)hIconCur);
}
+ /* return the copied icon */
return hNewIcon;
+
+error:
+ if (hNewIcon)
+ DestroyCursor(hNewIcon);
+
+ DeleteObject(IconInfo.hbmColor);
+ DeleteObject(IconInfo.hbmMask);
+
+ return NULL;
}
#endif
+
+
+
+/* PUBLIC FUNCTIONS **********************************************************/
+
+/*
+ * @implemented
+ */
+HANDLE STDCALL
+LoadImageW(IN HINSTANCE hinst,
+ IN LPCWSTR lpszName,
+ IN UINT uType,
+ IN INT cxDesired,
+ IN INT cyDesired,
+ IN UINT fuLoad)
+{
+ if (fuLoad & LR_DEFAULTSIZE)
+ {
+ if (uType == IMAGE_ICON)
+ {
+ if (cxDesired == 0)
+ cxDesired = GetSystemMetrics(SM_CXICON);
+ if (cyDesired == 0)
+ cyDesired = GetSystemMetrics(SM_CYICON);
+ }
+ else if (uType == IMAGE_CURSOR)
+ {
+ if (cxDesired == 0)
+ cxDesired = GetSystemMetrics(SM_CXCURSOR);
+ if (cyDesired == 0)
+ cyDesired = GetSystemMetrics(SM_CYCURSOR);
+ }
+ }
+
+ switch (uType)
+ {
+ case IMAGE_BITMAP:
+ return LoadBitmapImage(hinst,
+ lpszName,
+ fuLoad);
+ case IMAGE_CURSOR:
+ case IMAGE_ICON:
+ return LoadCursorIconImage(hinst,
+ lpszName,
+ cxDesired,
+ cyDesired,
+ fuLoad,
+ uType);
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+
+/*
+ * @implemented
+ */
+HBITMAP STDCALL
+LoadBitmapA(HINSTANCE hInstance,
+ LPCSTR lpBitmapName)
+{
+ return LoadImageA(hInstance,
+ lpBitmapName,
+ IMAGE_BITMAP,
+ 0,
+ 0,
+ 0);
+}
+
+
+/*
+ * @implemented
+ */
+HBITMAP STDCALL
+LoadBitmapW(HINSTANCE hInstance,
+ LPCWSTR lpBitmapName)
+{
+ return LoadImageW(hInstance,
+ lpBitmapName,
+ IMAGE_BITMAP,
+ 0,
+ 0,
+ 0);
+}
+
+
+/*
+ * @implemented
+ */
+HANDLE STDCALL
+LoadImageA(HINSTANCE hinst,
+ LPCSTR lpszName,
+ UINT uType,
+ int cxDesired,
+ int cyDesired,
+ UINT fuLoad)
+{
+ LPWSTR lpszWName;
+ HANDLE Handle;
+ UNICODE_STRING NameString;
+
+ if (HIWORD(lpszName))
+ {
+ RtlCreateUnicodeStringFromAsciiz(&NameString, (LPSTR)lpszName);
+ lpszWName = NameString.Buffer;
+ Handle = LoadImageW(hinst,
+ lpszWName,
+ uType,
+ cxDesired,
+ cyDesired,
+ fuLoad);
+ RtlFreeUnicodeString(&NameString);
+ }
+ else
+ {
+ Handle = LoadImageW(hinst,
+ (LPCWSTR)lpszName,
+ uType,
+ cxDesired,
+ cyDesired,
+ fuLoad);
+ }
+
+ return Handle;
+}
+
/*
* @unimplemented
@@ -871,31 +930,21 @@
* if the source is a DIB section.
* The LR_MONOCHROME flag is ignored if LR_CREATEDIBSECTION is present.
*/
- switch (type)
- {
- case IMAGE_BITMAP:
- return CopyBmp(hnd, type, desiredx, desiredy, flags);
-
- case IMAGE_ICON:
- //return CopyIcoCur(hnd, type, desiredx, desiredy, flags);
- return CopyIcon(hnd);
-
- case IMAGE_CURSOR:
- {
- static BOOL IconMsgDisplayed = FALSE;
- /* FIXME: support loading the image as shared from an instance */
- if (!IconMsgDisplayed)
- {
- FIXME("FIXME: CopyImage doesn't support IMAGE_CURSOR
correctly!\n");
- IconMsgDisplayed = TRUE;
- }
- /* Should call CURSORICON_ExtCopy but more testing
- * needs to be done before we change this
- */
- if (flags) FIXME("FIXME: Flags are ignored\n");
+ switch (type)
+ {
+ case IMAGE_BITMAP:
+ return CopyBmp(hnd, type, desiredx, desiredy, flags);
+
+ case IMAGE_ICON:
+ //return CopyIcoCur(hnd, type, desiredx, desiredy, flags);
+ return CopyIcon(hnd);
+
+ case IMAGE_CURSOR:
+ {
+ //return CopyIcoCur(hnd, type, desiredx, desiredy, flags);
return CopyCursor(hnd);
- }
- }
-
- return NULL;
-}
+ }
+ }
+
+ return NULL;
+}
Modified: branches/curicon_rewrite/dll/win32/user32/windows/cursor.c
URL:
http://svn.reactos.org/svn/reactos/branches/curicon_rewrite/dll/win32/user3…
==============================================================================
--- branches/curicon_rewrite/dll/win32/user32/windows/cursor.c (original)
+++ branches/curicon_rewrite/dll/win32/user32/windows/cursor.c Fri Jan 11 20:17:19 2008
@@ -1,29 +1,10 @@
/*
- * ReactOS kernel
- * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- *
- * PROJECT: ReactOS user32.dll
- * FILE: lib/user32/windows/cursor.c
- * PURPOSE: Cursor
- * PROGRAMMER: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- * UPDATE HISTORY:
- * 09-05-2001 CSH Created
+ * PROJECT: ReactOS User32 dll
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: dll/win32/user32/cursor.c
+ * PURPOSE: Curosr handling code
+ * PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
+ * Ged Murphy (gedmurphy(a)reactos.org)
*/
/* INCLUDES ******************************************************************/
@@ -36,35 +17,36 @@
#undef CopyCursor
-HBITMAP
-CopyBitmap(HBITMAP bmp);
-
-/* INTERNAL ******************************************************************/
+HBITMAP CopyBitmap(HBITMAP bmp);
+
+
+/* PRIVATE FUNCTIONS *********************************************************/
+
/* This callback routine is called directly after switching to gui mode */
NTSTATUS STDCALL
User32SetupDefaultCursors(PVOID Arguments, ULONG ArgumentLength)
{
- BOOL *DefaultCursor = (BOOL*)Arguments;
- LRESULT Result = TRUE;
-
- if(*DefaultCursor)
- {
- /* set default cursor */
- SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
- }
- else
- {
- /* FIXME load system cursor scheme */
- SetCursor(0);
- SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
- }
-
- return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
-}
-
-/* FUNCTIONS *****************************************************************/
-
+ BOOL *DefaultCursor = (BOOL*)Arguments;
+ LRESULT Result = TRUE;
+
+ if(*DefaultCursor)
+ {
+ /* set default cursor */
+ SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
+ }
+ else
+ {
+ /* FIXME load system cursor scheme */
+ SetCursor(0);
+ SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
+ }
+
+ return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
+}
+
+
+/* PUBLIC FUNCTIONS **********************************************************/
/*
* @implemented
Modified: branches/curicon_rewrite/dll/win32/user32/windows/icon.c
URL:
http://svn.reactos.org/svn/reactos/branches/curicon_rewrite/dll/win32/user3…
==============================================================================
--- branches/curicon_rewrite/dll/win32/user32/windows/icon.c (original)
+++ branches/curicon_rewrite/dll/win32/user32/windows/icon.c Fri Jan 11 20:17:19 2008
@@ -1,29 +1,10 @@
/*
- * ReactOS kernel
- * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- *
- * PROJECT: ReactOS user32.dll
- * FILE: lib/user32/windows/icon.c
- * PURPOSE: Icon
- * PROGRAMMER: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
- * UPDATE HISTORY:
- * 09-05-2001 CSH Created
+ * PROJECT: ReactOS User32 dll
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: dll/win32/user32/icon.c
+ * PURPOSE: Icon handling code
+ * PROGRAMMERS: Casper S. Hornstrup (chorns(a)users.sourceforge.net)
+ * Ged Murphy (gedmurphy(a)reactos.org)
*/
/* INCLUDES ******************************************************************/
@@ -33,8 +14,8 @@
#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(user32);
-/* FUNCTIONS *****************************************************************/
-
+
+/* PRIVATE FUNCTIONS *********************************************************/
HICON
ICON_CreateIconFromData(HDC hDC, PVOID ImageData, ICONIMAGE* IconImage, int cxDesired,
int cyDesired, int xHotspot, int yHotspot)
@@ -142,6 +123,206 @@
return NtUserCreateCursorIconHandle(&IconInfo, FALSE);
}
+
+
+
+
+/*
+ * The following macro function accounts for the irregularities of
+ * accessing cursor and icon resources in files and resource entries.
+ */
+typedef BOOL
+(*fnGetCIEntry)(LPVOID dir, int n, int *width, int *height, int *bits );
+
+/**********************************************************************
+ * CURSORICON_FindBestIcon
+ *
+ * Find the icon closest to the requested size and number of colors.
+ */
+static int
+CURSORICON_FindBestIcon(LPVOID dir,
+ fnGetCIEntry get_entry,
+ int Width,
+ int Height,
+ int ColorBits)
+{
+ int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
+ UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
+ UINT iTempXDiff, iTempYDiff, iTempColorDiff;
+
+ /* Find Best Fit */
+ iTotalDiff = 0xFFFFFFFF;
+ iColorDiff = 0xFFFFFFFF;
+ for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
+ {
+ iTempXDiff = abs(Width - cx);
+ iTempYDiff = abs(Height - cy);
+
+ if(iTotalDiff > (iTempXDiff + iTempYDiff))
+ {
+ iXDiff = iTempXDiff;
+ iYDiff = iTempYDiff;
+ iTotalDiff = iXDiff + iYDiff;
+ }
+ }
+
+ /* Find Best Colors for Best Fit */
+ for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
+ {
+ if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
+ {
+ iTempColorDiff = abs(ColorBits - Bits);
+ if(iColorDiff > iTempColorDiff)
+ {
+ BestEntry = i;
+ BestBits = Bits;
+ iColorDiff = iTempColorDiff;
+ }
+ }
+ }
+
+ TRACE("Best Icon: ResId: %d, bits : %d\n", BestEntry, BestBits);
+
+ return BestEntry;
+}
+
+
+
+/**********************************************************************
+ * CURSORICON_FindBestCursor
+ *
+ * Find the cursor closest to the requested size.
+ * FIXME: parameter 'color' ignored and entries with more than 1 bpp
+ * ignored too
+ */
+static int
+CURSORICON_FindBestCursor(LPVOID dir,
+ fnGetCIEntry get_entry,
+ int Width,
+ int Height,
+ int ColorBits)
+{
+ int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
+ UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
+ UINT iTempXDiff, iTempYDiff, iTempColorDiff;
+
+ /* Find Best Fit */
+ iTotalDiff = 0xFFFFFFFF;
+ iColorDiff = 0xFFFFFFFF;
+ for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
+ {
+ iTempXDiff = abs(Width - cx);
+ iTempYDiff = abs(Height - cy);
+
+ if(iTotalDiff > (iTempXDiff + iTempYDiff))
+ {
+ iXDiff = iTempXDiff;
+ iYDiff = iTempYDiff;
+ iTotalDiff = iXDiff + iYDiff;
+ }
+ }
+
+ /* Find Best Colors for Best Fit */
+ for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
+ {
+ if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
+ {
+ iTempColorDiff = abs(ColorBits - Bits);
+ if(iColorDiff > iTempColorDiff)
+ {
+ BestEntry = i;
+ BestBits = Bits;
+ iColorDiff = iTempColorDiff;
+ }
+ }
+ }
+
+ TRACE("Best Cursor: ResId: %d, bits : %d\n", BestEntry, BestBits);
+
+ return BestEntry;
+}
+
+
+static BOOL
+CURSORICON_GetResIconEntry(LPVOID dir,
+ int n,
+ int *Width,
+ int *Height,
+ int *Bits)
+{
+ GRPCURSORICONDIR *ResDir = dir;
+ ICONRESDIR *Icon;
+
+ if (ResDir->idCount <= n)
+ return FALSE;
+
+ Icon = &ResDir->idEntries[n].ResInfo.icon;
+ *Width = Icon->bWidth;
+ *Height = Icon->bHeight;
+ *Bits = ResDir->idEntries[n].wBitCount;
+ return TRUE;
+}
+
+static BOOL
+CURSORICON_GetResCursorEntry(LPVOID dir,
+ int n,
+ int *Width,
+ int *Height,
+ int *Bits)
+{
+ GRPCURSORICONDIR *ResDir = dir;
+ CURSORRESDIR *Cursor;
+
+ if (ResDir->idCount <= n)
+ return FALSE;
+
+ Cursor = &ResDir->idEntries[n].ResInfo.cursor;
+ *Width = Cursor->wWidth;
+ *Height = Cursor->wHeight;
+ *Bits = ResDir->idEntries[n].wBitCount;
+ return TRUE;
+}
+
+static GRPCURSORICONDIRENTRY *
+CURSORICON_FindBestIconRes(GRPCURSORICONDIR * dir,
+ int Width,
+ int Height,
+ int ColorBits)
+{
+ int n;
+ n = CURSORICON_FindBestIcon(dir,
+ CURSORICON_GetResIconEntry,
+ Width,
+ Height,
+ ColorBits);
+ if (n < 0)
+ return NULL;
+
+ return &dir->idEntries[n];
+}
+
+static GRPCURSORICONDIRENTRY *
+CURSORICON_FindBestCursorRes(GRPCURSORICONDIR *dir,
+ int Width,
+ int Height,
+ int ColorBits)
+{
+ int n;
+ n = CURSORICON_FindBestCursor(dir,
+ CURSORICON_GetResCursorEntry,
+ Width,
+ Height,
+ ColorBits);
+ if (n < 0)
+ return NULL;
+
+ return &dir->idEntries[n];
+}
+
+
+
+
+/* PUBLIC FUNCTIONS **********************************************************/
/*
* @implemented
@@ -452,201 +633,6 @@
-
-
-/*
- * The following macro function accounts for the irregularities of
- * accessing cursor and icon resources in files and resource entries.
- */
-typedef BOOL
-(*fnGetCIEntry)(LPVOID dir, int n, int *width, int *height, int *bits );
-
-/**********************************************************************
- * CURSORICON_FindBestIcon
- *
- * Find the icon closest to the requested size and number of colors.
- */
-static int
-CURSORICON_FindBestIcon(LPVOID dir,
- fnGetCIEntry get_entry,
- int Width,
- int Height,
- int ColorBits)
-{
- int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
- UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
- UINT iTempXDiff, iTempYDiff, iTempColorDiff;
-
- /* Find Best Fit */
- iTotalDiff = 0xFFFFFFFF;
- iColorDiff = 0xFFFFFFFF;
- for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
- {
- iTempXDiff = abs(Width - cx);
- iTempYDiff = abs(Height - cy);
-
- if(iTotalDiff > (iTempXDiff + iTempYDiff))
- {
- iXDiff = iTempXDiff;
- iYDiff = iTempYDiff;
- iTotalDiff = iXDiff + iYDiff;
- }
- }
-
- /* Find Best Colors for Best Fit */
- for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
- {
- if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
- {
- iTempColorDiff = abs(ColorBits - Bits);
- if(iColorDiff > iTempColorDiff)
- {
- BestEntry = i;
- BestBits = Bits;
- iColorDiff = iTempColorDiff;
- }
- }
- }
-
- TRACE("Best Icon: ResId: %d, bits : %d\n", BestEntry, BestBits);
-
- return BestEntry;
-}
-
-
-
-/**********************************************************************
- * CURSORICON_FindBestCursor
- *
- * Find the cursor closest to the requested size.
- * FIXME: parameter 'color' ignored and entries with more than 1 bpp
- * ignored too
- */
-static int
-CURSORICON_FindBestCursor(LPVOID dir,
- fnGetCIEntry get_entry,
- int Width,
- int Height,
- int ColorBits)
-{
- int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
- UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
- UINT iTempXDiff, iTempYDiff, iTempColorDiff;
-
- /* Find Best Fit */
- iTotalDiff = 0xFFFFFFFF;
- iColorDiff = 0xFFFFFFFF;
- for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
- {
- iTempXDiff = abs(Width - cx);
- iTempYDiff = abs(Height - cy);
-
- if(iTotalDiff > (iTempXDiff + iTempYDiff))
- {
- iXDiff = iTempXDiff;
- iYDiff = iTempYDiff;
- iTotalDiff = iXDiff + iYDiff;
- }
- }
-
- /* Find Best Colors for Best Fit */
- for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
- {
- if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
- {
- iTempColorDiff = abs(ColorBits - Bits);
- if(iColorDiff > iTempColorDiff)
- {
- BestEntry = i;
- BestBits = Bits;
- iColorDiff = iTempColorDiff;
- }
- }
- }
-
- TRACE("Best Cursor: ResId: %d, bits : %d\n", BestEntry, BestBits);
-
- return BestEntry;
-}
-
-
-static BOOL
-CURSORICON_GetResIconEntry(LPVOID dir,
- int n,
- int *Width,
- int *Height,
- int *Bits)
-{
- GRPCURSORICONDIR *ResDir = dir;
- ICONRESDIR *Icon;
-
- if (ResDir->idCount <= n)
- return FALSE;
-
- Icon = &ResDir->idEntries[n].ResInfo.icon;
- *Width = Icon->bWidth;
- *Height = Icon->bHeight;
- *Bits = ResDir->idEntries[n].wBitCount;
- return TRUE;
-}
-
-static BOOL
-CURSORICON_GetResCursorEntry(LPVOID dir,
- int n,
- int *Width,
- int *Height,
- int *Bits)
-{
- GRPCURSORICONDIR *ResDir = dir;
- CURSORRESDIR *Cursor;
-
- if (ResDir->idCount <= n)
- return FALSE;
-
- Cursor = &ResDir->idEntries[n].ResInfo.cursor;
- *Width = Cursor->wWidth;
- *Height = Cursor->wHeight;
- *Bits = ResDir->idEntries[n].wBitCount;
- return TRUE;
-}
-
-static GRPCURSORICONDIRENTRY *
-CURSORICON_FindBestIconRes(GRPCURSORICONDIR * dir,
- int Width,
- int Height,
- int ColorBits)
-{
- int n;
- n = CURSORICON_FindBestIcon(dir,
- CURSORICON_GetResIconEntry,
- Width,
- Height,
- ColorBits);
- if (n < 0)
- return NULL;
-
- return &dir->idEntries[n];
-}
-
-static GRPCURSORICONDIRENTRY *
-CURSORICON_FindBestCursorRes(GRPCURSORICONDIR *dir,
- int Width,
- int Height,
- int ColorBits)
-{
- int n;
- n = CURSORICON_FindBestCursor(dir,
- CURSORICON_GetResCursorEntry,
- Width,
- Height,
- ColorBits);
- if (n < 0)
- return NULL;
-
- return &dir->idEntries[n];
-}
-
-
INT WINAPI
LookupIconIdFromDirectoryEx(PBYTE xdir,
BOOL bIcon,