4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994 Alexandre Julliard
6 * Copyright 1997 Morten Welinder
10 * Note: the style MF_MOUSESELECT is used to mark popup items that
11 * have been selected, i.e. their popup menu is currently displayed.
12 * This is probably not the meaning this style has in MS-Windows.
21 #include "wine/winbase16.h"
22 #include "wine/winuser16.h"
26 #include "nonclient.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(menu)
37 /* internal popup menu window messages */
39 #define MM_SETMENUHANDLE (WM_USER + 0)
40 #define MM_GETMENUHANDLE (WM_USER + 1)
42 /* Menu item structure */
44 /* ----------- MENUITEMINFO Stuff ----------- */
45 UINT fType; /* Item type. */
46 UINT fState; /* Item state. */
47 UINT wID; /* Item id. */
48 HMENU hSubMenu; /* Pop-up menu. */
49 HBITMAP hCheckBit; /* Bitmap when checked. */
50 HBITMAP hUnCheckBit; /* Bitmap when unchecked. */
51 LPSTR text; /* Item text or bitmap handle. */
52 DWORD dwItemData; /* Application defined. */
53 DWORD dwTypeData; /* depends on fMask */
54 HBITMAP hbmpItem; /* bitmap in win98 style menus */
55 /* ----------- Wine stuff ----------- */
56 RECT rect; /* Item area (relative to menu window) */
57 UINT xTab; /* X position of text after Tab */
60 /* Popup menu structure */
62 WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
63 WORD wMagic; /* Magic number */
64 HQUEUE16 hTaskQ; /* Task queue for this menu */
65 WORD Width; /* Width of the whole menu */
66 WORD Height; /* Height of the whole menu */
67 WORD nItems; /* Number of items in the menu */
68 HWND hWnd; /* Window containing the menu */
69 MENUITEM *items; /* Array of menu items */
70 UINT FocusedItem; /* Currently focused item */
71 HWND hwndOwner; /* window receiving the messages for ownerdraw */
72 /* ------------ MENUINFO members ------ */
73 DWORD dwStyle; /* Extended mennu style */
74 UINT cyMax; /* max hight of the whole menu, 0 is screen hight */
75 HBRUSH hbrBack; /* brush for menu background */
76 DWORD dwContextHelpID;
77 DWORD dwMenuData; /* application defined value */
78 } POPUPMENU, *LPPOPUPMENU;
80 /* internal flags for menu tracking */
82 #define TF_ENDMENU 0x0001
83 #define TF_SUSPENDPOPUP 0x0002
84 #define TF_SKIPREMOVE 0x0004
89 HMENU hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
90 HMENU hTopMenu; /* initial menu */
91 HWND hOwnerWnd; /* where notifications are sent */
95 #define MENU_MAGIC 0x554d /* 'MU' */
96 #define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
101 /* Internal MENU_TrackMenu() flags */
102 #define TPM_INTERNAL 0xF0000000
103 #define TPM_ENTERIDLEEX 0x80000000 /* set owner window for WM_ENTERIDLE */
104 #define TPM_BUTTONDOWN 0x40000000 /* menu was clicked before tracking */
105 #define TPM_POPUPMENU 0x20000000 /* menu is a popup menu */
107 /* popup menu shade thickness */
108 #define POPUP_XSHADE 4
109 #define POPUP_YSHADE 4
111 /* Space between 2 menu bar items */
112 #define MENU_BAR_ITEMS_SPACE 12
114 /* Minimum width of a tab character */
115 #define MENU_TAB_SPACE 8
117 /* Height of a separator item */
118 #define SEPARATOR_HEIGHT 5
120 /* (other menu->FocusedItem values give the position of the focused item) */
121 #define NO_SELECTED_ITEM 0xffff
123 #define MENU_ITEM_TYPE(flags) \
124 ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
126 #define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
127 #define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
129 #define IS_SYSTEM_MENU(menu) \
130 (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
132 #define IS_SYSTEM_POPUP(menu) \
133 ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
135 #define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
136 MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
137 MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
138 MF_POPUP | MF_SYSMENU | MF_HELP)
139 #define STATE_MASK (~TYPE_MASK)
141 /* Dimension of the menu bitmaps */
142 static WORD check_bitmap_width = 0, check_bitmap_height = 0;
143 static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
145 static HBITMAP hStdRadioCheck = 0;
146 static HBITMAP hStdCheck = 0;
147 static HBITMAP hStdMnArrow = 0;
149 /* Minimze/restore/close buttons to be inserted in menubar */
150 static HBITMAP hBmpMinimize = 0;
151 static HBITMAP hBmpMinimizeD = 0;
152 static HBITMAP hBmpMaximize = 0;
153 static HBITMAP hBmpMaximizeD = 0;
154 static HBITMAP hBmpClose = 0;
155 static HBITMAP hBmpCloseD = 0;
158 static HBRUSH hShadeBrush = 0;
159 static HFONT hMenuFont = 0;
160 static HFONT hMenuFontBold = 0;
162 static HMENU MENU_DefSysPopup = 0; /* Default system menu popup */
164 /* Use global popup window because there's no way 2 menus can
165 * be tracked at the same time. */
167 static WND* pTopPopupWnd = 0;
168 static UINT uSubPWndLevel = 0;
170 /* Flag set by EndMenu() to force an exit from menu tracking */
171 static BOOL fEndMenu = FALSE;
174 /***********************************************************************
175 * debug_print_menuitem
177 * Print a menuitem in readable form.
180 #define debug_print_menuitem(pre, mp, post) \
181 if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
183 #define MENUOUT(text) \
184 dsprintf(menu, "%s%s", (count++ ? "," : ""), (text))
186 #define MENUFLAG(bit,text) \
188 if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
191 static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
194 dbg_decl_str(menu, 256);
197 UINT flags = mp->fType;
198 int typ = MENU_ITEM_TYPE(flags);
199 dsprintf(menu, "{ ID=0x%x", mp->wID);
200 if (flags & MF_POPUP)
201 dsprintf(menu, ", Sub=0x%x", mp->hSubMenu);
204 dsprintf(menu, ", Typ=");
205 if (typ == MFT_STRING)
207 else if (typ == MFT_SEPARATOR)
209 else if (typ == MFT_OWNERDRAW)
211 else if (typ == MFT_BITMAP)
217 MENUFLAG(MF_POPUP, "pop");
218 MENUFLAG(MFT_MENUBARBREAK, "barbrk");
219 MENUFLAG(MFT_MENUBREAK, "brk");
220 MENUFLAG(MFT_RADIOCHECK, "radio");
221 MENUFLAG(MFT_RIGHTORDER, "rorder");
222 MENUFLAG(MF_SYSMENU, "sys");
223 MENUFLAG(MFT_RIGHTJUSTIFY, "right"); /* same as MF_HELP */
226 dsprintf(menu, "+0x%x", flags);
231 dsprintf(menu, ", State=");
232 MENUFLAG(MFS_GRAYED, "grey");
233 MENUFLAG(MFS_DEFAULT, "default");
234 MENUFLAG(MFS_DISABLED, "dis");
235 MENUFLAG(MFS_CHECKED, "check");
236 MENUFLAG(MFS_HILITE, "hi");
237 MENUFLAG(MF_USECHECKBITMAPS, "usebit");
238 MENUFLAG(MF_MOUSESELECT, "mouse");
240 dsprintf(menu, "+0x%x", flags);
243 dsprintf(menu, ", Chk=0x%x", mp->hCheckBit);
245 dsprintf(menu, ", Unc=0x%x", mp->hUnCheckBit);
247 if (typ == MFT_STRING) {
249 dsprintf(menu, ", Text=\"%s\"", mp->text);
251 dsprintf(menu, ", Text=Null");
252 } else if (mp->text == NULL)
255 dsprintf(menu, ", Text=%p", mp->text);
257 dsprintf(menu, ", ItemData=0x%08lx", mp->dwItemData);
258 dsprintf(menu, " }");
260 dsprintf(menu, "NULL");
263 TRACE("%s %s %s\n", prefix, dbg_str(menu), postfix);
269 /***********************************************************************
272 * Return the default system menu.
274 static HMENU MENU_CopySysPopup(void)
276 HMENU hMenu = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
279 POPUPMENU* menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
280 menu->wFlags |= MF_SYSMENU | MF_POPUP;
281 SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
285 ERR("Unable to load default system menu\n" );
288 TRACE("returning %x.\n", hMenu );
293 /***********************************************************************
294 * MENU_GetTopPopupWnd()
296 * Return the locked pointer pTopPopupWnd.
298 static WND *MENU_GetTopPopupWnd()
300 return WIN_LockWndPtr(pTopPopupWnd);
302 /***********************************************************************
303 * MENU_ReleaseTopPopupWnd()
305 * Realease the locked pointer pTopPopupWnd.
307 static void MENU_ReleaseTopPopupWnd()
309 WIN_ReleaseWndPtr(pTopPopupWnd);
311 /***********************************************************************
312 * MENU_DestroyTopPopupWnd()
314 * Destroy the locked pointer pTopPopupWnd.
316 static void MENU_DestroyTopPopupWnd()
318 WND *tmpWnd = pTopPopupWnd;
320 WIN_ReleaseWndPtr(tmpWnd);
325 /**********************************************************************
328 * Create a copy of the system menu. System menu in Windows is
329 * a special menu-bar with the single entry - system menu popup.
330 * This popup is presented to the outside world as a "system menu".
331 * However, the real system menu handle is sometimes seen in the
332 * WM_MENUSELECT paramemters (and Word 6 likes it this way).
334 HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu )
338 if ((hMenu = CreateMenu()))
340 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hMenu);
341 menu->wFlags = MF_SYSMENU;
344 if (hPopupMenu == (HMENU)(-1))
345 hPopupMenu = MENU_CopySysPopup();
346 else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
350 InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
352 menu->items[0].fType = MF_SYSMENU | MF_POPUP;
353 menu->items[0].fState = 0;
354 menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hPopupMenu);
355 menu->wFlags |= MF_SYSMENU;
357 TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
360 DestroyMenu( hMenu );
362 ERR("failed to load system menu!\n");
367 /***********************************************************************
370 * Menus initialisation.
375 NONCLIENTMETRICSA ncm;
377 static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
382 /* Load menu bitmaps */
383 hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
384 hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
385 hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
386 /* Load system buttons bitmaps */
387 hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
388 hBmpMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
389 hBmpMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
390 hBmpMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
391 hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
392 hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
397 GetObjectA( hStdCheck, sizeof(bm), &bm );
398 check_bitmap_width = bm.bmWidth;
399 check_bitmap_height = bm.bmHeight;
403 /* Assume that radio checks have the same size as regular check. */
410 GetObjectA( hStdMnArrow, sizeof(bm), &bm );
411 arrow_bitmap_width = bm.bmWidth;
412 arrow_bitmap_height = bm.bmHeight;
416 if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
419 if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
422 DeleteObject( hBitmap );
423 if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
426 ncm.cbSize = sizeof (NONCLIENTMETRICSA);
427 if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
430 if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
433 ncm.lfMenuFont.lfWeight += 300;
434 if ( ncm.lfMenuFont.lfWeight > 1000)
435 ncm.lfMenuFont.lfWeight = 1000;
437 if (!(hMenuFontBold = CreateFontIndirectA( &ncm.lfMenuFont )))
443 /***********************************************************************
444 * MENU_InitSysMenuPopup
446 * Grey the appropriate items in System menu.
448 static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
452 gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
453 EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
454 gray = ((style & WS_MAXIMIZE) != 0);
455 EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
456 gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
457 EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
458 gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
459 EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
460 gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
461 EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
462 gray = (clsStyle & CS_NOCLOSE) != 0;
463 EnableMenuItem( hmenu, SC_CLOSE, (gray ? MF_GRAYED : MF_ENABLED) );
467 /******************************************************************************
469 * UINT32 MENU_GetStartOfNextColumn(
472 *****************************************************************************/
474 static UINT MENU_GetStartOfNextColumn(
477 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu);
478 UINT i = menu->FocusedItem + 1;
481 return NO_SELECTED_ITEM;
483 if( i == NO_SELECTED_ITEM )
486 for( ; i < menu->nItems; ++i ) {
487 if (menu->items[i].fType & MF_MENUBARBREAK)
491 return NO_SELECTED_ITEM;
495 /******************************************************************************
497 * UINT32 MENU_GetStartOfPrevColumn(
500 *****************************************************************************/
502 static UINT MENU_GetStartOfPrevColumn(
505 POPUPMENU const *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu);
509 return NO_SELECTED_ITEM;
511 if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
512 return NO_SELECTED_ITEM;
514 /* Find the start of the column */
516 for(i = menu->FocusedItem; i != 0 &&
517 !(menu->items[i].fType & MF_MENUBARBREAK);
521 return NO_SELECTED_ITEM;
523 for(--i; i != 0; --i) {
524 if (menu->items[i].fType & MF_MENUBARBREAK)
528 TRACE("ret %d.\n", i );
535 /***********************************************************************
538 * Find a menu item. Return a pointer on the item, and modifies *hmenu
539 * in case the item was in a sub-menu.
541 static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags )
546 if (((*hmenu)==0xffff) || (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(*hmenu)))) return NULL;
547 if (wFlags & MF_BYPOSITION)
549 if (*nPos >= menu->nItems) return NULL;
550 return &menu->items[*nPos];
554 MENUITEM *item = menu->items;
555 for (i = 0; i < menu->nItems; i++, item++)
557 if (item->wID == *nPos)
562 else if (item->fType & MF_POPUP)
564 HMENU hsubmenu = item->hSubMenu;
565 MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
577 /***********************************************************************
580 static void MENU_FreeItemData( MENUITEM* item )
583 if (IS_STRING_ITEM(item->fType) && item->text)
584 HeapFree( SystemHeap, 0, item->text );
587 /***********************************************************************
588 * MENU_FindItemByCoords
590 * Find the item at the specified coordinates (screen coords). Does
591 * not work for child windows and therefore should not be called for
592 * an arbitrary system menu.
594 static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
595 POINT pt, UINT *pos )
601 if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
602 pt.x -= wrect.left;pt.y -= wrect.top;
604 for (i = 0; i < menu->nItems; i++, item++)
606 if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
607 (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
617 /***********************************************************************
620 * Find the menu item selected by a key press.
621 * Return item id, -1 if none, -2 if we should close the menu.
623 static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
624 UINT key, BOOL forceMenuChar )
626 TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
628 if (!IsMenu( hmenu ))
630 WND* w = WIN_FindWndPtr(hwndOwner);
631 hmenu = GetSubMenu(w->hSysMenu, 0);
632 WIN_ReleaseWndPtr(w);
637 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
638 MENUITEM *item = menu->items;
646 for (i = 0; i < menu->nItems; i++, item++)
648 if (item->text && (IS_STRING_ITEM(item->fType)))
650 char *p = item->text - 2;
653 p = strchr (p + 2, '&');
655 while (p != NULL && p [1] == '&');
656 if (p && (toupper(p[1]) == key)) return i;
660 menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
661 MAKEWPARAM( key, menu->wFlags ), hmenu );
662 if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
663 if (HIWORD(menuchar) == 1) return (UINT)(-2);
667 /***********************************************************************
670 * Load the bitmap associated with the magic menu item and its style
673 static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
676 * Magic menu item id's section
677 * These magic id's are used by windows to insert "standard" mdi
678 * buttons (minimize,restore,close) on menu. Under windows,
679 * these magic id's make sure the right things appear when those
680 * bitmap buttons are pressed/selected/released.
684 { case HBMMENU_SYSTEM:
685 return (dwItemData) ?
686 (HBITMAP)dwItemData :
687 (hilite ? hBmpMinimizeD : hBmpMinimize);
688 case HBMMENU_MBAR_RESTORE:
689 return (hilite ? hBmpMaximizeD: hBmpMaximize);
690 case HBMMENU_MBAR_MINIMIZE:
691 return (hilite ? hBmpMinimizeD : hBmpMinimize);
692 case HBMMENU_MBAR_CLOSE:
693 return (hilite ? hBmpCloseD : hBmpClose);
694 case HBMMENU_CALLBACK:
695 case HBMMENU_MBAR_CLOSE_D:
696 case HBMMENU_MBAR_MINIMIZE_D:
697 case HBMMENU_POPUP_CLOSE:
698 case HBMMENU_POPUP_RESTORE:
699 case HBMMENU_POPUP_MAXIMIZE:
700 case HBMMENU_POPUP_MINIMIZE:
702 FIXME("Magic 0x%08x not implemented\n", id);
708 /***********************************************************************
711 * Calculate the size of the menu item and store it in lpitem->rect.
713 static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
714 INT orgX, INT orgY, BOOL menuBar )
718 TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
719 debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
720 (menuBar ? " (MenuBar)" : ""));
722 SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
724 if (lpitem->fType & MF_OWNERDRAW)
726 MEASUREITEMSTRUCT mis;
727 mis.CtlType = ODT_MENU;
729 mis.itemID = lpitem->wID;
730 mis.itemData = (DWORD)lpitem->dwItemData;
733 SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
734 lpitem->rect.bottom += mis.itemHeight;
735 lpitem->rect.right += mis.itemWidth;
736 TRACE("id=%04x size=%dx%d\n",
737 lpitem->wID, mis.itemWidth, mis.itemHeight);
741 if (lpitem->fType & MF_SEPARATOR)
743 lpitem->rect.bottom += SEPARATOR_HEIGHT;
749 lpitem->rect.right += 2 * check_bitmap_width;
750 if (lpitem->fType & MF_POPUP)
751 lpitem->rect.right += arrow_bitmap_width;
754 if (IS_BITMAP_ITEM(lpitem->fType))
759 /* Check if there is a magic menu item associated with this item */
760 if((LOWORD((int)lpitem->text))<12)
762 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
766 resBmp = (HBITMAP)lpitem->text;
768 if (GetObjectA(resBmp, sizeof(bm), &bm ))
770 lpitem->rect.right += bm.bmWidth;
771 lpitem->rect.bottom += bm.bmHeight;
777 /* If we get here, then it must be a text item */
778 if (IS_STRING_ITEM( lpitem->fType ))
781 GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
783 lpitem->rect.right += size.cx;
784 if (TWEAK_WineLook == WIN31_LOOK)
785 lpitem->rect.bottom += MAX( size.cy, GetSystemMetrics(SM_CYMENU) );
787 lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
792 lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
794 else if ((p = strchr( lpitem->text, '\t' )) != NULL)
796 /* Item contains a tab (only meaningful in popup menus) */
797 GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
798 lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
799 lpitem->rect.right += MENU_TAB_SPACE;
803 if (strchr( lpitem->text, '\b' ))
804 lpitem->rect.right += MENU_TAB_SPACE;
805 lpitem->xTab = lpitem->rect.right - check_bitmap_width
806 - arrow_bitmap_width;
809 TRACE("(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
813 /***********************************************************************
814 * MENU_PopupMenuCalcSize
816 * Calculate the size of a popup menu.
818 static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
823 int orgX, orgY, maxX, maxTab, maxTabWidth;
825 lppop->Width = lppop->Height = 0;
826 if (lppop->nItems == 0) return;
829 SelectObject( hdc, hMenuFont);
832 maxX = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CXBORDER) : 2 ;
834 while (start < lppop->nItems)
836 lpitem = &lppop->items[start];
838 orgY = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CYBORDER) : 2;
840 maxTab = maxTabWidth = 0;
842 /* Parse items until column break or end of menu */
843 for (i = start; i < lppop->nItems; i++, lpitem++)
846 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
848 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
850 if (lpitem->fType & MF_MENUBARBREAK) orgX++;
851 maxX = MAX( maxX, lpitem->rect.right );
852 orgY = lpitem->rect.bottom;
853 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
855 maxTab = MAX( maxTab, lpitem->xTab );
856 maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
860 /* Finish the column (set all items to the largest width found) */
861 maxX = MAX( maxX, maxTab + maxTabWidth );
862 for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
864 lpitem->rect.right = maxX;
865 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
866 lpitem->xTab = maxTab;
869 lppop->Height = MAX( lppop->Height, orgY );
874 /* space for 3d border */
875 if(TWEAK_WineLook > WIN31_LOOK)
885 /***********************************************************************
886 * MENU_MenuBarCalcSize
888 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
889 * height is off by 1 pixel which causes lengthy window relocations when
890 * active document window is maximized/restored.
892 * Calculate the size of the menu bar.
894 static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
895 LPPOPUPMENU lppop, HWND hwndOwner )
898 int start, i, orgX, orgY, maxY, helpPos;
900 if ((lprect == NULL) || (lppop == NULL)) return;
901 if (lppop->nItems == 0) return;
902 TRACE("left=%d top=%d right=%d bottom=%d\n",
903 lprect->left, lprect->top, lprect->right, lprect->bottom);
904 lppop->Width = lprect->right - lprect->left;
909 while (start < lppop->nItems)
911 lpitem = &lppop->items[start];
915 /* Parse items until line break or end of menu */
916 for (i = start; i < lppop->nItems; i++, lpitem++)
918 if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
920 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
922 TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
924 debug_print_menuitem (" item: ", lpitem, "");
925 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
927 if (lpitem->rect.right > lprect->right)
929 if (i != start) break;
930 else lpitem->rect.right = lprect->right;
932 maxY = MAX( maxY, lpitem->rect.bottom );
933 orgX = lpitem->rect.right;
936 /* Finish the line (set all items to the largest height found) */
937 while (start < i) lppop->items[start++].rect.bottom = maxY;
940 lprect->bottom = maxY;
941 lppop->Height = lprect->bottom - lprect->top;
943 /* Flush right all magic items and items between the MF_HELP and */
944 /* the last item (if several lines, only move the last line) */
945 lpitem = &lppop->items[lppop->nItems-1];
946 orgY = lpitem->rect.top;
947 orgX = lprect->right;
948 for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
950 if ( !IS_BITMAP_ITEM(lpitem->fType) && ((helpPos ==-1) ? TRUE : (helpPos>i) ))
952 if (lpitem->rect.top != orgY) break; /* Other line */
953 if (lpitem->rect.right >= orgX) break; /* Too far right already */
954 lpitem->rect.left += orgX - lpitem->rect.right;
955 lpitem->rect.right = orgX;
956 orgX = lpitem->rect.left;
960 /***********************************************************************
963 * Draw a single menu item.
965 static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
966 UINT height, BOOL menuBar, UINT odaction )
970 debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
972 if (lpitem->fType & MF_SYSMENU)
974 if( !IsIconic(hwnd) ) {
975 if (TWEAK_WineLook > WIN31_LOOK)
976 NC_DrawSysButton95( hwnd, hdc,
978 (MF_HILITE | MF_MOUSESELECT) );
980 NC_DrawSysButton( hwnd, hdc,
982 (MF_HILITE | MF_MOUSESELECT) );
988 if (lpitem->fType & MF_OWNERDRAW)
992 dis.CtlType = ODT_MENU;
994 dis.itemID = lpitem->wID;
995 dis.itemData = (DWORD)lpitem->dwItemData;
997 if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
998 if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
999 if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
1000 dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
1001 dis.hwndItem = hmenu;
1003 dis.rcItem = lpitem->rect;
1004 TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
1005 "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
1006 dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
1007 dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
1009 SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
1013 TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
1014 lpitem->rect.right,lpitem->rect.bottom);
1016 if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
1018 rect = lpitem->rect;
1020 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
1021 if ((menuBar) && (TWEAK_WineLook==WIN98_LOOK))
1022 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
1024 FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
1026 FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
1028 SetBkMode( hdc, TRANSPARENT );
1030 /* vertical separator */
1031 if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
1033 if (TWEAK_WineLook > WIN31_LOOK)
1037 rc.bottom = height - 3;
1038 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
1042 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1043 MoveTo16( hdc, rect.left, 0 );
1044 LineTo( hdc, rect.left, height );
1048 /* horizontal separator */
1049 if (lpitem->fType & MF_SEPARATOR)
1051 if (TWEAK_WineLook > WIN31_LOOK)
1056 rc.top += SEPARATOR_HEIGHT / 2;
1057 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
1061 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1062 MoveTo16( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2 );
1063 LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 );
1070 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
1072 if (lpitem->fState & MF_GRAYED)
1073 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
1075 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
1076 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
1080 if (lpitem->fState & MF_GRAYED)
1081 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
1083 SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
1084 SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
1087 /* helper lines for debugging */
1088 /* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1089 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1090 MoveTo16( hdc, rect.left, (rect.top + rect.bottom)/2 );
1091 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1096 INT y = rect.top + rect.bottom;
1098 /* Draw the check mark
1101 * Custom checkmark bitmaps are monochrome but not always 1bpp.
1104 if (lpitem->fState & MF_CHECKED)
1106 HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
1107 ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
1108 HDC hdcMem = CreateCompatibleDC( hdc );
1110 SelectObject( hdcMem, bm );
1111 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
1112 check_bitmap_width, check_bitmap_height,
1113 hdcMem, 0, 0, SRCCOPY );
1116 else if (lpitem->hUnCheckBit)
1118 HDC hdcMem = CreateCompatibleDC( hdc );
1120 SelectObject( hdcMem, lpitem->hUnCheckBit );
1121 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
1122 check_bitmap_width, check_bitmap_height,
1123 hdcMem, 0, 0, SRCCOPY );
1127 /* Draw the popup-menu arrow */
1128 if (lpitem->fType & MF_POPUP)
1130 HDC hdcMem = CreateCompatibleDC( hdc );
1132 SelectObject( hdcMem, hStdMnArrow );
1133 BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
1134 (y - arrow_bitmap_height) / 2,
1135 arrow_bitmap_width, arrow_bitmap_height,
1136 hdcMem, 0, 0, SRCCOPY );
1140 rect.left += check_bitmap_width;
1141 rect.right -= arrow_bitmap_width;
1144 /* Draw the item text or bitmap */
1145 if (IS_BITMAP_ITEM(lpitem->fType))
1150 HDC hdcMem = CreateCompatibleDC( hdc );
1153 * Check if there is a magic menu item associated with this item
1154 * and load the appropriate bitmap
1156 if((LOWORD((int)lpitem->text)) < 12)
1158 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
1159 lpitem->dwItemData);
1162 resBmp = (HBITMAP)lpitem->text;
1167 GetObjectA( resBmp, sizeof(bm), &bm );
1169 SelectObject(hdcMem,resBmp );
1171 /* handle fontsize > bitmap_height */
1172 top = ((rect.bottom-rect.top)>bm.bmHeight) ?
1173 rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
1175 BitBlt( hdc, rect.left, top, rect.right - rect.left,
1176 rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
1183 /* No bitmap - process text if present */
1184 else if (IS_STRING_ITEM(lpitem->fType))
1189 UINT uFormat = (menuBar) ?
1190 DT_CENTER | DT_VCENTER | DT_SINGLELINE :
1191 DT_LEFT | DT_VCENTER | DT_SINGLELINE;
1193 if ( lpitem->fState & MFS_DEFAULT )
1195 hfontOld = SelectObject( hdc, hMenuFontBold);
1200 rect.left += MENU_BAR_ITEMS_SPACE / 2;
1201 rect.right -= MENU_BAR_ITEMS_SPACE / 2;
1202 i = strlen( lpitem->text );
1206 for (i = 0; lpitem->text[i]; i++)
1207 if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
1211 if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
1213 if (!(lpitem->fState & MF_HILITE) )
1215 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
1216 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
1217 DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
1218 --rect.left; --rect.top; --rect.right; --rect.bottom;
1220 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
1223 DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
1225 /* paint the shortcut text */
1226 if (lpitem->text[i]) /* There's a tab or flush-right char */
1228 if (lpitem->text[i] == '\t')
1230 rect.left = lpitem->xTab;
1231 uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
1235 uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
1238 if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
1240 if (!(lpitem->fState & MF_HILITE) )
1242 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
1243 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
1244 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
1245 --rect.left; --rect.top; --rect.right; --rect.bottom;
1247 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
1249 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
1253 SelectObject (hdc, hfontOld);
1258 /***********************************************************************
1259 * MENU_DrawPopupMenu
1261 * Paint a popup menu.
1263 static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
1265 HBRUSH hPrevBrush = 0;
1268 TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
1270 GetClientRect( hwnd, &rect );
1272 if(TWEAK_WineLook == WIN31_LOOK)
1274 rect.bottom -= POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
1275 rect.right -= POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER);
1278 if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
1279 && (SelectObject( hdc, hMenuFont)))
1283 Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
1285 hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
1291 /* draw 3-d shade */
1292 if(TWEAK_WineLook == WIN31_LOOK) {
1293 SelectObject( hdc, hShadeBrush );
1294 SetBkMode( hdc, TRANSPARENT );
1295 ropPrev = SetROP2( hdc, R2_MASKPEN );
1297 i = rect.right; /* why SetBrushOrg() doesn't? */
1298 PatBlt( hdc, i & 0xfffffffe,
1299 rect.top + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER),
1300 i%2 + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
1301 rect.bottom - rect.top, 0x00a000c9 );
1303 PatBlt( hdc, rect.left + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
1304 i & 0xfffffffe,rect.right - rect.left,
1305 i%2 + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER), 0x00a000c9 );
1306 SelectObject( hdc, hPrevPen );
1307 SelectObject( hdc, hPrevBrush );
1308 SetROP2( hdc, ropPrev );
1311 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
1313 /* draw menu items */
1315 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1316 if (menu && menu->nItems)
1321 for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
1322 MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
1323 menu->Height, FALSE, ODA_DRAWENTIRE );
1328 SelectObject( hdc, hPrevBrush );
1333 /***********************************************************************
1336 * Paint a menu bar. Returns the height of the menu bar.
1337 * called from [windows/nonclient.c]
1339 UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
1346 WND *wndPtr = WIN_FindWndPtr( hwnd );
1348 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( (HMENU)wndPtr->wIDmenu );
1349 if (lppop == NULL || lprect == NULL)
1351 retvalue = GetSystemMetrics(SM_CYMENU);
1355 TRACE("(%04x, %p, %p)\n", hDC, lprect, lppop);
1357 hfontOld = SelectObject( hDC, hMenuFont);
1359 if (lppop->Height == 0)
1360 MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
1362 lprect->bottom = lprect->top + lppop->Height;
1366 retvalue = lppop->Height;
1370 FillRect(hDC, lprect, GetSysColorBrush(COLOR_MENU) );
1372 if (TWEAK_WineLook == WIN31_LOOK)
1374 SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
1375 MoveTo16( hDC, lprect->left, lprect->bottom );
1376 LineTo( hDC, lprect->right, lprect->bottom );
1380 SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
1381 MoveTo16( hDC, lprect->left, lprect->bottom );
1382 LineTo( hDC, lprect->right, lprect->bottom );
1385 if (lppop->nItems == 0)
1387 retvalue = GetSystemMetrics(SM_CYMENU);
1391 for (i = 0; i < lppop->nItems; i++)
1393 MENU_DrawMenuItem( hwnd, (HMENU)wndPtr->wIDmenu, GetWindow(hwnd,GW_OWNER),
1394 hDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
1396 retvalue = lppop->Height;
1400 SelectObject (hDC, hfontOld);
1402 WIN_ReleaseWndPtr(wndPtr);
1406 /***********************************************************************
1407 * MENU_PatchResidentPopup
1409 BOOL MENU_PatchResidentPopup( HQUEUE16 checkQueue, WND* checkWnd )
1411 WND *pTPWnd = MENU_GetTopPopupWnd();
1417 TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
1418 checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
1419 pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
1421 switch( checkQueue )
1423 case 0: /* checkWnd is the new popup owner */
1426 pTPWnd->owner = checkWnd;
1427 if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
1428 hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
1432 case 0xFFFF: /* checkWnd is destroyed */
1433 if( pTPWnd->owner == checkWnd )
1434 pTPWnd->owner = NULL;
1435 MENU_ReleaseTopPopupWnd();
1438 default: /* checkQueue is exiting */
1439 if( pTPWnd->hmemTaskQ == checkQueue )
1441 hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
1442 hTask = TASK_GetNextTask( hTask );
1449 TDB* task = (TDB*)GlobalLock16( hTask );
1452 pTPWnd->hInstance = task->hInstance;
1453 pTPWnd->hmemTaskQ = task->hQueue;
1454 MENU_ReleaseTopPopupWnd();
1457 else WARN("failed to patch resident popup.\n");
1460 MENU_ReleaseTopPopupWnd();
1464 /***********************************************************************
1467 * Display a popup menu.
1469 static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
1470 INT x, INT y, INT xanchor, INT yanchor )
1473 WND *wndOwner = NULL;
1475 TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
1476 hwndOwner, hmenu, id, x, y, xanchor, yanchor);
1478 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
1479 if (menu->FocusedItem != NO_SELECTED_ITEM)
1481 menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
1482 menu->FocusedItem = NO_SELECTED_ITEM;
1485 /* store the owner for DrawItem*/
1486 menu->hwndOwner = hwndOwner;
1488 if( (wndOwner = WIN_FindWndPtr( hwndOwner )) )
1492 MENU_PopupMenuCalcSize( menu, hwndOwner );
1494 /* adjust popup menu pos so that it fits within the desktop */
1496 width = menu->Width + GetSystemMetrics(SM_CXBORDER);
1497 height = menu->Height + GetSystemMetrics(SM_CYBORDER);
1499 if( x + width > GetSystemMetrics(SM_CXSCREEN ))
1502 x -= width - xanchor;
1503 if( x + width > GetSystemMetrics(SM_CXSCREEN))
1504 x = GetSystemMetrics(SM_CXSCREEN) - width;
1508 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
1511 y -= height + yanchor;
1512 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
1513 y = GetSystemMetrics(SM_CYSCREEN) - height;
1517 if( TWEAK_WineLook == WIN31_LOOK )
1519 width += POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER); /* add space for shading */
1520 height += POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
1523 /* NOTE: In Windows, top menu popup is not owned. */
1524 if (!pTopPopupWnd) /* create top level popup menu window */
1526 assert( uSubPWndLevel == 0 );
1528 pTopPopupWnd = WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
1529 WS_POPUP, x, y, width, height,
1530 hwndOwner, 0, wndOwner->hInstance,
1534 WIN_ReleaseWndPtr(wndOwner);
1537 menu->hWnd = pTopPopupWnd->hwndSelf;
1538 MENU_ReleaseTopPopupWnd();
1543 /* create a new window for the submenu */
1545 menu->hWnd = CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
1546 WS_POPUP, x, y, width, height,
1547 hwndOwner, 0, wndOwner->hInstance,
1551 WIN_ReleaseWndPtr(wndOwner);
1555 else /* top level popup menu window already exists */
1557 WND *pTPWnd = MENU_GetTopPopupWnd();
1558 menu->hWnd = pTPWnd->hwndSelf;
1560 MENU_PatchResidentPopup( 0, wndOwner );
1561 SendMessageA( pTPWnd->hwndSelf, MM_SETMENUHANDLE, (WPARAM16)hmenu, 0L);
1563 /* adjust its size */
1565 SetWindowPos( menu->hWnd, 0, x, y, width, height,
1566 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
1567 MENU_ReleaseTopPopupWnd();
1570 uSubPWndLevel++; /* menu level counter */
1572 /* Display the window */
1574 SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
1575 SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1576 UpdateWindow( menu->hWnd );
1577 WIN_ReleaseWndPtr(wndOwner);
1584 /***********************************************************************
1587 static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
1588 BOOL sendMenuSelect )
1593 TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
1595 lppop = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1596 if (!lppop->nItems) return;
1598 if ((wIndex != NO_SELECTED_ITEM) &&
1599 (lppop->items[wIndex].fType & MF_SEPARATOR))
1600 wIndex = NO_SELECTED_ITEM;
1602 if (lppop->FocusedItem == wIndex) return;
1603 if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
1604 else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
1606 SelectObject( hdc, hMenuFont);
1608 /* Clear previous highlighted item */
1609 if (lppop->FocusedItem != NO_SELECTED_ITEM)
1611 lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
1612 MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
1613 lppop->Height, !(lppop->wFlags & MF_POPUP),
1617 /* Highlight new item (if any) */
1618 lppop->FocusedItem = wIndex;
1619 if (lppop->FocusedItem != NO_SELECTED_ITEM)
1621 lppop->items[lppop->FocusedItem].fState |= MF_HILITE;
1622 MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc, &lppop->items[lppop->FocusedItem],
1623 lppop->Height, !(lppop->wFlags & MF_POPUP),
1627 MENUITEM *ip = &lppop->items[lppop->FocusedItem];
1628 SendMessageA( hwndOwner, WM_MENUSELECT,
1629 MAKELONG(ip->wID,ip->fType | (ip->fState | MF_MOUSESELECT)), hmenu);
1632 else if (sendMenuSelect) {
1633 SendMessageA( hwndOwner, WM_MENUSELECT,
1634 MAKELONG( hmenu, lppop->wFlags | MF_MOUSESELECT), hmenu );
1636 ReleaseDC( lppop->hWnd, hdc );
1640 /***********************************************************************
1641 * MENU_MoveSelection
1643 * Moves currently selected item according to the offset parameter.
1644 * If there is no selection then it should select the last item if
1645 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
1647 static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
1652 TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner, hmenu, offset);
1654 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1655 if (!menu->items) return;
1657 if ( menu->FocusedItem != NO_SELECTED_ITEM )
1659 if( menu->nItems == 1 ) return; else
1660 for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
1662 if (!(menu->items[i].fType & MF_SEPARATOR))
1664 MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
1669 for ( i = (offset > 0) ? 0 : menu->nItems - 1;
1670 i >= 0 && i < menu->nItems ; i += offset)
1671 if (!(menu->items[i].fType & MF_SEPARATOR))
1673 MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
1679 /**********************************************************************
1682 * Set an item flags, id and text ptr. Called by InsertMenu() and
1685 static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
1688 LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
1690 debug_print_menuitem("MENU_SetItemData from: ", item, "");
1692 if (IS_STRING_ITEM(flags))
1696 flags |= MF_SEPARATOR;
1702 /* Item beginning with a backspace is a help item */
1708 if (!(text = HEAP_strdupA( SystemHeap, 0, str ))) return FALSE;
1712 else if (IS_BITMAP_ITEM(flags))
1713 item->text = (LPSTR)(HBITMAP)LOWORD(str);
1714 else item->text = NULL;
1716 if (flags & MF_OWNERDRAW)
1717 item->dwItemData = (DWORD)str;
1719 item->dwItemData = 0;
1721 if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
1722 DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
1724 if (flags & MF_POPUP)
1726 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)id);
1727 if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
1739 if (flags & MF_POPUP)
1740 item->hSubMenu = id;
1742 if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
1743 flags |= MF_POPUP; /* keep popup */
1745 item->fType = flags & TYPE_MASK;
1746 item->fState = (flags & STATE_MASK) &
1747 ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
1750 /* Don't call SetRectEmpty here! */
1753 if (prevText) HeapFree( SystemHeap, 0, prevText );
1755 debug_print_menuitem("MENU_SetItemData to : ", item, "");
1760 /**********************************************************************
1763 * Insert a new item into a menu.
1765 static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
1770 if (!(menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu)))
1772 WARN("%04x not a menu handle\n",
1777 /* Find where to insert new item */
1779 if ((flags & MF_BYPOSITION) &&
1780 ((pos == (UINT)-1) || (pos == menu->nItems)))
1782 /* Special case: append to menu */
1783 /* Some programs specify the menu length to do that */
1788 if (!MENU_FindItem( &hMenu, &pos, flags ))
1790 WARN("item %x not found\n",
1794 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
1796 WARN("%04x not a menu handle\n",
1802 /* Create new items array */
1804 newItems = HeapAlloc( SystemHeap, 0, sizeof(MENUITEM) * (menu->nItems+1) );
1807 WARN("allocation failed\n" );
1810 if (menu->nItems > 0)
1812 /* Copy the old array into the new */
1813 if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
1814 if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
1815 (menu->nItems-pos)*sizeof(MENUITEM) );
1816 HeapFree( SystemHeap, 0, menu->items );
1818 menu->items = newItems;
1820 memset( &newItems[pos], 0, sizeof(*newItems) );
1821 return &newItems[pos];
1825 /**********************************************************************
1826 * MENU_ParseResource
1828 * Parse a standard menu resource and add items to the menu.
1829 * Return a pointer to the end of the resource.
1831 static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
1838 flags = GET_WORD(res);
1839 res += sizeof(WORD);
1840 if (!(flags & MF_POPUP))
1843 res += sizeof(WORD);
1845 if (!IS_STRING_ITEM(flags))
1846 ERR("not a string item %04x\n", flags );
1848 if (!unicode) res += strlen(str) + 1;
1849 else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
1850 if (flags & MF_POPUP)
1852 HMENU hSubMenu = CreatePopupMenu();
1853 if (!hSubMenu) return NULL;
1854 if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
1856 if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
1857 else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
1859 else /* Not a popup */
1861 if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1862 else AppendMenuW( hMenu, flags, id,
1863 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
1865 } while (!(flags & MF_END));
1870 /**********************************************************************
1871 * MENUEX_ParseResource
1873 * Parse an extended menu resource and add items to the menu.
1874 * Return a pointer to the end of the resource.
1876 static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
1882 mii.cbSize = sizeof(mii);
1883 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
1884 mii.fType = GET_DWORD(res);
1885 res += sizeof(DWORD);
1886 mii.fState = GET_DWORD(res);
1887 res += sizeof(DWORD);
1888 mii.wID = GET_DWORD(res);
1889 res += sizeof(DWORD);
1890 resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte. */
1891 res += sizeof(WORD);
1892 /* Align the text on a word boundary. */
1893 res += (~((int)res - 1)) & 1;
1894 mii.dwTypeData = (LPWSTR) res;
1895 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
1896 /* Align the following fields on a dword boundary. */
1897 res += (~((int)res - 1)) & 3;
1899 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1901 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
1903 TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
1904 mii.fType, mii.fState, mii.wID, resinfo, newstr);
1905 HeapFree( GetProcessHeap(), 0, newstr );
1908 if (resinfo & 1) { /* Pop-up? */
1909 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
1910 res += sizeof(DWORD);
1911 mii.hSubMenu = CreatePopupMenu();
1914 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
1915 DestroyMenu(mii.hSubMenu);
1918 mii.fMask |= MIIM_SUBMENU;
1919 mii.fType |= MF_POPUP;
1921 InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
1922 } while (!(resinfo & MF_END));
1927 /***********************************************************************
1930 * Return the handle of the selected sub-popup menu (if any).
1932 static HMENU MENU_GetSubPopup( HMENU hmenu )
1937 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1939 if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
1941 item = &menu->items[menu->FocusedItem];
1942 if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
1943 return item->hSubMenu;
1948 /***********************************************************************
1949 * MENU_HideSubPopups
1951 * Hide the sub-popup menus of this menu.
1953 static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
1954 BOOL sendMenuSelect )
1956 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR( hmenu );;
1958 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
1960 if (menu && uSubPWndLevel)
1966 if (menu->FocusedItem != NO_SELECTED_ITEM)
1968 item = &menu->items[menu->FocusedItem];
1969 if (!(item->fType & MF_POPUP) ||
1970 !(item->fState & MF_MOUSESELECT)) return;
1971 item->fState &= ~MF_MOUSESELECT;
1972 hsubmenu = item->hSubMenu;
1975 submenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hsubmenu );
1976 MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
1977 MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect );
1979 if (submenu->hWnd == MENU_GetTopPopupWnd()->hwndSelf )
1981 ShowWindow( submenu->hWnd, SW_HIDE );
1986 DestroyWindow( submenu->hWnd );
1989 MENU_ReleaseTopPopupWnd();
1994 /***********************************************************************
1997 * Display the sub-menu of the selected item of this menu.
1998 * Return the handle of the submenu, or hmenu if no submenu to display.
2000 static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
2009 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
2011 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return hmenu;
2013 if (!(wndPtr = WIN_FindWndPtr( menu->hWnd )) ||
2014 (menu->FocusedItem == NO_SELECTED_ITEM))
2016 WIN_ReleaseWndPtr(wndPtr);
2020 item = &menu->items[menu->FocusedItem];
2021 if (!(item->fType & MF_POPUP) ||
2022 (item->fState & (MF_GRAYED | MF_DISABLED)))
2024 WIN_ReleaseWndPtr(wndPtr);
2028 /* message must be send before using item,
2029 because nearly everything may by changed by the application ! */
2031 SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
2032 MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
2034 item = &menu->items[menu->FocusedItem];
2037 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2038 if (!(item->fState & MF_HILITE))
2040 if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
2041 else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
2043 SelectObject( hdc, hMenuFont);
2045 item->fState |= MF_HILITE;
2046 MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
2047 ReleaseDC( menu->hWnd, hdc );
2049 if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
2052 item->fState |= MF_MOUSESELECT;
2054 if (IS_SYSTEM_MENU(menu))
2056 MENU_InitSysMenuPopup(item->hSubMenu, wndPtr->dwStyle, GetClassLongA(wndPtr->hwndSelf, GCL_STYLE));
2058 NC_GetSysPopupPos( wndPtr, &rect );
2059 rect.top = rect.bottom;
2060 rect.right = GetSystemMetrics(SM_CXSIZE);
2061 rect.bottom = GetSystemMetrics(SM_CYSIZE);
2065 if (menu->wFlags & MF_POPUP)
2067 rect.left = wndPtr->rectWindow.left + item->rect.right-arrow_bitmap_width;
2068 rect.top = wndPtr->rectWindow.top + item->rect.top;
2069 rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
2070 rect.bottom = item->rect.top - item->rect.bottom;
2074 rect.left = wndPtr->rectWindow.left + item->rect.left;
2075 rect.top = wndPtr->rectWindow.top + item->rect.bottom;
2076 rect.right = item->rect.right - item->rect.left;
2077 rect.bottom = item->rect.bottom - item->rect.top;
2081 MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
2082 rect.left, rect.top, rect.right, rect.bottom );
2084 MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
2085 WIN_ReleaseWndPtr(wndPtr);
2086 return item->hSubMenu;
2089 /***********************************************************************
2092 * Walks menu chain trying to find a menu pt maps to.
2094 static HMENU MENU_PtMenu( HMENU hMenu, POINT16 pt )
2096 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
2097 register UINT ht = menu->FocusedItem;
2099 /* try subpopup first (if any) */
2100 ht = (ht != NO_SELECTED_ITEM &&
2101 (menu->items[ht].fType & MF_POPUP) &&
2102 (menu->items[ht].fState & MF_MOUSESELECT))
2103 ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0;
2105 if( !ht ) /* check the current window (avoiding WM_HITTEST) */
2107 ht = (UINT)NC_HandleNCHitTest( menu->hWnd, pt );
2108 if( menu->wFlags & MF_POPUP )
2109 ht = (ht != (UINT)HTNOWHERE &&
2110 ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
2113 WND* wndPtr = WIN_FindWndPtr(menu->hWnd);
2115 ht = ( ht == HTSYSMENU ) ? (UINT)(wndPtr->hSysMenu)
2116 : ( ht == HTMENU ) ? (UINT)(wndPtr->wIDmenu) : 0;
2117 WIN_ReleaseWndPtr(wndPtr);
2123 /***********************************************************************
2124 * MENU_ExecFocusedItem
2126 * Execute a menu item (for instance when user pressed Enter).
2127 * Return the wID of the executed item. Otherwise, zero indicating
2128 * that no menu item wase executed;
2129 * Have to receive the flags for the TrackPopupMenu options to avoid
2130 * sending unwanted message.
2133 static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
2136 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
2138 TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
2140 if (!menu || !menu->nItems ||
2141 (menu->FocusedItem == NO_SELECTED_ITEM)) return 0;
2143 item = &menu->items[menu->FocusedItem];
2145 TRACE("%08x %08x %08x\n",
2146 hMenu, item->wID, item->hSubMenu);
2148 if (!(item->fType & MF_POPUP))
2150 if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
2152 /* If TPM_RETURNCMD is set you return the id, but
2153 do not send a message to the owner */
2154 if(!(wFlags & TPM_RETURNCMD))
2156 if( menu->wFlags & MF_SYSMENU )
2157 PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
2158 MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
2160 PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
2166 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hMenu, TRUE );
2171 /***********************************************************************
2172 * MENU_SwitchTracking
2174 * Helper function for menu navigation routines.
2176 static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
2178 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2179 POPUPMENU *topmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
2181 TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
2183 if( pmt->hTopMenu != hPtMenu &&
2184 !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
2186 /* both are top level menus (system and menu-bar) */
2188 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2189 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE );
2190 pmt->hTopMenu = hPtMenu;
2192 else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
2193 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE );
2197 /***********************************************************************
2200 * Return TRUE if we can go on with menu tracking.
2202 static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu )
2204 TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
2209 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2212 if( IS_SYSTEM_MENU(ptmenu) )
2213 item = ptmenu->items;
2215 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2219 if( ptmenu->FocusedItem == id )
2221 /* nothing to do with already selected non-popup */
2222 if( !(item->fType & MF_POPUP) ) return TRUE;
2224 if( item->fState & MF_MOUSESELECT )
2226 if( ptmenu->wFlags & MF_POPUP )
2228 /* hide selected subpopup */
2230 MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, TRUE );
2231 pmt->hCurrentMenu = hPtMenu;
2234 return FALSE; /* shouldn't get here */
2237 else MENU_SwitchTracking( pmt, hPtMenu, id );
2239 /* try to display a subpopup */
2241 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE );
2244 else WARN("\tunable to find clicked item!\n");
2249 /***********************************************************************
2252 * Return the value of MENU_ExecFocusedItem if
2253 * the selected item was not a popup. Else open the popup.
2254 * A zero return value indicates that we go on with menu tracking.
2257 static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
2259 TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
2264 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2267 if( IS_SYSTEM_MENU(ptmenu) )
2268 item = ptmenu->items;
2270 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2272 if( item && (ptmenu->FocusedItem == id ))
2274 if( !(item->fType & MF_POPUP) )
2275 return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
2276 hPtMenu = item->hSubMenu;
2277 if( hPtMenu == pmt->hCurrentMenu )
2279 /* Select first item of sub-popup */
2281 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, NO_SELECTED_ITEM, FALSE );
2282 MENU_MoveSelection( pmt->hOwnerWnd, hPtMenu, ITEM_NEXT );
2290 /***********************************************************************
2293 * Return TRUE if we can go on with menu tracking.
2295 static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu )
2297 UINT id = NO_SELECTED_ITEM;
2298 POPUPMENU *ptmenu = NULL;
2302 ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2303 if( IS_SYSTEM_MENU(ptmenu) )
2306 MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2309 if( id == NO_SELECTED_ITEM )
2311 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2312 NO_SELECTED_ITEM, TRUE );
2314 else if( ptmenu->FocusedItem != id )
2316 MENU_SwitchTracking( pmt, hPtMenu, id );
2317 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE );
2323 /***********************************************************************
2326 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
2328 static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
2330 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
2332 if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
2333 (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
2339 LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
2340 (IS_SYSTEM_MENU(menu)) ? GetSubMenu16(pmt->hTopMenu,0) : pmt->hTopMenu );
2342 TRACE("%04x [%04x] -> %04x [%04x]\n",
2343 (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
2347 wndPtr = WIN_FindWndPtr(pmt->hOwnerWnd);
2349 hNewWnd = pmt->hOwnerWnd;
2350 if( IS_SYSTEM_MENU(menu) )
2352 /* switch to the menu bar */
2354 if( wndPtr->dwStyle & WS_CHILD || !wndPtr->wIDmenu )
2356 WIN_ReleaseWndPtr(wndPtr);
2360 hNewMenu = wndPtr->wIDmenu;
2363 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hNewMenu );
2364 id = menu->nItems - 1;
2367 else if( wndPtr->dwStyle & WS_SYSMENU )
2369 /* switch to the system menu */
2370 hNewMenu = wndPtr->hSysMenu;
2374 WIN_ReleaseWndPtr(wndPtr);
2377 WIN_ReleaseWndPtr(wndPtr);
2379 else /* application returned a new menu to switch to */
2381 hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
2383 if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
2385 wndPtr = WIN_FindWndPtr(hNewWnd);
2387 if( wndPtr->dwStyle & WS_SYSMENU &&
2388 GetSubMenu16(wndPtr->hSysMenu, 0) == hNewMenu )
2390 /* get the real system menu */
2391 hNewMenu = wndPtr->hSysMenu;
2393 else if( wndPtr->dwStyle & WS_CHILD || wndPtr->wIDmenu != hNewMenu )
2395 /* FIXME: Not sure what to do here, perhaps,
2396 * try to track hNewMenu as a popup? */
2398 TRACE(" -- got confused.\n");
2399 WIN_ReleaseWndPtr(wndPtr);
2402 WIN_ReleaseWndPtr(wndPtr);
2407 if( hNewMenu != pmt->hTopMenu )
2409 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE );
2410 if( pmt->hCurrentMenu != pmt->hTopMenu )
2411 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2414 if( hNewWnd != pmt->hOwnerWnd )
2417 pmt->hOwnerWnd = hNewWnd;
2418 EVENT_Capture( pmt->hOwnerWnd, HTMENU );
2421 pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
2422 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE );
2429 /***********************************************************************
2432 * The idea is not to show the popup if the next input message is
2433 * going to hide it anyway.
2435 static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT16 uMsg )
2439 msg.hwnd = pmt->hOwnerWnd;
2441 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2442 pmt->trackFlags |= TF_SKIPREMOVE;
2447 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
2448 if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
2450 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2451 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
2452 if( msg.message == WM_KEYDOWN &&
2453 (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
2455 pmt->trackFlags |= TF_SUSPENDPOPUP;
2462 /* failures go through this */
2463 pmt->trackFlags &= ~TF_SUSPENDPOPUP;
2467 /***********************************************************************
2470 * Handle a VK_LEFT key event in a menu.
2472 static void MENU_KeyLeft( MTRACKER* pmt )
2475 HMENU hmenutmp, hmenuprev;
2478 hmenuprev = hmenutmp = pmt->hTopMenu;
2479 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenutmp );
2481 /* Try to move 1 column left (if possible) */
2482 if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
2483 NO_SELECTED_ITEM ) {
2485 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2490 /* close topmost popup */
2491 while (hmenutmp != pmt->hCurrentMenu)
2493 hmenuprev = hmenutmp;
2494 hmenutmp = MENU_GetSubPopup( hmenuprev );
2497 MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
2498 pmt->hCurrentMenu = hmenuprev;
2500 if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
2502 /* move menu bar selection if no more popups are left */
2504 if( !MENU_DoNextMenu( pmt, VK_LEFT) )
2505 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
2507 if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2509 /* A sublevel menu was displayed - display the next one
2510 * unless there is another displacement coming up */
2512 if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
2513 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd,
2514 pmt->hTopMenu, TRUE );
2520 /***********************************************************************
2523 * Handle a VK_RIGHT key event in a menu.
2525 static void MENU_KeyRight( MTRACKER* pmt )
2528 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
2531 TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
2533 ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
2535 pmt->hTopMenu, menu->items[0].text );
2537 if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
2539 /* If already displaying a popup, try to display sub-popup */
2541 hmenutmp = pmt->hCurrentMenu;
2542 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hmenutmp, TRUE );
2544 /* if subpopup was displayed then we are done */
2545 if (hmenutmp != pmt->hCurrentMenu) return;
2548 /* Check to see if there's another column */
2549 if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
2550 NO_SELECTED_ITEM ) {
2551 TRACE("Going to %d.\n", nextcol );
2552 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2557 if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
2559 if( pmt->hCurrentMenu != pmt->hTopMenu )
2561 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2562 hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
2563 } else hmenutmp = 0;
2565 /* try to move to the next item */
2566 if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
2567 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
2569 if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2570 if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
2571 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd,
2572 pmt->hTopMenu, TRUE );
2576 /***********************************************************************
2579 * Menu tracking code.
2581 static INT MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
2582 HWND hwnd, const RECT *lprect )
2587 INT executedMenuId = 0;
2591 mt.hCurrentMenu = hmenu;
2592 mt.hTopMenu = hmenu;
2593 mt.hOwnerWnd = hwnd;
2597 TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
2598 hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
2599 (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
2602 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
2604 if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu );
2606 EVENT_Capture( mt.hOwnerWnd, HTMENU );
2610 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2611 msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
2613 /* we have to keep the message in the queue until it's
2614 * clear that menu loop is not over yet. */
2616 if (!MSG_InternalGetMessage( &msg, msg.hwnd, mt.hOwnerWnd,
2617 MSGF_MENU, PM_NOREMOVE, TRUE )) break;
2619 TranslateMessage( &msg );
2623 if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
2625 /* Find a menu for this mouse event */
2627 CONV_POINT32TO16( &msg.pt, &pt16 );
2628 hmenu = MENU_PtMenu( mt.hTopMenu, pt16 );
2632 /* no WM_NC... messages in captured state */
2634 case WM_RBUTTONDBLCLK:
2635 case WM_RBUTTONDOWN:
2636 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2638 case WM_LBUTTONDBLCLK:
2639 case WM_LBUTTONDOWN:
2640 fEndMenu |= !MENU_ButtonDown( &mt, hmenu );
2644 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2647 /* Check if a menu was selected by the mouse */
2650 executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
2652 /* End the loop if executedMenuId is an item ID */
2653 /* or if the job was done (executedMenuId = 1). */
2654 fEndMenu = fRemove = (executedMenuId != 0);
2656 /* No menu was selected by the mouse */
2657 /* if the function was called by TrackPopupMenu, continue
2658 with the menu tracking. If not, stop it */
2660 fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
2665 /* In win95 winelook, the selected menu item must be changed every time the
2666 mouse moves. In Win31 winelook, the mouse button has to be held down */
2668 if ( (TWEAK_WineLook > WIN31_LOOK) ||
2669 ( (msg.wParam & MK_LBUTTON) ||
2670 ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
2672 fEndMenu |= !MENU_MouseMove( &mt, hmenu );
2674 } /* switch(msg.message) - mouse */
2676 else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
2678 fRemove = TRUE; /* Keyboard messages are always removed */
2686 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
2687 NO_SELECTED_ITEM, FALSE );
2690 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
2691 (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
2694 case VK_DOWN: /* If on menu bar, pull-down the menu */
2696 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2697 if (!(menu->wFlags & MF_POPUP))
2698 mt.hCurrentMenu = MENU_ShowSubPopup( mt.hOwnerWnd, mt.hTopMenu, TRUE );
2699 else /* otherwise try to move selection */
2700 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
2704 MENU_KeyLeft( &mt );
2708 MENU_KeyRight( &mt );
2718 break; /* WM_KEYDOWN */
2728 break; /* WM_SYSKEYDOWN */
2734 if (msg.wParam == '\r' || msg.wParam == ' ')
2736 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
2737 fEndMenu = (executedMenuId != 0);
2742 /* Hack to avoid control chars. */
2743 /* We will find a better way real soon... */
2744 if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
2746 pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
2747 LOWORD(msg.wParam), FALSE );
2748 if (pos == (UINT)-2) fEndMenu = TRUE;
2749 else if (pos == (UINT)-1) MessageBeep(0);
2752 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos, TRUE );
2753 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
2754 fEndMenu = (executedMenuId != 0);
2758 } /* switch(msg.message) - kbd */
2762 DispatchMessageA( &msg );
2765 if (!fEndMenu) fRemove = TRUE;
2767 /* finally remove message from the queue */
2769 if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
2770 PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
2771 else mt.trackFlags &= ~TF_SKIPREMOVE;
2776 if( IsWindow( mt.hOwnerWnd ) )
2778 MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
2780 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hTopMenu );
2781 if (menu && menu->wFlags & MF_POPUP)
2783 ShowWindow( menu->hWnd, SW_HIDE );
2786 MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE );
2787 SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0), 0xffff );
2790 /* returning the id of the selected menu.
2791 The return value is only used by TrackPopupMenu */
2792 return executedMenuId;
2795 /***********************************************************************
2798 static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup)
2801 TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
2804 SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
2805 SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
2806 SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
2809 /***********************************************************************
2812 static BOOL MENU_ExitTracking(HWND hWnd)
2814 TRACE("hwnd=0x%04x\n", hWnd);
2816 SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
2821 /***********************************************************************
2822 * MENU_TrackMouseMenuBar
2824 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2826 void MENU_TrackMouseMenuBar( WND* wndPtr, INT ht, POINT pt )
2828 HWND hWnd = wndPtr->hwndSelf;
2829 HMENU hMenu = (ht == HTSYSMENU) ? wndPtr->hSysMenu : wndPtr->wIDmenu;
2831 TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
2835 MENU_InitTracking( hWnd, hMenu, FALSE );
2836 MENU_TrackMenu( hMenu, TPM_ENTERIDLEEX | TPM_BUTTONDOWN |
2837 TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, hWnd, NULL );
2838 MENU_ExitTracking(hWnd);
2843 /***********************************************************************
2844 * MENU_TrackKbdMenuBar
2846 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2848 void MENU_TrackKbdMenuBar( WND* wndPtr, UINT wParam, INT vkey)
2850 UINT uItem = NO_SELECTED_ITEM;
2853 /* find window that has a menu */
2855 while( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwStyle & WS_SYSMENU) )
2856 if( !(wndPtr = wndPtr->parent) ) return;
2858 /* check if we have to track a system menu */
2860 if( (wndPtr->dwStyle & (WS_CHILD | WS_MINIMIZE)) ||
2861 !wndPtr->wIDmenu || vkey == VK_SPACE )
2863 if( !(wndPtr->dwStyle & WS_SYSMENU) ) return;
2864 hTrackMenu = wndPtr->hSysMenu;
2866 wParam |= HTSYSMENU; /* prevent item lookup */
2869 hTrackMenu = wndPtr->wIDmenu;
2871 if (IsMenu( hTrackMenu ))
2873 MENU_InitTracking( wndPtr->hwndSelf, hTrackMenu, FALSE );
2875 if( vkey && vkey != VK_SPACE )
2877 uItem = MENU_FindItemByKey( wndPtr->hwndSelf, hTrackMenu,
2878 vkey, (wParam & HTSYSMENU) );
2879 if( uItem >= (UINT)(-2) )
2881 if( uItem == (UINT)(-1) ) MessageBeep(0);
2888 MENU_SelectItem( wndPtr->hwndSelf, hTrackMenu, uItem, TRUE );
2890 if( uItem == NO_SELECTED_ITEM )
2891 MENU_MoveSelection( wndPtr->hwndSelf, hTrackMenu, ITEM_NEXT );
2893 PostMessageA( wndPtr->hwndSelf, WM_KEYDOWN, VK_DOWN, 0L );
2895 MENU_TrackMenu( hTrackMenu, TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON,
2896 0, 0, wndPtr->hwndSelf, NULL );
2899 MENU_ExitTracking (wndPtr->hwndSelf);
2904 /**********************************************************************
2905 * TrackPopupMenu16 (USER.416)
2907 BOOL16 WINAPI TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
2908 INT16 nReserved, HWND16 hWnd, const RECT16 *lpRect )
2912 CONV_RECT16TO32( lpRect, &r );
2913 return TrackPopupMenu( hMenu, wFlags, x, y, nReserved, hWnd,
2914 lpRect ? &r : NULL );
2918 /**********************************************************************
2919 * TrackPopupMenu (USER32.549)
2921 * Like the win32 API, the function return the command ID only if the
2922 * flag TPM_RETURNCMD is on.
2925 BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
2926 INT nReserved, HWND hWnd, const RECT *lpRect )
2930 MENU_InitTracking(hWnd, hMenu, TRUE);
2931 SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
2932 if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
2933 ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
2934 MENU_ExitTracking(hWnd);
2936 if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
2942 /**********************************************************************
2943 * TrackPopupMenuEx (USER32.550)
2945 BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
2946 HWND hWnd, LPTPMPARAMS lpTpm )
2948 FIXME("not fully implemented\n" );
2949 return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
2950 lpTpm ? &lpTpm->rcExclude : NULL );
2953 /***********************************************************************
2956 * NOTE: Windows has totally different (and undocumented) popup wndproc.
2958 LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
2961 WND* wndPtr = WIN_FindWndPtr(hwnd);
2964 TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
2965 hwnd, message, wParam, lParam);
2971 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
2972 SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
2977 case WM_MOUSEACTIVATE: /* We don't want to be activated */
2978 retvalue = MA_NOACTIVATE;
2984 BeginPaint( hwnd, &ps );
2985 MENU_DrawPopupMenu( hwnd, ps.hdc,
2986 (HMENU)GetWindowLongA( hwnd, 0 ) );
2987 EndPaint( hwnd, &ps );
2997 /* zero out global pointer in case resident popup window
2998 * was somehow destroyed. */
3000 if(MENU_GetTopPopupWnd() )
3002 if( hwnd == pTopPopupWnd->hwndSelf )
3004 ERR("resident popup destroyed!\n");
3006 MENU_DestroyTopPopupWnd();
3011 MENU_ReleaseTopPopupWnd();
3019 if( !(*(HMENU*)wndPtr->wExtra) )
3020 ERR("no menu to display\n");
3023 *(HMENU*)wndPtr->wExtra = 0;
3026 case MM_SETMENUHANDLE:
3028 *(HMENU*)wndPtr->wExtra = (HMENU)wParam;
3031 case MM_GETMENUHANDLE:
3033 retvalue = *(HMENU*)wndPtr->wExtra;
3037 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
3042 WIN_ReleaseWndPtr(wndPtr);
3047 /***********************************************************************
3048 * MENU_GetMenuBarHeight
3050 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3052 UINT MENU_GetMenuBarHeight( HWND hwnd, UINT menubarWidth,
3053 INT orgX, INT orgY )
3061 TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
3062 hwnd, menubarWidth, orgX, orgY );
3064 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
3067 if (!(lppop = (LPPOPUPMENU)USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu)))
3069 WIN_ReleaseWndPtr(wndPtr);
3073 hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
3074 SelectObject( hdc, hMenuFont);
3075 SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
3076 MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
3077 ReleaseDC( hwnd, hdc );
3078 retvalue = lppop->Height;
3079 WIN_ReleaseWndPtr(wndPtr);
3084 /*******************************************************************
3085 * ChangeMenu16 (USER.153)
3087 BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
3088 UINT16 id, UINT16 flags )
3090 TRACE("menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
3091 hMenu, pos, (DWORD)data, id, flags );
3092 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND,
3095 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
3096 /* for MF_DELETE. We should check the parameters for all others */
3097 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
3099 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
3100 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE,
3102 if (flags & MF_REMOVE) return RemoveMenu16(hMenu,
3103 flags & MF_BYPOSITION ? pos : id,
3104 flags & ~MF_REMOVE );
3105 /* Default: MF_INSERT */
3106 return InsertMenu16( hMenu, pos, flags, id, data );
3110 /*******************************************************************
3111 * ChangeMenu32A (USER32.23)
3113 BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
3114 UINT id, UINT flags )
3116 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3117 hMenu, pos, (DWORD)data, id, flags );
3118 if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
3120 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3121 if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
3123 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
3124 flags & MF_BYPOSITION ? pos : id,
3125 flags & ~MF_REMOVE );
3126 /* Default: MF_INSERT */
3127 return InsertMenuA( hMenu, pos, flags, id, data );
3131 /*******************************************************************
3132 * ChangeMenu32W (USER32.24)
3134 BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
3135 UINT id, UINT flags )
3137 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3138 hMenu, pos, (DWORD)data, id, flags );
3139 if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
3141 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3142 if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
3144 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
3145 flags & MF_BYPOSITION ? pos : id,
3146 flags & ~MF_REMOVE );
3147 /* Default: MF_INSERT */
3148 return InsertMenuW( hMenu, pos, flags, id, data );
3152 /*******************************************************************
3153 * CheckMenuItem16 (USER.154)
3155 BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
3157 return (BOOL16)CheckMenuItem( hMenu, id, flags );
3161 /*******************************************************************
3162 * CheckMenuItem (USER32.46)
3164 DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
3169 TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
3170 if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
3171 ret = item->fState & MF_CHECKED;
3172 if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
3173 else item->fState &= ~MF_CHECKED;
3178 /**********************************************************************
3179 * EnableMenuItem16 (USER.155)
3181 UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
3183 return EnableMenuItem( hMenu, wItemID, wFlags );
3187 /**********************************************************************
3188 * EnableMenuItem32 (USER32.170)
3190 UINT WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
3195 TRACE("(%04x, %04X, %04X) !\n",
3196 hMenu, wItemID, wFlags);
3198 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
3201 oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
3202 item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
3207 /*******************************************************************
3208 * GetMenuString16 (USER.161)
3210 INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
3211 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
3213 return GetMenuStringA( hMenu, wItemID, str, nMaxSiz, wFlags );
3217 /*******************************************************************
3218 * GetMenuString32A (USER32.268)
3220 INT WINAPI GetMenuStringA( HMENU hMenu, UINT wItemID,
3221 LPSTR str, INT nMaxSiz, UINT wFlags )
3225 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3226 hMenu, wItemID, str, nMaxSiz, wFlags );
3227 if (!str || !nMaxSiz) return 0;
3229 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
3230 if (!IS_STRING_ITEM(item->fType)) return 0;
3231 lstrcpynA( str, item->text, nMaxSiz );
3232 TRACE("returning '%s'\n", str );
3237 /*******************************************************************
3238 * GetMenuString32W (USER32.269)
3240 INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
3241 LPWSTR str, INT nMaxSiz, UINT wFlags )
3245 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3246 hMenu, wItemID, str, nMaxSiz, wFlags );
3247 if (!str || !nMaxSiz) return 0;
3249 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
3250 if (!IS_STRING_ITEM(item->fType)) return 0;
3251 lstrcpynAtoW( str, item->text, nMaxSiz );
3252 return lstrlenW(str);
3256 /**********************************************************************
3257 * HiliteMenuItem16 (USER.162)
3259 BOOL16 WINAPI HiliteMenuItem16( HWND16 hWnd, HMENU16 hMenu, UINT16 wItemID,
3262 return HiliteMenuItem( hWnd, hMenu, wItemID, wHilite );
3266 /**********************************************************************
3267 * HiliteMenuItem32 (USER32.318)
3269 BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
3273 TRACE("(%04x, %04x, %04x, %04x);\n",
3274 hWnd, hMenu, wItemID, wHilite);
3275 if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
3276 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
3277 if (menu->FocusedItem == wItemID) return TRUE;
3278 MENU_HideSubPopups( hWnd, hMenu, FALSE );
3279 MENU_SelectItem( hWnd, hMenu, wItemID, TRUE );
3284 /**********************************************************************
3285 * GetMenuState16 (USER.250)
3287 UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
3289 return GetMenuState( hMenu, wItemID, wFlags );
3293 /**********************************************************************
3294 * GetMenuState (USER32.267)
3296 UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
3299 TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
3300 hMenu, wItemID, wFlags);
3301 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
3302 debug_print_menuitem (" item: ", item, "");
3303 if (item->fType & MF_POPUP)
3305 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( item->hSubMenu );
3306 if (!menu) return -1;
3307 else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
3311 /* We used to (from way back then) mask the result to 0xff. */
3312 /* I don't know why and it seems wrong as the documented */
3313 /* return flag MF_SEPARATOR is outside that mask. */
3314 return (item->fType | item->fState);
3319 /**********************************************************************
3320 * GetMenuItemCount16 (USER.263)
3322 INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
3324 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
3325 if (!IS_A_MENU(menu)) return -1;
3326 TRACE("(%04x) returning %d\n",
3327 hMenu, menu->nItems );
3328 return menu->nItems;
3332 /**********************************************************************
3333 * GetMenuItemCount32 (USER32.262)
3335 INT WINAPI GetMenuItemCount( HMENU hMenu )
3337 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
3338 if (!IS_A_MENU(menu)) return -1;
3339 TRACE("(%04x) returning %d\n",
3340 hMenu, menu->nItems );
3341 return menu->nItems;
3344 /**********************************************************************
3345 * GetMenuItemID16 (USER.264)
3347 UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
3349 return (UINT16) GetMenuItemID (hMenu, nPos);
3352 /**********************************************************************
3353 * GetMenuItemID32 (USER32.263)
3355 UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
3359 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3360 if (lpmi->fType & MF_POPUP) return -1;
3365 /*******************************************************************
3366 * InsertMenu16 (USER.410)
3368 BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3369 UINT16 id, SEGPTR data )
3371 UINT pos32 = (UINT)pos;
3372 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
3373 if (IS_STRING_ITEM(flags) && data)
3374 return InsertMenuA( hMenu, pos32, flags, id,
3375 (LPSTR)PTR_SEG_TO_LIN(data) );
3376 return InsertMenuA( hMenu, pos32, flags, id, (LPSTR)data );
3380 /*******************************************************************
3381 * InsertMenu32A (USER32.322)
3383 BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
3384 UINT id, LPCSTR str )
3388 if (IS_STRING_ITEM(flags) && str)
3389 TRACE("hMenu %04x, pos %d, flags %08x, "
3390 "id %04x, str '%s'\n",
3391 hMenu, pos, flags, id, str );
3392 else TRACE("hMenu %04x, pos %d, flags %08x, "
3393 "id %04x, str %08lx (not a string)\n",
3394 hMenu, pos, flags, id, (DWORD)str );
3396 if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
3398 if (!(MENU_SetItemData( item, flags, id, str )))
3400 RemoveMenu( hMenu, pos, flags );
3404 if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
3405 ((POPUPMENU *)USER_HEAP_LIN_ADDR((HMENU16)id))->wFlags |= MF_POPUP;
3407 item->hCheckBit = item->hUnCheckBit = 0;
3412 /*******************************************************************
3413 * InsertMenu32W (USER32.325)
3415 BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
3416 UINT id, LPCWSTR str )
3420 if (IS_STRING_ITEM(flags) && str)
3422 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
3423 ret = InsertMenuA( hMenu, pos, flags, id, newstr );
3424 HeapFree( GetProcessHeap(), 0, newstr );
3427 else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
3431 /*******************************************************************
3432 * AppendMenu16 (USER.411)
3434 BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
3436 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
3440 /*******************************************************************
3441 * AppendMenu32A (USER32.5)
3443 BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
3444 UINT id, LPCSTR data )
3446 return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
3450 /*******************************************************************
3451 * AppendMenu32W (USER32.6)
3453 BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
3454 UINT id, LPCWSTR data )
3456 return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
3460 /**********************************************************************
3461 * RemoveMenu16 (USER.412)
3463 BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
3465 return RemoveMenu( hMenu, nPos, wFlags );
3469 /**********************************************************************
3470 * RemoveMenu (USER32.441)
3472 BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
3477 TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
3478 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
3479 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
3483 MENU_FreeItemData( item );
3485 if (--menu->nItems == 0)
3487 HeapFree( SystemHeap, 0, menu->items );
3492 while(nPos < menu->nItems)
3498 menu->items = HeapReAlloc( SystemHeap, 0, menu->items,
3499 menu->nItems * sizeof(MENUITEM) );
3505 /**********************************************************************
3506 * DeleteMenu16 (USER.413)
3508 BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
3510 return DeleteMenu( hMenu, nPos, wFlags );
3514 /**********************************************************************
3515 * DeleteMenu32 (USER32.129)
3517 BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
3519 MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
3520 if (!item) return FALSE;
3521 if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
3522 /* nPos is now the position of the item */
3523 RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
3528 /*******************************************************************
3529 * ModifyMenu16 (USER.414)
3531 BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3532 UINT16 id, SEGPTR data )
3534 if (IS_STRING_ITEM(flags))
3535 return ModifyMenuA( hMenu, pos, flags, id,
3536 (LPSTR)PTR_SEG_TO_LIN(data) );
3537 return ModifyMenuA( hMenu, pos, flags, id, (LPSTR)data );
3541 /*******************************************************************
3542 * ModifyMenu32A (USER32.397)
3544 BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
3545 UINT id, LPCSTR str )
3549 if (IS_STRING_ITEM(flags))
3551 TRACE("%04x %d %04x %04x '%s'\n",
3552 hMenu, pos, flags, id, str ? str : "#NULL#" );
3553 if (!str) return FALSE;
3557 TRACE("%04x %d %04x %04x %08lx\n",
3558 hMenu, pos, flags, id, (DWORD)str );
3561 if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
3562 return MENU_SetItemData( item, flags, id, str );
3566 /*******************************************************************
3567 * ModifyMenu32W (USER32.398)
3569 BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
3570 UINT id, LPCWSTR str )
3574 if (IS_STRING_ITEM(flags) && str)
3576 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
3577 ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
3578 HeapFree( GetProcessHeap(), 0, newstr );
3581 else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
3585 /**********************************************************************
3586 * CreatePopupMenu16 (USER.415)
3588 HMENU16 WINAPI CreatePopupMenu16(void)
3590 return CreatePopupMenu();
3594 /**********************************************************************
3595 * CreatePopupMenu32 (USER32.82)
3597 HMENU WINAPI CreatePopupMenu(void)
3602 if (!(hmenu = CreateMenu())) return 0;
3603 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
3604 menu->wFlags |= MF_POPUP;
3609 /**********************************************************************
3610 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
3612 DWORD WINAPI GetMenuCheckMarkDimensions(void)
3614 return MAKELONG( check_bitmap_width, check_bitmap_height );
3618 /**********************************************************************
3619 * SetMenuItemBitmaps16 (USER.418)
3621 BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
3622 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
3624 return SetMenuItemBitmaps( hMenu, nPos, wFlags, hNewUnCheck, hNewCheck );
3628 /**********************************************************************
3629 * SetMenuItemBitmaps32 (USER32.490)
3631 BOOL WINAPI SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags,
3632 HBITMAP hNewUnCheck, HBITMAP hNewCheck)
3635 TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
3636 hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
3637 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
3639 if (!hNewCheck && !hNewUnCheck)
3641 item->fState &= ~MF_USECHECKBITMAPS;
3643 else /* Install new bitmaps */
3645 item->hCheckBit = hNewCheck;
3646 item->hUnCheckBit = hNewUnCheck;
3647 item->fState |= MF_USECHECKBITMAPS;
3653 /**********************************************************************
3654 * CreateMenu16 (USER.151)
3656 HMENU16 WINAPI CreateMenu16(void)
3658 return CreateMenu();
3662 /**********************************************************************
3663 * CreateMenu (USER32.81)
3665 HMENU WINAPI CreateMenu(void)
3669 if (!(hMenu = USER_HEAP_ALLOC( sizeof(POPUPMENU) ))) return 0;
3670 menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
3672 ZeroMemory(menu, sizeof(POPUPMENU));
3673 menu->wMagic = MENU_MAGIC;
3674 menu->FocusedItem = NO_SELECTED_ITEM;
3676 TRACE("return %04x\n", hMenu );
3682 /**********************************************************************
3683 * DestroyMenu16 (USER.152)
3685 BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
3687 return DestroyMenu( hMenu );
3691 /**********************************************************************
3692 * DestroyMenu32 (USER32.134)
3694 BOOL WINAPI DestroyMenu( HMENU hMenu )
3696 TRACE("(%04x)\n", hMenu);
3698 /* Silently ignore attempts to destroy default system popup */
3700 if (hMenu && hMenu != MENU_DefSysPopup)
3702 LPPOPUPMENU lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
3703 WND *pTPWnd = MENU_GetTopPopupWnd();
3705 if( pTPWnd && (hMenu == *(HMENU*)pTPWnd->wExtra) )
3706 *(UINT*)pTPWnd->wExtra = 0;
3708 if (IS_A_MENU( lppop ))
3710 lppop->wMagic = 0; /* Mark it as destroyed */
3712 if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
3713 (!pTPWnd || (lppop->hWnd != pTPWnd->hwndSelf)))
3714 DestroyWindow( lppop->hWnd );
3716 if (lppop->items) /* recursively destroy submenus */
3719 MENUITEM *item = lppop->items;
3720 for (i = lppop->nItems; i > 0; i--, item++)
3722 if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
3723 MENU_FreeItemData( item );
3725 HeapFree( SystemHeap, 0, lppop->items );
3727 USER_HEAP_FREE( hMenu );
3728 MENU_ReleaseTopPopupWnd();
3732 MENU_ReleaseTopPopupWnd();
3736 return (hMenu != MENU_DefSysPopup);
3740 /**********************************************************************
3741 * GetSystemMenu16 (USER.156)
3743 HMENU16 WINAPI GetSystemMenu16( HWND16 hWnd, BOOL16 bRevert )
3745 return GetSystemMenu( hWnd, bRevert );
3749 /**********************************************************************
3750 * GetSystemMenu32 (USER32.291)
3752 HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
3754 WND *wndPtr = WIN_FindWndPtr( hWnd );
3758 if( wndPtr->hSysMenu )
3762 DestroyMenu(wndPtr->hSysMenu);
3763 wndPtr->hSysMenu = 0;
3767 POPUPMENU *menu = (POPUPMENU*)
3768 USER_HEAP_LIN_ADDR(wndPtr->hSysMenu);
3769 if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
3770 menu->items[0].hSubMenu = MENU_CopySysPopup();
3774 if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) )
3775 wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
3777 if( wndPtr->hSysMenu )
3779 HMENU retvalue = GetSubMenu16(wndPtr->hSysMenu, 0);
3780 WIN_ReleaseWndPtr(wndPtr);
3783 WIN_ReleaseWndPtr(wndPtr);
3789 /*******************************************************************
3790 * SetSystemMenu16 (USER.280)
3792 BOOL16 WINAPI SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
3794 return SetSystemMenu( hwnd, hMenu );
3798 /*******************************************************************
3799 * SetSystemMenu32 (USER32.508)
3801 BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
3803 WND *wndPtr = WIN_FindWndPtr(hwnd);
3807 if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu );
3808 wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu );
3809 WIN_ReleaseWndPtr(wndPtr);
3816 /**********************************************************************
3817 * GetMenu16 (USER.157)
3819 HMENU16 WINAPI GetMenu16( HWND16 hWnd )
3822 WND * wndPtr = WIN_FindWndPtr(hWnd);
3823 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
3825 retvalue = (HMENU16)wndPtr->wIDmenu;
3830 WIN_ReleaseWndPtr(wndPtr);
3835 /**********************************************************************
3836 * GetMenu32 (USER32.257)
3838 HMENU WINAPI GetMenu( HWND hWnd )
3841 WND * wndPtr = WIN_FindWndPtr(hWnd);
3842 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
3844 retvalue = (HMENU)wndPtr->wIDmenu;
3849 WIN_ReleaseWndPtr(wndPtr);
3854 /**********************************************************************
3855 * SetMenu16 (USER.158)
3857 BOOL16 WINAPI SetMenu16( HWND16 hWnd, HMENU16 hMenu )
3859 return SetMenu( hWnd, hMenu );
3863 /**********************************************************************
3864 * SetMenu32 (USER32.487)
3866 BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
3868 WND * wndPtr = WIN_FindWndPtr(hWnd);
3870 TRACE("(%04x, %04x);\n", hWnd, hMenu);
3872 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
3874 if (GetCapture() == hWnd) ReleaseCapture();
3876 wndPtr->wIDmenu = (UINT)hMenu;
3881 if (!(lpmenu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
3883 WIN_ReleaseWndPtr(wndPtr);
3886 lpmenu->hWnd = hWnd;
3887 lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
3888 lpmenu->Height = 0; /* Make sure we recalculate the size */
3890 if (IsWindowVisible(hWnd))
3891 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
3892 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
3893 WIN_ReleaseWndPtr(wndPtr);
3896 WIN_ReleaseWndPtr(wndPtr);
3902 /**********************************************************************
3903 * GetSubMenu16 (USER.159)
3905 HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
3907 return GetSubMenu( hMenu, nPos );
3911 /**********************************************************************
3912 * GetSubMenu32 (USER32.288)
3914 HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
3918 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3919 if (!(lpmi->fType & MF_POPUP)) return 0;
3920 return lpmi->hSubMenu;
3924 /**********************************************************************
3925 * DrawMenuBar16 (USER.160)
3927 void WINAPI DrawMenuBar16( HWND16 hWnd )
3929 DrawMenuBar( hWnd );
3933 /**********************************************************************
3934 * DrawMenuBar (USER32.161)
3936 BOOL WINAPI DrawMenuBar( HWND hWnd )
3939 WND *wndPtr = WIN_FindWndPtr(hWnd);
3940 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && wndPtr->wIDmenu)
3942 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu);
3945 WIN_ReleaseWndPtr(wndPtr);
3949 lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
3950 lppop->hwndOwner = hWnd;
3951 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
3952 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
3953 WIN_ReleaseWndPtr(wndPtr);
3956 WIN_ReleaseWndPtr(wndPtr);
3961 /***********************************************************************
3962 * EndMenu (USER.187) (USER32.175)
3964 void WINAPI EndMenu(void)
3967 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
3974 /***********************************************************************
3975 * LookupMenuHandle (USER.217)
3977 HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
3979 HMENU hmenu32 = hmenu;
3981 if (!MENU_FindItem( &hmenu32, &id32, MF_BYCOMMAND )) return 0;
3982 else return hmenu32;
3986 /**********************************************************************
3987 * LoadMenu16 (USER.150)
3989 HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, SEGPTR name )
3997 char *str = (char *)PTR_SEG_TO_LIN( name );
3998 TRACE("(%04x,'%s')\n", instance, str );
3999 if (str[0] == '#') name = (SEGPTR)atoi( str + 1 );
4002 TRACE("(%04x,%04x)\n",instance,LOWORD(name));
4004 if (!name) return 0;
4006 /* check for Win32 module */
4007 if (HIWORD(instance))
4008 return LoadMenuA(instance,PTR_SEG_TO_LIN(name));
4009 instance = GetExePtr( instance );
4011 if (!(hRsrc = FindResource16( instance, name, RT_MENU16 ))) return 0;
4012 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
4013 hMenu = LoadMenuIndirect16(LockResource16(handle));
4014 FreeResource16( handle );
4019 /*****************************************************************
4020 * LoadMenu32A (USER32.370)
4022 HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
4024 HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
4025 if (!hrsrc) return 0;
4026 return LoadMenuIndirectA( (LPCVOID)LoadResource( instance, hrsrc ));
4030 /*****************************************************************
4031 * LoadMenu32W (USER32.373)
4033 HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
4035 HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
4036 if (!hrsrc) return 0;
4037 return LoadMenuIndirectW( (LPCVOID)LoadResource( instance, hrsrc ));
4041 /**********************************************************************
4042 * LoadMenuIndirect16 (USER.220)
4044 HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
4047 WORD version, offset;
4048 LPCSTR p = (LPCSTR)template;
4050 TRACE("(%p)\n", template );
4051 version = GET_WORD(p);
4055 WARN("version must be 0 for Win16\n" );
4058 offset = GET_WORD(p);
4059 p += sizeof(WORD) + offset;
4060 if (!(hMenu = CreateMenu())) return 0;
4061 if (!MENU_ParseResource( p, hMenu, FALSE ))
4063 DestroyMenu( hMenu );
4070 /**********************************************************************
4071 * LoadMenuIndirect32A (USER32.371)
4073 HMENU WINAPI LoadMenuIndirectA( LPCVOID template )
4076 WORD version, offset;
4077 LPCSTR p = (LPCSTR)template;
4079 TRACE("%p\n", template );
4080 version = GET_WORD(p);
4085 offset = GET_WORD(p);
4086 p += sizeof(WORD) + offset;
4087 if (!(hMenu = CreateMenu())) return 0;
4088 if (!MENU_ParseResource( p, hMenu, TRUE ))
4090 DestroyMenu( hMenu );
4095 offset = GET_WORD(p);
4096 p += sizeof(WORD) + offset;
4097 if (!(hMenu = CreateMenu())) return 0;
4098 if (!MENUEX_ParseResource( p, hMenu))
4100 DestroyMenu( hMenu );
4105 ERR("version %d not supported.\n", version);
4111 /**********************************************************************
4112 * LoadMenuIndirect32W (USER32.372)
4114 HMENU WINAPI LoadMenuIndirectW( LPCVOID template )
4116 /* FIXME: is there anything different between A and W? */
4117 return LoadMenuIndirectA( template );
4121 /**********************************************************************
4122 * IsMenu16 (USER.358)
4124 BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
4126 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4127 return IS_A_MENU(menu);
4131 /**********************************************************************
4132 * IsMenu32 (USER32.346)
4134 BOOL WINAPI IsMenu(HMENU hmenu)
4136 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4137 return IS_A_MENU(menu);
4140 /**********************************************************************
4141 * GetMenuItemInfo32_common
4144 static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
4145 LPMENUITEMINFOA lpmii, BOOL unicode)
4147 MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
4149 debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
4154 if (lpmii->fMask & MIIM_TYPE) {
4155 lpmii->fType = menu->fType;
4156 switch (MENU_ITEM_TYPE(menu->fType)) {
4158 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
4160 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4161 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4163 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4164 lpmii->cch = lstrlenA(menu->text);
4170 lpmii->dwTypeData = menu->text;
4177 if (lpmii->fMask & MIIM_STRING) {
4179 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4180 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4182 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4183 lpmii->cch = lstrlenA(menu->text);
4187 if (lpmii->fMask & MIIM_FTYPE)
4188 lpmii->fType = menu->fType;
4190 if (lpmii->fMask & MIIM_BITMAP)
4191 lpmii->hbmpItem = menu->hbmpItem;
4193 if (lpmii->fMask & MIIM_STATE)
4194 lpmii->fState = menu->fState;
4196 if (lpmii->fMask & MIIM_ID)
4197 lpmii->wID = menu->wID;
4199 if (lpmii->fMask & MIIM_SUBMENU)
4200 lpmii->hSubMenu = menu->hSubMenu;
4202 if (lpmii->fMask & MIIM_CHECKMARKS) {
4203 lpmii->hbmpChecked = menu->hCheckBit;
4204 lpmii->hbmpUnchecked = menu->hUnCheckBit;
4206 if (lpmii->fMask & MIIM_DATA)
4207 lpmii->dwItemData = menu->dwItemData;
4212 /**********************************************************************
4213 * GetMenuItemInfoA (USER32.264)
4215 BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
4216 LPMENUITEMINFOA lpmii)
4218 return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
4221 /**********************************************************************
4222 * GetMenuItemInfoW (USER32.265)
4224 BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
4225 LPMENUITEMINFOW lpmii)
4227 return GetMenuItemInfo_common (hmenu, item, bypos,
4228 (LPMENUITEMINFOA)lpmii, TRUE);
4231 /**********************************************************************
4232 * SetMenuItemInfo32_common
4235 static BOOL SetMenuItemInfo_common(MENUITEM * menu,
4236 const MENUITEMINFOA *lpmii,
4239 if (!menu) return FALSE;
4241 if (lpmii->fMask & MIIM_TYPE ) {
4242 /* Get rid of old string. */
4243 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4244 HeapFree(SystemHeap, 0, menu->text);
4248 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4249 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4250 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4252 menu->text = lpmii->dwTypeData;
4254 if (IS_STRING_ITEM(menu->fType) && menu->text) {
4256 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4258 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
4262 if (lpmii->fMask & MIIM_FTYPE ) {
4263 /* free the string when the type is changing */
4264 if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
4265 HeapFree(SystemHeap, 0, menu->text);
4268 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4269 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4272 if (lpmii->fMask & MIIM_STRING ) {
4273 /* free the string when used */
4274 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4275 HeapFree(SystemHeap, 0, menu->text);
4277 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4279 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
4283 if (lpmii->fMask & MIIM_STATE)
4285 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
4286 menu->fState = lpmii->fState;
4289 if (lpmii->fMask & MIIM_ID)
4290 menu->wID = lpmii->wID;
4292 if (lpmii->fMask & MIIM_SUBMENU) {
4293 menu->hSubMenu = lpmii->hSubMenu;
4294 if (menu->hSubMenu) {
4295 POPUPMENU *subMenu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)menu->hSubMenu);
4296 if (IS_A_MENU(subMenu)) {
4297 subMenu->wFlags |= MF_POPUP;
4298 menu->fType |= MF_POPUP;
4301 /* FIXME: Return an error ? */
4302 menu->fType &= ~MF_POPUP;
4305 menu->fType &= ~MF_POPUP;
4308 if (lpmii->fMask & MIIM_CHECKMARKS)
4310 menu->hCheckBit = lpmii->hbmpChecked;
4311 menu->hUnCheckBit = lpmii->hbmpUnchecked;
4313 if (lpmii->fMask & MIIM_DATA)
4314 menu->dwItemData = lpmii->dwItemData;
4316 debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
4320 /**********************************************************************
4321 * SetMenuItemInfo32A (USER32.491)
4323 BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
4324 const MENUITEMINFOA *lpmii)
4326 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4330 /**********************************************************************
4331 * SetMenuItemInfo32W (USER32.492)
4333 BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
4334 const MENUITEMINFOW *lpmii)
4336 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4337 (const MENUITEMINFOA*)lpmii, TRUE);
4340 /**********************************************************************
4341 * SetMenuDefaultItem (USER32.489)
4344 BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
4350 TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
4352 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return FALSE;
4354 /* reset all default-item flags */
4356 for (i = 0; i < menu->nItems; i++, item++)
4358 item->fState &= ~MFS_DEFAULT;
4361 /* no default item */
4370 if ( uItem >= menu->nItems ) return FALSE;
4371 item[uItem].fState |= MFS_DEFAULT;
4376 for (i = 0; i < menu->nItems; i++, item++)
4378 if (item->wID == uItem)
4380 item->fState |= MFS_DEFAULT;
4389 /**********************************************************************
4390 * GetMenuDefaultItem (USER32.260)
4392 UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
4398 TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
4400 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return -1;
4402 /* find default item */
4406 if (! item) return -1;
4408 while ( !( item->fState & MFS_DEFAULT ) )
4411 if (i >= menu->nItems ) return -1;
4414 /* default: don't return disabled items */
4415 if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
4417 /* search rekursiv when needed */
4418 if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
4421 ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
4422 if ( -1 != ret ) return ret;
4424 /* when item not found in submenu, return the popup item */
4426 return ( bypos ) ? i : item->wID;
4430 /*******************************************************************
4431 * InsertMenuItem16 (USER.441)
4435 BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
4436 const MENUITEMINFO16 *mii )
4440 miia.cbSize = sizeof(miia);
4441 miia.fMask = mii->fMask;
4442 miia.dwTypeData = mii->dwTypeData;
4443 miia.fType = mii->fType;
4444 miia.fState = mii->fState;
4445 miia.wID = mii->wID;
4446 miia.hSubMenu = mii->hSubMenu;
4447 miia.hbmpChecked = mii->hbmpChecked;
4448 miia.hbmpUnchecked = mii->hbmpUnchecked;
4449 miia.dwItemData = mii->dwItemData;
4450 miia.cch = mii->cch;
4451 if (IS_STRING_ITEM(miia.fType))
4452 miia.dwTypeData = PTR_SEG_TO_LIN(miia.dwTypeData);
4453 return InsertMenuItemA( hmenu, pos, byposition, &miia );
4457 /**********************************************************************
4458 * InsertMenuItem32A (USER32.323)
4460 BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
4461 const MENUITEMINFOA *lpmii)
4463 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
4464 return SetMenuItemInfo_common(item, lpmii, FALSE);
4468 /**********************************************************************
4469 * InsertMenuItem32W (USER32.324)
4471 BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
4472 const MENUITEMINFOW *lpmii)
4474 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
4475 return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
4478 /**********************************************************************
4479 * CheckMenuRadioItem32 (USER32.47)
4482 BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
4483 UINT first, UINT last, UINT check,
4486 MENUITEM *mifirst, *milast, *micheck;
4487 HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
4489 TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
4490 hMenu, first, last, check, bypos);
4492 mifirst = MENU_FindItem (&mfirst, &first, bypos);
4493 milast = MENU_FindItem (&mlast, &last, bypos);
4494 micheck = MENU_FindItem (&mcheck, &check, bypos);
4496 if (mifirst == NULL || milast == NULL || micheck == NULL ||
4497 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
4498 micheck > milast || micheck < mifirst)
4501 while (mifirst <= milast)
4503 if (mifirst == micheck)
4505 mifirst->fType |= MFT_RADIOCHECK;
4506 mifirst->fState |= MFS_CHECKED;
4508 mifirst->fType &= ~MFT_RADIOCHECK;
4509 mifirst->fState &= ~MFS_CHECKED;
4517 /**********************************************************************
4518 * CheckMenuRadioItem16 (not a Windows API)
4521 BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu,
4522 UINT16 first, UINT16 last, UINT16 check,
4525 return CheckMenuRadioItem (hMenu, first, last, check, bypos);
4528 /**********************************************************************
4529 * GetMenuItemRect32 (USER32.266)
4531 * ATTENTION: Here, the returned values in rect are the screen
4532 * coordinates of the item just like if the menu was
4533 * always on the upper left side of the application.
4536 BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
4539 POPUPMENU *itemMenu;
4543 TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
4545 item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
4546 referenceHwnd = hwnd;
4550 itemMenu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
4551 if (itemMenu == NULL)
4554 if(itemMenu->hWnd == 0)
4556 referenceHwnd = itemMenu->hWnd;
4559 if ((rect == NULL) || (item == NULL))
4564 MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
4569 /**********************************************************************
4570 * GetMenuItemRect16 (USER.665)
4573 BOOL16 WINAPI GetMenuItemRect16 (HWND16 hwnd, HMENU16 hMenu, UINT16 uItem,
4579 if (!rect) return FALSE;
4580 res = GetMenuItemRect (hwnd, hMenu, uItem, &r32);
4581 CONV_RECT32TO16 (&r32, rect);
4585 /**********************************************************************
4589 * MIM_APPLYTOSUBMENUS
4590 * actually use the items to draw the menu
4592 BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
4596 TRACE("(0x%04x %p)\n", hMenu, lpmi);
4598 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)USER_HEAP_LIN_ADDR(hMenu)))
4601 if (lpmi->fMask & MIM_BACKGROUND)
4602 menu->hbrBack = lpmi->hbrBack;
4604 if (lpmi->fMask & MIM_HELPID)
4605 menu->dwContextHelpID = lpmi->dwContextHelpID;
4607 if (lpmi->fMask & MIM_MAXHEIGHT)
4608 menu->cyMax = lpmi->cyMax;
4610 if (lpmi->fMask & MIM_MENUDATA)
4611 menu->dwMenuData = lpmi->dwMenuData;
4613 if (lpmi->fMask & MIM_STYLE)
4614 menu->dwStyle = lpmi->dwStyle;
4621 /**********************************************************************
4628 BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
4631 TRACE("(0x%04x %p)\n", hMenu, lpmi);
4633 if (lpmi && (menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4636 if (lpmi->fMask & MIM_BACKGROUND)
4637 lpmi->hbrBack = menu->hbrBack;
4639 if (lpmi->fMask & MIM_HELPID)
4640 lpmi->dwContextHelpID = menu->dwContextHelpID;
4642 if (lpmi->fMask & MIM_MAXHEIGHT)
4643 lpmi->cyMax = menu->cyMax;
4645 if (lpmi->fMask & MIM_MENUDATA)
4646 lpmi->dwMenuData = menu->dwMenuData;
4648 if (lpmi->fMask & MIM_STYLE)
4649 lpmi->dwStyle = menu->dwStyle;
4656 /**********************************************************************
4657 * SetMenuContextHelpId16 (USER.384)
4659 BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
4661 return SetMenuContextHelpId( hMenu, dwContextHelpID );
4665 /**********************************************************************
4666 * SetMenuContextHelpId (USER32.488)
4668 BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
4672 TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
4674 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4676 menu->dwContextHelpID = dwContextHelpID;
4682 /**********************************************************************
4683 * GetMenuContextHelpId16 (USER.385)
4685 DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
4687 return GetMenuContextHelpId( hMenu );
4690 /**********************************************************************
4691 * GetMenuContextHelpId (USER32.488)
4693 DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
4697 TRACE("(0x%04x)\n", hMenu);
4699 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4701 return menu->dwContextHelpID;