Use DrawFrameControl() instead of OEM bitmaps to paint caption buttons

and menu check marks.
This commit is contained in:
Alexandre Julliard 2001-01-24 19:47:57 +00:00
parent d40ef6bfe4
commit c1d35ccd9b
4 changed files with 96 additions and 201 deletions

View File

@ -146,11 +146,8 @@ typedef struct
#define STATE_MASK (~TYPE_MASK) #define STATE_MASK (~TYPE_MASK)
/* Dimension of the menu bitmaps */ /* Dimension of the menu bitmaps */
static WORD check_bitmap_width = 0, check_bitmap_height = 0;
static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0; static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
static HBITMAP hStdRadioCheck = 0;
static HBITMAP hStdCheck = 0;
static HBITMAP hStdMnArrow = 0; static HBITMAP hStdMnArrow = 0;
/* Minimze/restore/close buttons to be inserted in menubar */ /* Minimze/restore/close buttons to be inserted in menubar */
@ -421,8 +418,6 @@ BOOL MENU_Init()
0x55, 0, 0xAA, 0 }; 0x55, 0, 0xAA, 0 };
/* Load menu bitmaps */ /* Load menu bitmaps */
hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW)); hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
/* Load system buttons bitmaps */ /* Load system buttons bitmaps */
hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE)); hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
@ -432,19 +427,6 @@ BOOL MENU_Init()
hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE)); hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED)); hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
if (hStdCheck)
{
BITMAP bm;
GetObjectA( hStdCheck, sizeof(bm), &bm );
check_bitmap_width = bm.bmWidth;
check_bitmap_height = bm.bmHeight;
} else
return FALSE;
/* Assume that radio checks have the same size as regular checks. */
if (!hStdRadioCheck)
return FALSE;
if (hStdMnArrow) if (hStdMnArrow)
{ {
BITMAP bm; BITMAP bm;
@ -791,6 +773,7 @@ static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
INT orgX, INT orgY, BOOL menuBar ) INT orgX, INT orgY, BOOL menuBar )
{ {
WCHAR *p; WCHAR *p;
UINT check_bitmap_width = GetSystemMetrics( SM_CXMENUCHECK );
TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY); TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem, debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
@ -1240,6 +1223,8 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
if (!menuBar) if (!menuBar)
{ {
INT y = rect.top + rect.bottom; INT y = rect.top + rect.bottom;
UINT check_bitmap_width = GetSystemMetrics( SM_CXMENUCHECK );
UINT check_bitmap_height = GetSystemMetrics( SM_CYMENUCHECK );
if (!(lpitem->fType & MF_OWNERDRAW)) if (!(lpitem->fType & MF_OWNERDRAW))
{ {
@ -1248,28 +1233,30 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
* FIXME: * FIXME:
* Custom checkmark bitmaps are monochrome but not always 1bpp. * Custom checkmark bitmaps are monochrome but not always 1bpp.
*/ */
HBITMAP bm = (lpitem->fState & MF_CHECKED) ? lpitem->hCheckBit : lpitem->hUnCheckBit;
if (lpitem->fState & MF_CHECKED) if (bm) /* we have a custom bitmap */
{ {
HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
HDC hdcMem = CreateCompatibleDC( hdc ); HDC hdcMem = CreateCompatibleDC( hdc );
SelectObject( hdcMem, bm ); SelectObject( hdcMem, bm );
BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2, BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
check_bitmap_width, check_bitmap_height, check_bitmap_width, check_bitmap_height,
hdcMem, 0, 0, SRCCOPY ); hdcMem, 0, 0, SRCCOPY );
DeleteDC( hdcMem ); DeleteDC( hdcMem );
} }
else if (lpitem->hUnCheckBit) else if (lpitem->fState & MF_CHECKED) /* standard bitmaps */
{ {
RECT r;
HBITMAP bm = CreateBitmap( check_bitmap_width, check_bitmap_height, 1, 1, NULL );
HDC hdcMem = CreateCompatibleDC( hdc ); HDC hdcMem = CreateCompatibleDC( hdc );
SelectObject( hdcMem, bm );
SelectObject( hdcMem, lpitem->hUnCheckBit ); SetRect( &r, 0, 0, check_bitmap_width, check_bitmap_height );
BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2, DrawFrameControl( hdcMem, &r, DFC_MENU,
check_bitmap_width, check_bitmap_height, (lpitem->fType & MFT_RADIOCHECK) ?
DFCS_MENUBULLET : DFCS_MENUCHECK );
BitBlt( hdc, rect.left, (y - r.bottom) / 2, r.right, r.bottom,
hdcMem, 0, 0, SRCCOPY ); hdcMem, 0, 0, SRCCOPY );
DeleteDC( hdcMem ); DeleteDC( hdcMem );
DeleteObject( bm );
} }
} }
@ -3858,7 +3845,7 @@ HMENU WINAPI CreatePopupMenu(void)
*/ */
DWORD WINAPI GetMenuCheckMarkDimensions(void) DWORD WINAPI GetMenuCheckMarkDimensions(void)
{ {
return MAKELONG( check_bitmap_width, check_bitmap_height ); return MAKELONG( GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK) );
} }

View File

@ -1044,6 +1044,8 @@ static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
} }
/* Correct for the shadow shift */ /* Correct for the shadow shift */
if (!(uFlags & DFCS_PUSHED))
{
for(i = 0; i < Line1N; i++) for(i = 0; i < Line1N; i++)
{ {
Line1[i].x--; Line1[i].x--;
@ -1054,6 +1056,7 @@ static BOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags)
Line2[i].x--; Line2[i].x--;
Line2[i].y--; Line2[i].y--;
} }
}
/* Make the final picture */ /* Make the final picture */
i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT; i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT;

View File

@ -30,16 +30,15 @@ DECLARE_DEBUG_CHANNEL(shell);
BOOL NC_DrawGrayButton(HDC hdc, int x, int y); BOOL NC_DrawGrayButton(HDC hdc, int x, int y);
static HBITMAP16 hbitmapClose = 0; static HBITMAP hbitmapClose;
static HBITMAP16 hbitmapCloseD = 0; static HBITMAP hbitmapMinimize;
static HBITMAP16 hbitmapMinimize = 0; static HBITMAP hbitmapMinimizeD;
static HBITMAP16 hbitmapMinimizeD = 0; static HBITMAP hbitmapMaximize;
static HBITMAP16 hbitmapMaximize = 0; static HBITMAP hbitmapMaximizeD;
static HBITMAP16 hbitmapMaximizeD = 0; static HBITMAP hbitmapRestore;
static HBITMAP16 hbitmapRestore = 0; static HBITMAP hbitmapRestoreD;
static HBITMAP16 hbitmapRestoreD = 0;
BYTE lpGrayMask[] = { 0xAA, 0xA0, static const BYTE lpGrayMask[] = { 0xAA, 0xA0,
0x55, 0x50, 0x55, 0x50,
0xAA, 0xA0, 0xAA, 0xA0,
0x55, 0x50, 0x55, 0x50,
@ -1104,174 +1103,93 @@ NC_DrawSysButton95 (HWND hwnd, HDC hdc, BOOL down)
static void NC_DrawCloseButton95 (HWND hwnd, HDC hdc, BOOL down, BOOL bGrayed) static void NC_DrawCloseButton95 (HWND hwnd, HDC hdc, BOOL down, BOOL bGrayed)
{ {
RECT rect; RECT rect;
HDC hdcMem;
WND *wndPtr = WIN_FindWndPtr( hwnd ); WND *wndPtr = WIN_FindWndPtr( hwnd );
if( !(wndPtr->dwExStyle & WS_EX_MANAGED) ) if( !(wndPtr->dwExStyle & WS_EX_MANAGED) )
{ {
BITMAP bmp;
HBITMAP hBmp, hOldBmp;
NC_GetInsideRect95( hwnd, &rect ); NC_GetInsideRect95( hwnd, &rect );
/* A tool window has a smaller Close button */ /* A tool window has a smaller Close button */
if(wndPtr->dwExStyle & WS_EX_TOOLWINDOW) if(wndPtr->dwExStyle & WS_EX_TOOLWINDOW)
{ {
RECT toolRect;
INT iBmpHeight = 11; /* Windows does not use SM_CXSMSIZE and SM_CYSMSIZE */ INT iBmpHeight = 11; /* Windows does not use SM_CXSMSIZE and SM_CYSMSIZE */
INT iBmpWidth = 11; /* it uses 11x11 for the close button in tool window */ INT iBmpWidth = 11; /* it uses 11x11 for the close button in tool window */
INT iCaptionHeight = GetSystemMetrics(SM_CYSMCAPTION); INT iCaptionHeight = GetSystemMetrics(SM_CYSMCAPTION);
toolRect.top = rect.top + (iCaptionHeight - 1 - iBmpHeight) / 2; rect.top = rect.top + (iCaptionHeight - 1 - iBmpHeight) / 2;
toolRect.left = rect.right - (iCaptionHeight + 1 + iBmpWidth) / 2; rect.left = rect.right - (iCaptionHeight + 1 + iBmpWidth) / 2;
toolRect.bottom = toolRect.top + iBmpHeight; rect.bottom = rect.top + iBmpHeight;
toolRect.right = toolRect.left + iBmpWidth; rect.right = rect.left + iBmpWidth;
DrawFrameControl(hdc,&toolRect,
DFC_CAPTION,DFCS_CAPTIONCLOSE |
down ? DFCS_PUSHED : 0 |
bGrayed ? DFCS_INACTIVE : 0);
} }
else else
{ {
hdcMem = CreateCompatibleDC( hdc ); rect.left = rect.right - GetSystemMetrics(SM_CXSIZE) - 1;
hBmp = down ? hbitmapCloseD : hbitmapClose; rect.bottom = rect.top + GetSystemMetrics(SM_CYSIZE) - 1;
hOldBmp = SelectObject (hdcMem, hBmp); rect.top += 2;
GetObjectA (hBmp, sizeof(BITMAP), &bmp); rect.right -= 2;
BitBlt (hdc, rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
if(bGrayed)
NC_DrawGrayButton(hdc,rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
SelectObject (hdcMem, hOldBmp);
DeleteDC (hdcMem);
} }
DrawFrameControl( hdc, &rect, DFC_CAPTION,
(DFCS_CAPTIONCLOSE |
(down ? DFCS_PUSHED : 0) |
(bGrayed ? DFCS_INACTIVE : 0)) );
} }
WIN_ReleaseWndPtr(wndPtr); WIN_ReleaseWndPtr(wndPtr);
} }
/****************************************************************************** /******************************************************************************
* * NC_DrawMaxButton95
* NC_DrawMaxButton95(
* HWND hwnd,
* HDC16 hdc,
* BOOL down
* BOOL bGrayed )
* *
* Draws the maximize button for Win95 style windows. * Draws the maximize button for Win95 style windows.
*
* If bGrayed is true, then draw a disabled Maximize button * If bGrayed is true, then draw a disabled Maximize button
* */
* Bugs
* Many. Spacing might still be incorrect. Need to fit a close
* button between the max button and the edge.
* Should scale the image with the title bar. And more...
*
* Revision history
* 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
* Original implementation.
*
*****************************************************************************/
static void NC_DrawMaxButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed) static void NC_DrawMaxButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed)
{ {
RECT rect; RECT rect;
HDC hdcMem;
WND *wndPtr = WIN_FindWndPtr( hwnd ); WND *wndPtr = WIN_FindWndPtr( hwnd );
if( !(wndPtr->dwExStyle & WS_EX_MANAGED)) if( !(wndPtr->dwExStyle & WS_EX_MANAGED))
{ {
BITMAP bmp; UINT flags = IsZoomed(hwnd) ? DFCS_CAPTIONRESTORE : DFCS_CAPTIONMAX;
HBITMAP hBmp,hOldBmp;
NC_GetInsideRect95( hwnd, &rect ); NC_GetInsideRect95( hwnd, &rect );
hdcMem = CreateCompatibleDC( hdc );
hBmp = IsZoomed(hwnd) ?
(down ? hbitmapRestoreD : hbitmapRestore ) :
(down ? hbitmapMaximizeD: hbitmapMaximize);
hOldBmp=SelectObject( hdcMem, hBmp );
GetObjectA (hBmp, sizeof(BITMAP), &bmp);
if (wndPtr->dwStyle & WS_SYSMENU) if (wndPtr->dwStyle & WS_SYSMENU)
rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1; rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
rect.left = rect.right - GetSystemMetrics(SM_CXSIZE);
BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2, rect.bottom = rect.top + GetSystemMetrics(SM_CYSIZE) - 1;
rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2, rect.top += 2;
bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY ); rect.right -= 2;
if (down) flags |= DFCS_PUSHED;
if(bGrayed) if (bGrayed) flags |= DFCS_INACTIVE;
NC_DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2, DrawFrameControl( hdc, &rect, DFC_CAPTION, flags );
rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
SelectObject (hdcMem, hOldBmp);
DeleteDC( hdcMem );
} }
WIN_ReleaseWndPtr(wndPtr); WIN_ReleaseWndPtr(wndPtr);
} }
/****************************************************************************** /******************************************************************************
* * NC_DrawMinButton95
* NC_DrawMinButton95(
* HWND hwnd,
* HDC16 hdc,
* BOOL down,
* BOOL bGrayed )
* *
* Draws the minimize button for Win95 style windows. * Draws the minimize button for Win95 style windows.
*
* If bGrayed is true, then draw a disabled Minimize button * If bGrayed is true, then draw a disabled Minimize button
* */
* Bugs
* Many. Spacing is still incorrect. Should scale the image with the
* title bar. And more...
*
* Revision history
* 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
* Original implementation.
*
*****************************************************************************/
static void NC_DrawMinButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed) static void NC_DrawMinButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed)
{ {
RECT rect; RECT rect;
HDC hdcMem;
WND *wndPtr = WIN_FindWndPtr( hwnd ); WND *wndPtr = WIN_FindWndPtr( hwnd );
if( !(wndPtr->dwExStyle & WS_EX_MANAGED)) if( !(wndPtr->dwExStyle & WS_EX_MANAGED))
{ {
BITMAP bmp; UINT flags = DFCS_CAPTIONMIN;
HBITMAP hBmp,hOldBmp;
NC_GetInsideRect95( hwnd, &rect ); NC_GetInsideRect95( hwnd, &rect );
hdcMem = CreateCompatibleDC( hdc );
hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
hOldBmp= SelectObject( hdcMem, hBmp );
GetObjectA (hBmp, sizeof(BITMAP), &bmp);
if (wndPtr->dwStyle & WS_SYSMENU) if (wndPtr->dwStyle & WS_SYSMENU)
rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1; rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
if (wndPtr->dwStyle & (WS_MAXIMIZEBOX|WS_MINIMIZEBOX))
/* In win 95 there is always a Maximize box when there is a Minimize one */ rect.right -= GetSystemMetrics(SM_CXSIZE) - 2;
if ((wndPtr->dwStyle & WS_MAXIMIZEBOX) || (wndPtr->dwStyle & WS_MINIMIZEBOX)) rect.left = rect.right - GetSystemMetrics(SM_CXSIZE);
rect.right += -1 - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2; rect.bottom = rect.top + GetSystemMetrics(SM_CYSIZE) - 1;
rect.top += 2;
BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2, rect.right -= 2;
rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2, if (down) flags |= DFCS_PUSHED;
bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY ); if (bGrayed) flags |= DFCS_INACTIVE;
DrawFrameControl( hdc, &rect, DFC_CAPTION, flags );
if(bGrayed)
NC_DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
SelectObject (hdcMem, hOldBmp);
DeleteDC( hdcMem );
} }
WIN_ReleaseWndPtr(wndPtr); WIN_ReleaseWndPtr(wndPtr);
} }
@ -1468,7 +1386,6 @@ static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
WIN_ReleaseWndPtr(wndPtr); WIN_ReleaseWndPtr(wndPtr);
return; return;
} }
hbitmapCloseD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_CLOSED) );
hbitmapMinimize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCE) ); hbitmapMinimize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCE) );
hbitmapMinimizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCED) ); hbitmapMinimizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCED) );
hbitmapMaximize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOM) ); hbitmapMaximize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOM) );
@ -1577,18 +1494,6 @@ static void NC_DrawCaption95(
FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
COLOR_INACTIVECAPTION) ); COLOR_INACTIVECAPTION) );
if (!hbitmapClose) {
if (!(hbitmapClose = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_CLOSE) )))
return;
hbitmapCloseD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_CLOSED));
hbitmapMinimize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCE) );
hbitmapMinimizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCED) );
hbitmapMaximize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOM) );
hbitmapMaximizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOMD) );
hbitmapRestore = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORE) );
hbitmapRestoreD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORED) );
}
if ((style & WS_SYSMENU) && !(exStyle & WS_EX_TOOLWINDOW)) { if ((style & WS_SYSMENU) && !(exStyle & WS_EX_TOOLWINDOW)) {
if (NC_DrawSysButton95 (hwnd, hdc, FALSE)) if (NC_DrawSysButton95 (hwnd, hdc, FALSE))
r.left += GetSystemMetrics(SM_CYCAPTION) - 1; r.left += GetSystemMetrics(SM_CYCAPTION) - 1;

View File

@ -154,8 +154,8 @@ void SYSMETRICS_Init(void)
sysMetrics[SM_CXDRAG] = 2; sysMetrics[SM_CXDRAG] = 2;
sysMetrics[SM_CYDRAG] = 2; sysMetrics[SM_CYDRAG] = 2;
sysMetrics[SM_SHOWSOUNDS] = 0; sysMetrics[SM_SHOWSOUNDS] = 0;
sysMetrics[SM_CXMENUCHECK] = 2; sysMetrics[SM_CXMENUCHECK] = 14;
sysMetrics[SM_CYMENUCHECK] = 2; sysMetrics[SM_CYMENUCHECK] = 14;
/* FIXME: Should check the type of processor for the following */ /* FIXME: Should check the type of processor for the following */
sysMetrics[SM_SLOWMACHINE] = 0; sysMetrics[SM_SLOWMACHINE] = 0;