user: Move drawing of pop menu arrows to a subroutine reduces nesting

level of some large if statements in the drawing code. Some updates to
the comments.
This commit is contained in:
Rein Klazes 2006-02-20 11:54:28 +01:00 committed by Alexandre Julliard
parent 4be3d64d47
commit 672a1e4e4e
1 changed files with 175 additions and 155 deletions

View File

@ -27,6 +27,11 @@
* have been selected, i.e. their popup menu is currently displayed.
* This is probably not the meaning this style has in MS-Windows.
*
* Note 2: where there is a difference, these menu API's are according
* the behavior of Windows 2k and Windows XP. Known differences with
* Windows 9x/ME are documented in the comments, in case an application
* is found to depend on the old behavior.
*
* TODO:
* implements styles :
* - MNS_AUTODISMISS
@ -104,7 +109,7 @@ typedef struct {
DWORD dwContextHelpID;
DWORD dwMenuData; /* application defined value */
HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */
SIZE maxBmpSize; /* Maximum size of the bitmap items in MIIM_BITMAP state */
SIZE maxBmpSize; /* Maximum size of the bitmap items */
} POPUPMENU, *LPPOPUPMENU;
/* internal flags for menu tracking */
@ -155,6 +160,7 @@ typedef struct
#define MENU_ITEM_TYPE(flags) \
((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
/* macro to test that flags do not indicate bitmap, ownerdraw or separator */
#define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
#define IS_MAGIC_BITMAP(id) ((id) && ((INT_PTR)(id) < 12) && ((INT_PTR)(id) >= -1))
@ -1257,6 +1263,25 @@ MENU_DrawScrollArrows(LPPOPUPMENU lppop, HDC hdc)
}
/***********************************************************************
* draw_popup_arrow
*
* Draws the popup-menu arrow.
*/
static void draw_popup_arrow( HDC hdc, RECT rect, UINT arrow_bitmap_width,
UINT arrow_bitmap_height)
{
HDC hdcMem = CreateCompatibleDC( hdc );
HBITMAP hOrigBitmap;
hOrigBitmap = SelectObject( hdcMem, get_arrow_bitmap() );
BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
(rect.top + rect.bottom - arrow_bitmap_height) / 2,
arrow_bitmap_width, arrow_bitmap_height,
hdcMem, 0, 0, SRCCOPY );
SelectObject( hdcMem, hOrigBitmap );
DeleteDC( hdcMem );
}
/***********************************************************************
* MENU_DrawMenuItem
*
@ -1268,9 +1293,17 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
RECT rect;
BOOL flat_menu = FALSE;
int bkgnd;
UINT arrow_bitmap_width = 0, arrow_bitmap_height = 0;
debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
if (!menuBar) {
BITMAP bmp;
GetObjectW( get_arrow_bitmap(), sizeof(bmp), &bmp );
arrow_bitmap_width = bmp.bmWidth;
arrow_bitmap_height = bmp.bmHeight;
}
if (lpitem->fType & MF_SYSMENU)
{
if( !IsIconic(hwnd) )
@ -1336,7 +1369,11 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
dis.hDC, wine_dbgstr_rect( &dis.rcItem));
SendMessageW( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
/* Fall through to draw popup-menu arrow */
/* Draw the popup-menu arrow */
if (lpitem->fType & MF_POPUP)
draw_popup_arrow( hdc, rect, arrow_bitmap_width,
arrow_bitmap_height);
return;
}
TRACE("rect=%s\n", wine_dbgstr_rect( &lpitem->rect));
@ -1346,8 +1383,6 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
rect = lpitem->rect;
MENU_AdjustMenuItemRect(MENU_GetMenu(hmenu), &rect);
if (!(lpitem->fType & MF_OWNERDRAW))
{
if (lpitem->fState & MF_HILITE)
{
if (flat_menu)
@ -1367,18 +1402,15 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
}
else
FillRect( hdc, &rect, GetSysColorBrush(bkgnd) );
}
SetBkMode( hdc, TRANSPARENT );
if (!(lpitem->fType & MF_OWNERDRAW))
{
HPEN oldPen;
/* vertical separator */
if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
{
HPEN oldPen;
RECT rc = rect;
rc.top = 3;
rc.bottom = height - 3;
if (flat_menu)
@ -1395,7 +1427,9 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
/* horizontal separator */
if (lpitem->fType & MF_SEPARATOR)
{
HPEN oldPen;
RECT rc = rect;
rc.left++;
rc.right--;
rc.top += SEPARATOR_HEIGHT / 2;
@ -1410,7 +1444,6 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
return;
}
}
/* helper lines for debugging */
/* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
@ -1423,19 +1456,10 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
{
HBITMAP bm;
INT y = rect.top + rect.bottom;
RECT rc = rect;
UINT check_bitmap_width = GetSystemMetrics( SM_CXMENUCHECK );
UINT check_bitmap_height = GetSystemMetrics( SM_CYMENUCHECK );
UINT arrow_bitmap_width, arrow_bitmap_height;
BITMAP bmp;
GetObjectW( get_arrow_bitmap(), sizeof(bmp), &bmp );
arrow_bitmap_width = bmp.bmWidth;
arrow_bitmap_height = bmp.bmHeight;
if (!(lpitem->fType & MF_OWNERDRAW))
{
RECT rc;
rc = rect;
if (lpitem->hbmpItem)
{
POPUPMENU *menu = MENU_GetMenu(hmenu);
@ -1505,33 +1529,18 @@ static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc,
MENU_DrawBitmapItem(hdc, lpitem, &rect, FALSE);
}
}
}
/* Draw the popup-menu arrow */
if (lpitem->fType & MF_POPUP)
{
HDC hdcMem = CreateCompatibleDC( hdc );
HBITMAP hOrigBitmap;
hOrigBitmap = SelectObject( hdcMem, get_arrow_bitmap() );
BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
(y - arrow_bitmap_height) / 2,
arrow_bitmap_width, arrow_bitmap_height,
hdcMem, 0, 0, SRCCOPY );
SelectObject( hdcMem, hOrigBitmap );
DeleteDC( hdcMem );
}
draw_popup_arrow( hdc, rect, arrow_bitmap_width,
arrow_bitmap_height);
rect.left += check_bitmap_width;
rect.right -= arrow_bitmap_width;
}
else if( lpitem->hbmpItem && !(lpitem->fType & MF_OWNERDRAW))
else if( lpitem->hbmpItem)
{ /* Draw the bitmap */
MENU_DrawBitmapItem( hdc, lpitem, &rect, menuBar);
}
/* Done for owner-drawn */
if (lpitem->fType & MF_OWNERDRAW)
return;
/* process text if present */
if (lpitem->text)
{
@ -4279,16 +4288,19 @@ static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
if( lpmii->fMask & MIIM_TYPE) {
if( lpmii->fMask & ( MIIM_STRING | MIIM_FTYPE | MIIM_BITMAP)) {
WARN("invalid combination of fMask bits used\n");
/* this does not happen on Win9x/ME */
SetLastError( ERROR_INVALID_PARAMETER);
return FALSE;
}
lpmii->fType = menu->fType & ~MF_POPUP;
if( menu->hbmpItem) lpmii->fType |= MFT_BITMAP;
lpmii->hbmpItem = menu->hbmpItem;
lpmii->hbmpItem = menu->hbmpItem; /* not on Win9x/ME */
if( lpmii->fType & MFT_BITMAP) {
lpmii->dwTypeData = (LPWSTR) menu->hbmpItem;
lpmii->cch = 0;
} else if( lpmii->fType & (MFT_OWNERDRAW | MFT_SEPARATOR)) {
/* this does not happen on Win9x/ME */
lpmii->dwTypeData = 0;
lpmii->cch = 0;
}
@ -4327,10 +4339,13 @@ static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
lpmii->cch--;
else
lpmii->cch = len;
else /* return length of string */
else {
/* return length of string */
/* not on Win9x/ME if fType & MFT_BITMAP */
lpmii->cch = len;
}
}
}
if (lpmii->fMask & MIIM_FTYPE)
lpmii->fType = menu->fType & ~MF_POPUP;
@ -4346,8 +4361,11 @@ static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
if (lpmii->fMask & MIIM_SUBMENU)
lpmii->hSubMenu = menu->hSubMenu;
else
lpmii->hSubMenu = 0; /* hSubMenu is always cleared */
else {
/* hSubMenu is always cleared
* (not on Win9x/ME ) */
lpmii->hSubMenu = 0;
}
if (lpmii->fMask & MIIM_CHECKMARKS) {
lpmii->hbmpChecked = menu->hCheckBit;
@ -4433,10 +4451,12 @@ static BOOL SetMenuItemInfo_common(MENUITEM * menu,
{
if (!menu) return FALSE;
debug_print_menuitem("MENU_SetItemInfo_common from: ", menu, "");
debug_print_menuitem("SetmenuItemInfo_common from: ", menu, "");
if (lpmii->fMask & MIIM_TYPE ) {
if( lpmii->fMask & ( MIIM_STRING | MIIM_FTYPE | MIIM_BITMAP)) {
WARN("invalid combination of fMask bits used\n");
/* this does not happen on Win9x/ME */
SetLastError( ERROR_INVALID_PARAMETER);
return FALSE;
}