merge new icon/cursor selection code, cursors and radio button drawing code from head

svn path=/branches/ros-branch-0_3_1/; revision=25615
This commit is contained in:
Ged Murphy
2007-01-24 15:25:43 +00:00
parent a3ad85c5a5
commit 2ec1b8df07
21 changed files with 262 additions and 216 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 518 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 4.5 KiB

+53 -95
View File
@@ -717,123 +717,81 @@ static BOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags)
return TRUE;
}
/* Ported from WINE20020904 */
/* Draw a radio/radioimage/radiomask button coming from DrawFrameControl()
*
* Does a pretty good job in emulating MS behavior. Some quirks are
* however there because MS uses a TrueType font (Marlett) to draw
* the buttons.
*/
static BOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags)
{
RECT myr;
int i;
int SmallDiam = UITOOLS_MakeSquareRect(r, &myr);
int BorderShrink = SmallDiam / 16;
HPEN hpsave;
HBRUSH hbsave;
int xc, yc;
RECT rc;
LOGFONT lf;
HFONT hFont, hOldFont;
int SmallDiam, i;
if(BorderShrink < 1) BorderShrink = 1;
LPCTSTR OutRight = TEXT("j"); // Outer right
LPCTSTR OutLeft = TEXT("k"); // Outer left
LPCTSTR InRight = TEXT("l"); // inner right
LPCTSTR InLeft = TEXT("m"); // inner left
LPCTSTR Center = TEXT("n"); // center
if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE)
{
FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH));
}
SmallDiam = UITOOLS_MakeSquareRect(r, &rc);
xc = myr.left + SmallDiam - SmallDiam/2;
yc = myr.top + SmallDiam - SmallDiam/2;
/* Define bounding box */
i = 14*SmallDiam/16;
myr.left = xc - i+i/2;
myr.right = xc + i/2;
myr.top = yc - i+i/2;
myr.bottom = yc + i/2;
ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfHeight = SmallDiam;
lf.lfWidth = 0;
lf.lfWeight = FW_NORMAL;
lf.lfCharSet = DEFAULT_CHARSET;
lstrcpy(lf.lfFaceName, TEXT("Marlett"));
hFont = CreateFontIndirect(&lf);
hOldFont = SelectObject(dc, hFont);
if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK)
{
hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH));
Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
SelectObject(dc, hbsave);
SetBkMode(dc, OPAQUE);
SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME));
TextOut(dc, rc.left, rc.top, Center, 1);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME));
TextOut(dc, rc.left, rc.top, OutRight, 1);
SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME));
TextOut(dc, rc.left, rc.top, OutLeft, 1);
}
else
{
if(uFlags & (DFCS_FLAT|DFCS_MONO))
SetBkMode(dc, TRANSPARENT);
/* Center section, white for active, grey for inactive */
i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
SetTextColor(dc, GetSysColor(i));
TextOut(dc, rc.left, rc.top, Center, 1);
if(uFlags & (DFCS_FLAT | DFCS_MONO))
{
hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_WINDOWFRAME));
hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
SelectObject(dc, hbsave);
SelectObject(dc, hpsave);
SetTextColor(dc, GetSysColor(COLOR_WINDOWFRAME));
TextOut(dc, rc.left, rc.top, OutRight, 1);
TextOut(dc, rc.left, rc.top, OutLeft, 1);
TextOut(dc, rc.left, rc.top, InRight, 1);
TextOut(dc, rc.left, rc.top, InLeft, 1);
}
else
{
hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT));
hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT));
Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
SelectObject(dc, GetSysColorPen(COLOR_BTNSHADOW));
SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW));
Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
myr.left += BorderShrink;
myr.right -= BorderShrink;
myr.top += BorderShrink;
myr.bottom -= BorderShrink;
SelectObject(dc, GetSysColorPen(COLOR_3DLIGHT));
SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT));
Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.left-1, myr.bottom, myr.right+1, myr.top);
SelectObject(dc, GetSysColorPen(COLOR_3DDKSHADOW));
SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW));
Pie(dc, myr.left, myr.top, myr.right+1, myr.bottom+1, myr.right+1, myr.top, myr.left-1, myr.bottom);
SelectObject(dc, hbsave);
SelectObject(dc, hpsave);
SetTextColor(dc, GetSysColor(COLOR_BTNSHADOW));
TextOut(dc, rc.left, rc.top, OutRight, 1);
SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT));
TextOut(dc, rc.left, rc.top, OutLeft, 1);
SetTextColor(dc, GetSysColor(COLOR_3DDKSHADOW));
TextOut(dc, rc.left, rc.top, InRight, 1);
SetTextColor(dc, GetSysColor(COLOR_3DLIGHT));
TextOut(dc, rc.left, rc.top, InLeft, 1);
}
i = 10*SmallDiam/16;
myr.left = xc - i+i/2;
myr.right = xc + i/2;
myr.top = yc - i+i/2;
myr.bottom = yc + i/2;
i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE;
hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
SelectObject(dc, hbsave);
SelectObject(dc, hpsave);
}
if(uFlags & DFCS_CHECKED)
{
i = 6*SmallDiam/16;
i = i < 1 ? 1 : i;
myr.left = xc - i+i/2;
myr.right = xc + i/2;
myr.top = yc - i+i/2;
myr.bottom = yc + i/2;
LPCTSTR Check = TEXT("i");
i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT;
hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i));
hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i));
Ellipse(dc, myr.left, myr.top, myr.right, myr.bottom);
SelectObject(dc, hpsave);
SelectObject(dc, hbsave);
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
TextOut(dc, rc.left, rc.top, Check, 1);
}
/* FIXME: M$ has a Polygon in the center at relative points: */
/* 0.476, 0.476 (times SmallDiam, SmallDiam) */
/* 0.476, 0.525 */
/* 0.500, 0.500 */
/* 0.500, 0.499 */
/* when the button is unchecked. The reason for it is unknown. The */
/* color is COLOR_BTNHIGHLIGHT, although the Polygon gets painted at */
/* least 3 times (it looks like a clip-region when you see it happen). */
/* I do not really see a reason why this should be implemented. If you */
/* have a good reason, let me know. Maybe this is a quirk in the Marlett */
/* font. */
SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
SelectObject(dc, hOldFont);
return TRUE;
}
+209 -121
View File
@@ -247,10 +247,10 @@ CreateIconFromResourceEx(
if (! fIcon)
{
wXHotspot = *(WORD*)pbIconBits;
pbIconBits+=sizeof(WORD);
pbIconBits += sizeof(WORD);
wYHotspot = *(WORD*)pbIconBits;
pbIconBits+=sizeof(WORD);
cbIconBits-=2*sizeof(WORD);
pbIconBits += sizeof(WORD);
cbIconBits -= 2 * sizeof(WORD);
}
else
{
@@ -266,7 +266,7 @@ CreateIconFromResourceEx(
}
memcpy(SafeIconImage, pbIconBits, cbIconBits);
/* take into acount the origonal height was for both the AND and XOR images */
/* take into acount the original height was for both the AND and XOR images */
if(fIcon)
SafeIconImage->icHeader.biHeight /= 2;
@@ -326,7 +326,7 @@ CreateIconIndirect(PICONINFO IconInfo)
return (HICON)0;
}
/* FIXME - does there really *have* to be a color bitmap? monochrome cursors don't have one */
if(IconInfo->hbmColor && !GetObjectW(IconInfo->hbmColor, sizeof(BITMAP), &ColorBitmap))
if(/*IconInfo->hbmColor &&*/ !GetObjectW(IconInfo->hbmColor, sizeof(BITMAP), &ColorBitmap))
{
return (HICON)0;
}
@@ -440,35 +440,47 @@ LookupIconIdFromDirectory(
PBYTE presbits,
BOOL fIcon)
{
return LookupIconIdFromDirectoryEx( presbits, fIcon,
fIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
fIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), LR_DEFAULTCOLOR );
return LookupIconIdFromDirectoryEx(presbits,
fIcon,
fIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
fIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR),
LR_DEFAULTCOLOR);
}
/* Ported from WINE20030408 */
GRPCURSORICONDIRENTRY*
CURSORICON_FindBestCursor( GRPCURSORICONDIR *dir, int width, int height, int colors)
/*
* 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;
GRPCURSORICONDIRENTRY *entry, *bestEntry = NULL;
int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
UINT iTempXDiff, iTempYDiff, iTempColorDiff;
if (dir->idCount < 1)
{
DPRINT("Empty directory!\n");
return NULL;
}
if (dir->idCount == 1)
return &dir->idEntries[0]; /* No choice... */
/* Find Best Fit */
iTotalDiff = 0xFFFFFFFF;
iColorDiff = 0xFFFFFFFF;
for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
{
iTempXDiff = abs(width - entry->ResInfo.icon.bWidth);
iTempYDiff = abs(height - entry->ResInfo.icon.bHeight);
iTempXDiff = abs(Width - cx);
iTempYDiff = abs(Height - cy);
if(iTotalDiff > (iTempXDiff + iTempYDiff))
{
@@ -479,118 +491,194 @@ CURSORICON_FindBestCursor( GRPCURSORICONDIR *dir, int width, int height, int col
}
/* Find Best Colors for Best Fit */
for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
for (i = 0; get_entry(dir, i, &cx, &cy, &Bits); i++ )
{
if(abs(width - entry->ResInfo.icon.bWidth) == (int) iXDiff &&
abs(height - entry->ResInfo.icon.bHeight) == (int) iYDiff)
if(abs(Width - cx) == iXDiff && abs(Height - cy) == iYDiff)
{
iTempColorDiff = abs(colors - entry->ResInfo.icon.bColorCount);
if(iColorDiff > iTempColorDiff)
{
bestEntry = entry;
iColorDiff = iTempColorDiff;
}
}
}
return bestEntry;
}
/* Ported from WINE20030408 */
GRPCURSORICONDIRENTRY*
CURSORICON_FindBestIcon( GRPCURSORICONDIR *dir, int width, int height, int colorbits)
{
int i;
GRPCURSORICONDIRENTRY *entry, *bestEntry = NULL;
UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
UINT iTempXDiff, iTempYDiff, iTempColorDiff;
if (dir->idCount < 1)
{
DPRINT("Empty directory!\n");
return NULL;
}
if (dir->idCount == 1)
return &dir->idEntries[0]; /* No choice... */
/* Find Best Fit */
iTotalDiff = 0xFFFFFFFF;
iColorDiff = 0xFFFFFFFF;
for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
{
iTempXDiff = abs(width - entry->ResInfo.icon.bWidth);
iTempYDiff = abs(height - entry->ResInfo.icon.bHeight);
if(iTotalDiff > (iTempXDiff + iTempYDiff))
{
iXDiff = iTempXDiff;
iYDiff = iTempYDiff;
iTotalDiff = iXDiff + iYDiff;
}
}
/* Find Best Colors for Best Fit */
for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
{
if(abs(width - entry->ResInfo.icon.bWidth) == (int) iXDiff &&
abs(height - entry->ResInfo.icon.bHeight) == (int) iYDiff)
{
iTempColorDiff = abs(colorbits - entry->wBitCount);
iTempColorDiff = abs(ColorBits - Bits);
if(iColorDiff > iTempColorDiff)
{
bestEntry = entry;
BestEntry = i;
BestBits = Bits;
iColorDiff = iTempColorDiff;
}
}
}
return bestEntry;
DPRINT("Best Icon: ResId: %d, bits : %d\n", BestEntry, BestBits);
return BestEntry;
}
/* Ported from WINE20030408 */
/*
* @implemented
/**********************************************************************
* CURSORICON_FindBestCursor
*
* Find the cursor closest to the requested size.
* FIXME: parameter 'color' ignored and entries with more than 1 bpp
* ignored too
*/
INT STDCALL
LookupIconIdFromDirectoryEx(
PBYTE presbits,
BOOL fIcon,
int cxDesired,
int cyDesired,
UINT Flags)
static int
CURSORICON_FindBestCursor(LPVOID dir,
fnGetCIEntry get_entry,
int Width,
int Height,
int ColorBits)
{
GRPCURSORICONDIR *dir = (GRPCURSORICONDIR*)presbits;
UINT retVal = 0;
int i, cx, cy, Bits, BestBits = 0, BestEntry = -1;
UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
UINT iTempXDiff, iTempYDiff, iTempColorDiff;
if (dir && !dir->idReserved && (IMAGE_ICON == dir->idType || IMAGE_CURSOR == dir->idType))
{
GRPCURSORICONDIRENTRY *entry;
HDC hdc;
int ColorBits;
/* 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);
hdc = CreateICW(NULL, NULL, NULL, NULL);
if (Flags & LR_MONOCHROME)
{
ColorBits = 1;
}
else
{
ColorBits = GetDeviceCaps(hdc, BITSPIXEL);
if (ColorBits > 8)
ColorBits = 8;
}
DeleteDC(hdc);
if(iTotalDiff > (iTempXDiff + iTempYDiff))
{
iXDiff = iTempXDiff;
iYDiff = iTempYDiff;
iTotalDiff = iXDiff + iYDiff;
}
}
entry = CURSORICON_FindBestIcon( dir, cxDesired, cyDesired, ColorBits );
/* 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;
}
}
}
if (entry)
retVal = entry->nID;
}
else
{
DbgPrint("invalid resource directory\n");
}
return retVal;
DPRINT("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,
INT width,
INT height,
UINT cFlag)
{
GRPCURSORICONDIR *dir = (GRPCURSORICONDIR*)xdir;
UINT retVal = 0;
if(dir && !dir->idReserved && (IMAGE_ICON == dir->idType || IMAGE_CURSOR == dir->idType))
{
GRPCURSORICONDIRENTRY *entry = NULL;
int ColorBits;
if (cFlag & LR_MONOCHROME)
{
ColorBits = 1;
}
else
{
HDC hdc = CreateICW(NULL, NULL, NULL, NULL);
ColorBits = GetDeviceCaps(hdc, BITSPIXEL);
DeleteDC(hdc);
}
if(bIcon)
entry = CURSORICON_FindBestIconRes(dir, width, height, ColorBits);
else
entry = CURSORICON_FindBestCursorRes(dir, width, height, 1);
if (entry)
retVal = entry->nID;
}
else
DPRINT1("%s() : Invalid resource directory\n", __FUNCTION__);
return retVal;
}