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 BOOL bTimeToHide
; /* Request hiding when receiving a second click in the top-level menu item */
73 /* ------------ MENUINFO members ------ */
74 DWORD dwStyle
; /* Extended mennu style */
75 UINT cyMax
; /* max hight of the whole menu, 0 is screen hight */
76 HBRUSH hbrBack
; /* brush for menu background */
77 DWORD dwContextHelpID
;
78 DWORD dwMenuData
; /* application defined value */
79 HMENU hSysMenuOwner
; /* Handle to the dummy sys menu holder */
80 } POPUPMENU
, *LPPOPUPMENU
;
82 /* internal flags for menu tracking */
84 #define TF_ENDMENU 0x0001
85 #define TF_SUSPENDPOPUP 0x0002
86 #define TF_SKIPREMOVE 0x0004
91 HMENU hCurrentMenu
; /* current submenu (can be equal to hTopMenu)*/
92 HMENU hTopMenu
; /* initial menu */
93 HWND hOwnerWnd
; /* where notifications are sent */
97 #define MENU_MAGIC 0x554d /* 'MU' */
98 #define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
103 /* Internal MENU_TrackMenu() flags */
104 #define TPM_INTERNAL 0xF0000000
105 #define TPM_ENTERIDLEEX 0x80000000 /* set owner window for WM_ENTERIDLE */
106 #define TPM_BUTTONDOWN 0x40000000 /* menu was clicked before tracking */
107 #define TPM_POPUPMENU 0x20000000 /* menu is a popup menu */
109 /* popup menu shade thickness */
110 #define POPUP_XSHADE 4
111 #define POPUP_YSHADE 4
113 /* Space between 2 menu bar items */
114 #define MENU_BAR_ITEMS_SPACE 12
116 /* Minimum width of a tab character */
117 #define MENU_TAB_SPACE 8
119 /* Height of a separator item */
120 #define SEPARATOR_HEIGHT 5
122 /* (other menu->FocusedItem values give the position of the focused item) */
123 #define NO_SELECTED_ITEM 0xffff
125 #define MENU_ITEM_TYPE(flags) \
126 ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
128 #define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
129 #define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
131 #define IS_SYSTEM_MENU(menu) \
132 (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
134 #define IS_SYSTEM_POPUP(menu) \
135 ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
137 #define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
138 MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
139 MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
140 MF_POPUP | MF_SYSMENU | MF_HELP)
141 #define STATE_MASK (~TYPE_MASK)
143 /* Dimension of the menu bitmaps */
144 static WORD check_bitmap_width
= 0, check_bitmap_height
= 0;
145 static WORD arrow_bitmap_width
= 0, arrow_bitmap_height
= 0;
147 static HBITMAP hStdRadioCheck
= 0;
148 static HBITMAP hStdCheck
= 0;
149 static HBITMAP hStdMnArrow
= 0;
151 /* Minimze/restore/close buttons to be inserted in menubar */
152 static HBITMAP hBmpMinimize
= 0;
153 static HBITMAP hBmpMinimizeD
= 0;
154 static HBITMAP hBmpMaximize
= 0;
155 static HBITMAP hBmpMaximizeD
= 0;
156 static HBITMAP hBmpClose
= 0;
157 static HBITMAP hBmpCloseD
= 0;
160 static HBRUSH hShadeBrush
= 0;
161 static HFONT hMenuFont
= 0;
162 static HFONT hMenuFontBold
= 0;
164 static HMENU MENU_DefSysPopup
= 0; /* Default system menu popup */
166 /* Use global popup window because there's no way 2 menus can
167 * be tracked at the same time. */
169 static WND
* pTopPopupWnd
= 0;
170 static UINT uSubPWndLevel
= 0;
172 /* Flag set by EndMenu() to force an exit from menu tracking */
173 static BOOL fEndMenu
= FALSE
;
176 /***********************************************************************
177 * debug_print_menuitem
179 * Print a menuitem in readable form.
182 #define debug_print_menuitem(pre, mp, post) \
183 if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
185 #define MENUOUT(text) \
186 DPRINTF("%s%s", (count++ ? "," : ""), (text))
188 #define MENUFLAG(bit,text) \
190 if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
193 static void do_debug_print_menuitem(const char *prefix
, MENUITEM
* mp
,
196 TRACE("%s ", prefix
);
198 UINT flags
= mp
->fType
;
199 int typ
= MENU_ITEM_TYPE(flags
);
200 DPRINTF( "{ ID=0x%x", mp
->wID
);
201 if (flags
& MF_POPUP
)
202 DPRINTF( ", Sub=0x%x", mp
->hSubMenu
);
206 if (typ
== MFT_STRING
)
208 else if (typ
== MFT_SEPARATOR
)
210 else if (typ
== MFT_OWNERDRAW
)
212 else if (typ
== MFT_BITMAP
)
218 MENUFLAG(MF_POPUP
, "pop");
219 MENUFLAG(MFT_MENUBARBREAK
, "barbrk");
220 MENUFLAG(MFT_MENUBREAK
, "brk");
221 MENUFLAG(MFT_RADIOCHECK
, "radio");
222 MENUFLAG(MFT_RIGHTORDER
, "rorder");
223 MENUFLAG(MF_SYSMENU
, "sys");
224 MENUFLAG(MFT_RIGHTJUSTIFY
, "right"); /* same as MF_HELP */
227 DPRINTF( "+0x%x", flags
);
232 DPRINTF( ", State=");
233 MENUFLAG(MFS_GRAYED
, "grey");
234 MENUFLAG(MFS_DEFAULT
, "default");
235 MENUFLAG(MFS_DISABLED
, "dis");
236 MENUFLAG(MFS_CHECKED
, "check");
237 MENUFLAG(MFS_HILITE
, "hi");
238 MENUFLAG(MF_USECHECKBITMAPS
, "usebit");
239 MENUFLAG(MF_MOUSESELECT
, "mouse");
241 DPRINTF( "+0x%x", flags
);
244 DPRINTF( ", Chk=0x%x", mp
->hCheckBit
);
246 DPRINTF( ", Unc=0x%x", mp
->hUnCheckBit
);
248 if (typ
== MFT_STRING
) {
250 DPRINTF( ", Text=\"%s\"", mp
->text
);
252 DPRINTF( ", Text=Null");
253 } else if (mp
->text
== NULL
)
256 DPRINTF( ", Text=%p", mp
->text
);
258 DPRINTF( ", ItemData=0x%08lx", mp
->dwItemData
);
264 DPRINTF(" %s\n", postfix
);
270 /***********************************************************************
273 * Return the default system menu.
275 static HMENU
MENU_CopySysPopup(void)
277 HMENU hMenu
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
280 POPUPMENU
* menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
);
281 menu
->wFlags
|= MF_SYSMENU
| MF_POPUP
;
282 SetMenuDefaultItem(hMenu
, SC_CLOSE
, FALSE
);
286 ERR("Unable to load default system menu\n" );
289 TRACE("returning %x.\n", hMenu
);
294 /***********************************************************************
295 * MENU_GetTopPopupWnd()
297 * Return the locked pointer pTopPopupWnd.
299 static WND
*MENU_GetTopPopupWnd()
301 return WIN_LockWndPtr(pTopPopupWnd
);
303 /***********************************************************************
304 * MENU_ReleaseTopPopupWnd()
306 * Realease the locked pointer pTopPopupWnd.
308 static void MENU_ReleaseTopPopupWnd()
310 WIN_ReleaseWndPtr(pTopPopupWnd
);
312 /***********************************************************************
313 * MENU_DestroyTopPopupWnd()
315 * Destroy the locked pointer pTopPopupWnd.
317 static void MENU_DestroyTopPopupWnd()
319 WND
*tmpWnd
= pTopPopupWnd
;
321 WIN_ReleaseWndPtr(tmpWnd
);
326 /**********************************************************************
329 * Create a copy of the system menu. System menu in Windows is
330 * a special menu-bar with the single entry - system menu popup.
331 * This popup is presented to the outside world as a "system menu".
332 * However, the real system menu handle is sometimes seen in the
333 * WM_MENUSELECT paramemters (and Word 6 likes it this way).
335 HMENU
MENU_GetSysMenu( HWND hWnd
, HMENU hPopupMenu
)
339 if ((hMenu
= CreateMenu()))
341 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
);
342 menu
->wFlags
= MF_SYSMENU
;
345 if (hPopupMenu
== (HMENU
)(-1))
346 hPopupMenu
= MENU_CopySysPopup();
347 else if( !hPopupMenu
) hPopupMenu
= MENU_DefSysPopup
;
351 InsertMenuA( hMenu
, -1, MF_SYSMENU
| MF_POPUP
| MF_BYPOSITION
, hPopupMenu
, NULL
);
353 menu
->items
[0].fType
= MF_SYSMENU
| MF_POPUP
;
354 menu
->items
[0].fState
= 0;
355 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hPopupMenu
);
356 menu
->wFlags
|= MF_SYSMENU
;
358 TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu
, hPopupMenu
);
361 DestroyMenu( hMenu
);
363 ERR("failed to load system menu!\n");
368 /***********************************************************************
371 * Menus initialisation.
376 NONCLIENTMETRICSA ncm
;
378 static unsigned char shade_bits
[16] = { 0x55, 0, 0xAA, 0,
383 /* Load menu bitmaps */
384 hStdCheck
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK
));
385 hStdRadioCheck
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK
));
386 hStdMnArrow
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW
));
387 /* Load system buttons bitmaps */
388 hBmpMinimize
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE
));
389 hBmpMinimizeD
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED
));
390 hBmpMaximize
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE
));
391 hBmpMaximizeD
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED
));
392 hBmpClose
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE
));
393 hBmpCloseD
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED
));
398 GetObjectA( hStdCheck
, sizeof(bm
), &bm
);
399 check_bitmap_width
= bm
.bmWidth
;
400 check_bitmap_height
= bm
.bmHeight
;
404 /* Assume that radio checks have the same size as regular check. */
411 GetObjectA( hStdMnArrow
, sizeof(bm
), &bm
);
412 arrow_bitmap_width
= bm
.bmWidth
;
413 arrow_bitmap_height
= bm
.bmHeight
;
417 if (! (hBitmap
= CreateBitmap( 8, 8, 1, 1, shade_bits
)))
420 if(!(hShadeBrush
= CreatePatternBrush( hBitmap
)))
423 DeleteObject( hBitmap
);
424 if (!(MENU_DefSysPopup
= MENU_CopySysPopup()))
427 ncm
.cbSize
= sizeof (NONCLIENTMETRICSA
);
428 if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICSA
), &ncm
, 0)))
431 if (!(hMenuFont
= CreateFontIndirectA( &ncm
.lfMenuFont
)))
434 ncm
.lfMenuFont
.lfWeight
+= 300;
435 if ( ncm
.lfMenuFont
.lfWeight
> 1000)
436 ncm
.lfMenuFont
.lfWeight
= 1000;
438 if (!(hMenuFontBold
= CreateFontIndirectA( &ncm
.lfMenuFont
)))
444 /***********************************************************************
445 * MENU_InitSysMenuPopup
447 * Grey the appropriate items in System menu.
449 static void MENU_InitSysMenuPopup( HMENU hmenu
, DWORD style
, DWORD clsStyle
)
453 gray
= !(style
& WS_THICKFRAME
) || (style
& (WS_MAXIMIZE
| WS_MINIMIZE
));
454 EnableMenuItem( hmenu
, SC_SIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
455 gray
= ((style
& WS_MAXIMIZE
) != 0);
456 EnableMenuItem( hmenu
, SC_MOVE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
457 gray
= !(style
& WS_MINIMIZEBOX
) || (style
& WS_MINIMIZE
);
458 EnableMenuItem( hmenu
, SC_MINIMIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
459 gray
= !(style
& WS_MAXIMIZEBOX
) || (style
& WS_MAXIMIZE
);
460 EnableMenuItem( hmenu
, SC_MAXIMIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
461 gray
= !(style
& (WS_MAXIMIZE
| WS_MINIMIZE
));
462 EnableMenuItem( hmenu
, SC_RESTORE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
463 gray
= (clsStyle
& CS_NOCLOSE
) != 0;
465 /* The menu item must keep its state if it's disabled */
467 EnableMenuItem( hmenu
, SC_CLOSE
, MF_GRAYED
);
471 /******************************************************************************
473 * UINT32 MENU_GetStartOfNextColumn(
476 *****************************************************************************/
478 static UINT
MENU_GetStartOfNextColumn(
481 POPUPMENU
*menu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR(hMenu
);
482 UINT i
= menu
->FocusedItem
+ 1;
485 return NO_SELECTED_ITEM
;
487 if( i
== NO_SELECTED_ITEM
)
490 for( ; i
< menu
->nItems
; ++i
) {
491 if (menu
->items
[i
].fType
& MF_MENUBARBREAK
)
495 return NO_SELECTED_ITEM
;
499 /******************************************************************************
501 * UINT32 MENU_GetStartOfPrevColumn(
504 *****************************************************************************/
506 static UINT
MENU_GetStartOfPrevColumn(
509 POPUPMENU
const *menu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR(hMenu
);
513 return NO_SELECTED_ITEM
;
515 if( menu
->FocusedItem
== 0 || menu
->FocusedItem
== NO_SELECTED_ITEM
)
516 return NO_SELECTED_ITEM
;
518 /* Find the start of the column */
520 for(i
= menu
->FocusedItem
; i
!= 0 &&
521 !(menu
->items
[i
].fType
& MF_MENUBARBREAK
);
525 return NO_SELECTED_ITEM
;
527 for(--i
; i
!= 0; --i
) {
528 if (menu
->items
[i
].fType
& MF_MENUBARBREAK
)
532 TRACE("ret %d.\n", i
);
539 /***********************************************************************
542 * Find a menu item. Return a pointer on the item, and modifies *hmenu
543 * in case the item was in a sub-menu.
545 static MENUITEM
*MENU_FindItem( HMENU
*hmenu
, UINT
*nPos
, UINT wFlags
)
550 if (((*hmenu
)==0xffff) || (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(*hmenu
)))) return NULL
;
551 if (wFlags
& MF_BYPOSITION
)
553 if (*nPos
>= menu
->nItems
) return NULL
;
554 return &menu
->items
[*nPos
];
558 MENUITEM
*item
= menu
->items
;
559 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
561 if (item
->wID
== *nPos
)
566 else if (item
->fType
& MF_POPUP
)
568 HMENU hsubmenu
= item
->hSubMenu
;
569 MENUITEM
*subitem
= MENU_FindItem( &hsubmenu
, nPos
, wFlags
);
581 /***********************************************************************
584 * Find a Sub menu. Return the position of the submenu, and modifies
585 * *hmenu in case it is found in another sub-menu.
586 * If the submenu cannot be found, NO_SELECTED_ITEM is returned.
588 UINT
MENU_FindSubMenu( HMENU
*hmenu
, HMENU hSubTarget
)
593 if (((*hmenu
)==0xffff) ||
594 (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(*hmenu
))))
595 return NO_SELECTED_ITEM
;
597 for (i
= 0; i
< menu
->nItems
; i
++, item
++) {
598 if(!(item
->fType
& MF_POPUP
)) continue;
599 if (item
->hSubMenu
== hSubTarget
) {
603 HMENU hsubmenu
= item
->hSubMenu
;
604 UINT pos
= MENU_FindSubMenu( &hsubmenu
, hSubTarget
);
605 if (pos
!= NO_SELECTED_ITEM
) {
611 return NO_SELECTED_ITEM
;
614 /***********************************************************************
617 static void MENU_FreeItemData( MENUITEM
* item
)
620 if (IS_STRING_ITEM(item
->fType
) && item
->text
)
621 HeapFree( SystemHeap
, 0, item
->text
);
624 /***********************************************************************
625 * MENU_FindItemByCoords
627 * Find the item at the specified coordinates (screen coords). Does
628 * not work for child windows and therefore should not be called for
629 * an arbitrary system menu.
631 static MENUITEM
*MENU_FindItemByCoords( POPUPMENU
*menu
,
632 POINT pt
, UINT
*pos
)
638 if (!GetWindowRect(menu
->hWnd
,&wrect
)) return NULL
;
639 pt
.x
-= wrect
.left
;pt
.y
-= wrect
.top
;
641 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
643 if ((pt
.x
>= item
->rect
.left
) && (pt
.x
< item
->rect
.right
) &&
644 (pt
.y
>= item
->rect
.top
) && (pt
.y
< item
->rect
.bottom
))
654 /***********************************************************************
657 * Find the menu item selected by a key press.
658 * Return item id, -1 if none, -2 if we should close the menu.
660 static UINT
MENU_FindItemByKey( HWND hwndOwner
, HMENU hmenu
,
661 UINT key
, BOOL forceMenuChar
)
663 TRACE("\tlooking for '%c' in [%04x]\n", (char)key
, (UINT16
)hmenu
);
665 if (!IsMenu( hmenu
))
667 WND
* w
= WIN_FindWndPtr(hwndOwner
);
668 hmenu
= GetSubMenu(w
->hSysMenu
, 0);
669 WIN_ReleaseWndPtr(w
);
674 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
675 MENUITEM
*item
= menu
->items
;
683 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
685 if (item
->text
&& (IS_STRING_ITEM(item
->fType
)))
687 char *p
= item
->text
- 2;
690 p
= strchr (p
+ 2, '&');
692 while (p
!= NULL
&& p
[1] == '&');
693 if (p
&& (toupper(p
[1]) == key
)) return i
;
697 menuchar
= SendMessageA( hwndOwner
, WM_MENUCHAR
,
698 MAKEWPARAM( key
, menu
->wFlags
), hmenu
);
699 if (HIWORD(menuchar
) == 2) return LOWORD(menuchar
);
700 if (HIWORD(menuchar
) == 1) return (UINT
)(-2);
704 /***********************************************************************
707 * Load the bitmap associated with the magic menu item and its style
710 static HBITMAP
MENU_LoadMagicItem(UINT id
, BOOL hilite
, DWORD dwItemData
)
713 * Magic menu item id's section
714 * These magic id's are used by windows to insert "standard" mdi
715 * buttons (minimize,restore,close) on menu. Under windows,
716 * these magic id's make sure the right things appear when those
717 * bitmap buttons are pressed/selected/released.
721 { case HBMMENU_SYSTEM
:
722 return (dwItemData
) ?
723 (HBITMAP
)dwItemData
:
724 (hilite
? hBmpMinimizeD
: hBmpMinimize
);
725 case HBMMENU_MBAR_RESTORE
:
726 return (hilite
? hBmpMaximizeD
: hBmpMaximize
);
727 case HBMMENU_MBAR_MINIMIZE
:
728 return (hilite
? hBmpMinimizeD
: hBmpMinimize
);
729 case HBMMENU_MBAR_CLOSE
:
730 return (hilite
? hBmpCloseD
: hBmpClose
);
731 case HBMMENU_CALLBACK
:
732 case HBMMENU_MBAR_CLOSE_D
:
733 case HBMMENU_MBAR_MINIMIZE_D
:
734 case HBMMENU_POPUP_CLOSE
:
735 case HBMMENU_POPUP_RESTORE
:
736 case HBMMENU_POPUP_MAXIMIZE
:
737 case HBMMENU_POPUP_MINIMIZE
:
739 FIXME("Magic 0x%08x not implemented\n", id
);
745 /***********************************************************************
748 * Calculate the size of the menu item and store it in lpitem->rect.
750 static void MENU_CalcItemSize( HDC hdc
, MENUITEM
*lpitem
, HWND hwndOwner
,
751 INT orgX
, INT orgY
, BOOL menuBar
)
755 TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc
, hwndOwner
, orgX
, orgY
);
756 debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem
,
757 (menuBar
? " (MenuBar)" : ""));
759 SetRect( &lpitem
->rect
, orgX
, orgY
, orgX
, orgY
);
761 if (lpitem
->fType
& MF_OWNERDRAW
)
763 MEASUREITEMSTRUCT mis
;
764 mis
.CtlType
= ODT_MENU
;
766 mis
.itemID
= lpitem
->wID
;
767 mis
.itemData
= (DWORD
)lpitem
->dwItemData
;
770 SendMessageA( hwndOwner
, WM_MEASUREITEM
, 0, (LPARAM
)&mis
);
771 lpitem
->rect
.bottom
+= mis
.itemHeight
;
772 lpitem
->rect
.right
+= mis
.itemWidth
;
773 TRACE("id=%04x size=%dx%d\n",
774 lpitem
->wID
, mis
.itemWidth
, mis
.itemHeight
);
778 if (lpitem
->fType
& MF_SEPARATOR
)
780 lpitem
->rect
.bottom
+= SEPARATOR_HEIGHT
;
786 lpitem
->rect
.right
+= 2 * check_bitmap_width
;
787 if (lpitem
->fType
& MF_POPUP
)
788 lpitem
->rect
.right
+= arrow_bitmap_width
;
791 if (IS_BITMAP_ITEM(lpitem
->fType
))
796 /* Check if there is a magic menu item associated with this item */
797 if((LOWORD((int)lpitem
->text
))<12)
799 resBmp
= MENU_LoadMagicItem((int)lpitem
->text
, (lpitem
->fType
& MF_HILITE
),
803 resBmp
= (HBITMAP
)lpitem
->text
;
805 if (GetObjectA(resBmp
, sizeof(bm
), &bm
))
807 lpitem
->rect
.right
+= bm
.bmWidth
;
808 lpitem
->rect
.bottom
+= bm
.bmHeight
;
814 /* If we get here, then it must be a text item */
815 if (IS_STRING_ITEM( lpitem
->fType
))
818 GetTextExtentPoint32A(hdc
, lpitem
->text
, strlen(lpitem
->text
), &size
);
820 lpitem
->rect
.right
+= size
.cx
;
821 if (TWEAK_WineLook
== WIN31_LOOK
)
822 lpitem
->rect
.bottom
+= MAX( size
.cy
, GetSystemMetrics(SM_CYMENU
) );
824 lpitem
->rect
.bottom
+= MAX (size
.cy
, GetSystemMetrics(SM_CYMENU
)-1);
829 lpitem
->rect
.right
+= MENU_BAR_ITEMS_SPACE
;
831 else if ((p
= strchr( lpitem
->text
, '\t' )) != NULL
)
833 /* Item contains a tab (only meaningful in popup menus) */
834 GetTextExtentPoint32A(hdc
, lpitem
->text
, (int)(p
- lpitem
->text
) , &size
);
835 lpitem
->xTab
= check_bitmap_width
+ MENU_TAB_SPACE
+ size
.cx
;
836 lpitem
->rect
.right
+= MENU_TAB_SPACE
;
840 if (strchr( lpitem
->text
, '\b' ))
841 lpitem
->rect
.right
+= MENU_TAB_SPACE
;
842 lpitem
->xTab
= lpitem
->rect
.right
- check_bitmap_width
843 - arrow_bitmap_width
;
846 TRACE("(%d,%d)-(%d,%d)\n", lpitem
->rect
.left
, lpitem
->rect
.top
, lpitem
->rect
.right
, lpitem
->rect
.bottom
);
850 /***********************************************************************
851 * MENU_PopupMenuCalcSize
853 * Calculate the size of a popup menu.
855 static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop
, HWND hwndOwner
)
860 int orgX
, orgY
, maxX
, maxTab
, maxTabWidth
;
862 lppop
->Width
= lppop
->Height
= 0;
863 if (lppop
->nItems
== 0) return;
866 SelectObject( hdc
, hMenuFont
);
869 maxX
= (TWEAK_WineLook
== WIN31_LOOK
) ? GetSystemMetrics(SM_CXBORDER
) : 2 ;
871 while (start
< lppop
->nItems
)
873 lpitem
= &lppop
->items
[start
];
875 orgY
= (TWEAK_WineLook
== WIN31_LOOK
) ? GetSystemMetrics(SM_CYBORDER
) : 2;
877 maxTab
= maxTabWidth
= 0;
879 /* Parse items until column break or end of menu */
880 for (i
= start
; i
< lppop
->nItems
; i
++, lpitem
++)
883 (lpitem
->fType
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
885 MENU_CalcItemSize( hdc
, lpitem
, hwndOwner
, orgX
, orgY
, FALSE
);
887 if (lpitem
->fType
& MF_MENUBARBREAK
) orgX
++;
888 maxX
= MAX( maxX
, lpitem
->rect
.right
);
889 orgY
= lpitem
->rect
.bottom
;
890 if (IS_STRING_ITEM(lpitem
->fType
) && lpitem
->xTab
)
892 maxTab
= MAX( maxTab
, lpitem
->xTab
);
893 maxTabWidth
= MAX(maxTabWidth
,lpitem
->rect
.right
-lpitem
->xTab
);
897 /* Finish the column (set all items to the largest width found) */
898 maxX
= MAX( maxX
, maxTab
+ maxTabWidth
);
899 for (lpitem
= &lppop
->items
[start
]; start
< i
; start
++, lpitem
++)
901 lpitem
->rect
.right
= maxX
;
902 if (IS_STRING_ITEM(lpitem
->fType
) && lpitem
->xTab
)
903 lpitem
->xTab
= maxTab
;
906 lppop
->Height
= MAX( lppop
->Height
, orgY
);
911 /* space for 3d border */
912 if(TWEAK_WineLook
> WIN31_LOOK
)
922 /***********************************************************************
923 * MENU_MenuBarCalcSize
925 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
926 * height is off by 1 pixel which causes lengthy window relocations when
927 * active document window is maximized/restored.
929 * Calculate the size of the menu bar.
931 static void MENU_MenuBarCalcSize( HDC hdc
, LPRECT lprect
,
932 LPPOPUPMENU lppop
, HWND hwndOwner
)
935 int start
, i
, orgX
, orgY
, maxY
, helpPos
;
937 if ((lprect
== NULL
) || (lppop
== NULL
)) return;
938 if (lppop
->nItems
== 0) return;
939 TRACE("left=%d top=%d right=%d bottom=%d\n",
940 lprect
->left
, lprect
->top
, lprect
->right
, lprect
->bottom
);
941 lppop
->Width
= lprect
->right
- lprect
->left
;
946 while (start
< lppop
->nItems
)
948 lpitem
= &lppop
->items
[start
];
952 /* Parse items until line break or end of menu */
953 for (i
= start
; i
< lppop
->nItems
; i
++, lpitem
++)
955 if ((helpPos
== -1) && (lpitem
->fType
& MF_HELP
)) helpPos
= i
;
957 (lpitem
->fType
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
959 TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
961 debug_print_menuitem (" item: ", lpitem
, "");
962 MENU_CalcItemSize( hdc
, lpitem
, hwndOwner
, orgX
, orgY
, TRUE
);
964 if (lpitem
->rect
.right
> lprect
->right
)
966 if (i
!= start
) break;
967 else lpitem
->rect
.right
= lprect
->right
;
969 maxY
= MAX( maxY
, lpitem
->rect
.bottom
);
970 orgX
= lpitem
->rect
.right
;
973 /* Finish the line (set all items to the largest height found) */
974 while (start
< i
) lppop
->items
[start
++].rect
.bottom
= maxY
;
977 lprect
->bottom
= maxY
;
978 lppop
->Height
= lprect
->bottom
- lprect
->top
;
980 /* Flush right all magic items and items between the MF_HELP and */
981 /* the last item (if several lines, only move the last line) */
982 lpitem
= &lppop
->items
[lppop
->nItems
-1];
983 orgY
= lpitem
->rect
.top
;
984 orgX
= lprect
->right
;
985 for (i
= lppop
->nItems
- 1; i
>= helpPos
; i
--, lpitem
--)
987 if ( !IS_BITMAP_ITEM(lpitem
->fType
) && ((helpPos
==-1) ? TRUE
: (helpPos
>i
) ))
989 if (lpitem
->rect
.top
!= orgY
) break; /* Other line */
990 if (lpitem
->rect
.right
>= orgX
) break; /* Too far right already */
991 lpitem
->rect
.left
+= orgX
- lpitem
->rect
.right
;
992 lpitem
->rect
.right
= orgX
;
993 orgX
= lpitem
->rect
.left
;
997 /***********************************************************************
1000 * Draw a single menu item.
1002 static void MENU_DrawMenuItem( HWND hwnd
, HMENU hmenu
, HWND hwndOwner
, HDC hdc
, MENUITEM
*lpitem
,
1003 UINT height
, BOOL menuBar
, UINT odaction
)
1007 debug_print_menuitem("MENU_DrawMenuItem: ", lpitem
, "");
1009 if (lpitem
->fType
& MF_SYSMENU
)
1011 if( !IsIconic(hwnd
) ) {
1012 if (TWEAK_WineLook
> WIN31_LOOK
)
1013 NC_DrawSysButton95( hwnd
, hdc
,
1015 (MF_HILITE
| MF_MOUSESELECT
) );
1017 NC_DrawSysButton( hwnd
, hdc
,
1019 (MF_HILITE
| MF_MOUSESELECT
) );
1025 if (lpitem
->fType
& MF_OWNERDRAW
)
1029 dis
.CtlType
= ODT_MENU
;
1031 dis
.itemID
= lpitem
->wID
;
1032 dis
.itemData
= (DWORD
)lpitem
->dwItemData
;
1034 if (lpitem
->fState
& MF_CHECKED
) dis
.itemState
|= ODS_CHECKED
;
1035 if (lpitem
->fState
& MF_GRAYED
) dis
.itemState
|= ODS_GRAYED
;
1036 if (lpitem
->fState
& MF_HILITE
) dis
.itemState
|= ODS_SELECTED
;
1037 dis
.itemAction
= odaction
; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
1038 dis
.hwndItem
= hmenu
;
1040 dis
.rcItem
= lpitem
->rect
;
1041 TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
1042 "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner
,
1043 dis
.itemID
, dis
.itemState
, dis
.itemAction
, dis
.hwndItem
,
1044 dis
.hDC
, dis
.rcItem
.left
, dis
.rcItem
.top
, dis
.rcItem
.right
,
1046 SendMessageA( hwndOwner
, WM_DRAWITEM
, 0, (LPARAM
)&dis
);
1050 TRACE("rect={%d,%d,%d,%d}\n", lpitem
->rect
.left
, lpitem
->rect
.top
,
1051 lpitem
->rect
.right
,lpitem
->rect
.bottom
);
1053 if (menuBar
&& (lpitem
->fType
& MF_SEPARATOR
)) return;
1055 rect
= lpitem
->rect
;
1057 if ((lpitem
->fState
& MF_HILITE
) && !(IS_BITMAP_ITEM(lpitem
->fType
)))
1058 if ((menuBar
) && (TWEAK_WineLook
==WIN98_LOOK
))
1059 DrawEdge(hdc
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
1061 FillRect( hdc
, &rect
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
1063 FillRect( hdc
, &rect
, GetSysColorBrush(COLOR_MENU
) );
1065 SetBkMode( hdc
, TRANSPARENT
);
1067 /* vertical separator */
1068 if (!menuBar
&& (lpitem
->fType
& MF_MENUBARBREAK
))
1070 if (TWEAK_WineLook
> WIN31_LOOK
)
1074 rc
.bottom
= height
- 3;
1075 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_LEFT
);
1079 SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1080 MoveTo16( hdc
, rect
.left
, 0 );
1081 LineTo( hdc
, rect
.left
, height
);
1085 /* horizontal separator */
1086 if (lpitem
->fType
& MF_SEPARATOR
)
1088 if (TWEAK_WineLook
> WIN31_LOOK
)
1093 rc
.top
+= SEPARATOR_HEIGHT
/ 2;
1094 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_TOP
);
1098 SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1099 MoveTo16( hdc
, rect
.left
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
1100 LineTo( hdc
, rect
.right
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
1107 if ((lpitem
->fState
& MF_HILITE
) && !(IS_BITMAP_ITEM(lpitem
->fType
)) )
1109 if (lpitem
->fState
& MF_GRAYED
)
1110 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
1112 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
1113 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
1117 if (lpitem
->fState
& MF_GRAYED
)
1118 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
1120 SetTextColor( hdc
, GetSysColor( COLOR_MENUTEXT
) );
1121 SetBkColor( hdc
, GetSysColor( COLOR_MENU
) );
1124 /* helper lines for debugging */
1125 /* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1126 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1127 MoveTo16( hdc, rect.left, (rect.top + rect.bottom)/2 );
1128 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1133 INT y
= rect
.top
+ rect
.bottom
;
1135 /* Draw the check mark
1138 * Custom checkmark bitmaps are monochrome but not always 1bpp.
1141 if (lpitem
->fState
& MF_CHECKED
)
1143 HBITMAP bm
= lpitem
->hCheckBit
? lpitem
->hCheckBit
:
1144 ((lpitem
->fType
& MFT_RADIOCHECK
) ? hStdRadioCheck
: hStdCheck
);
1145 HDC hdcMem
= CreateCompatibleDC( hdc
);
1147 SelectObject( hdcMem
, bm
);
1148 BitBlt( hdc
, rect
.left
, (y
- check_bitmap_height
) / 2,
1149 check_bitmap_width
, check_bitmap_height
,
1150 hdcMem
, 0, 0, SRCCOPY
);
1153 else if (lpitem
->hUnCheckBit
)
1155 HDC hdcMem
= CreateCompatibleDC( hdc
);
1157 SelectObject( hdcMem
, lpitem
->hUnCheckBit
);
1158 BitBlt( hdc
, rect
.left
, (y
- check_bitmap_height
) / 2,
1159 check_bitmap_width
, check_bitmap_height
,
1160 hdcMem
, 0, 0, SRCCOPY
);
1164 /* Draw the popup-menu arrow */
1165 if (lpitem
->fType
& MF_POPUP
)
1167 HDC hdcMem
= CreateCompatibleDC( hdc
);
1169 SelectObject( hdcMem
, hStdMnArrow
);
1170 BitBlt( hdc
, rect
.right
- arrow_bitmap_width
- 1,
1171 (y
- arrow_bitmap_height
) / 2,
1172 arrow_bitmap_width
, arrow_bitmap_height
,
1173 hdcMem
, 0, 0, SRCCOPY
);
1177 rect
.left
+= check_bitmap_width
;
1178 rect
.right
-= arrow_bitmap_width
;
1181 /* Draw the item text or bitmap */
1182 if (IS_BITMAP_ITEM(lpitem
->fType
))
1187 HDC hdcMem
= CreateCompatibleDC( hdc
);
1190 * Check if there is a magic menu item associated with this item
1191 * and load the appropriate bitmap
1193 if((LOWORD((int)lpitem
->text
)) < 12)
1195 resBmp
= MENU_LoadMagicItem((int)lpitem
->text
, (lpitem
->fState
& MF_HILITE
),
1196 lpitem
->dwItemData
);
1199 resBmp
= (HBITMAP
)lpitem
->text
;
1204 GetObjectA( resBmp
, sizeof(bm
), &bm
);
1206 SelectObject(hdcMem
,resBmp
);
1208 /* handle fontsize > bitmap_height */
1209 top
= ((rect
.bottom
-rect
.top
)>bm
.bmHeight
) ?
1210 rect
.top
+(rect
.bottom
-rect
.top
-bm
.bmHeight
)/2 : rect
.top
;
1212 BitBlt( hdc
, rect
.left
, top
, rect
.right
- rect
.left
,
1213 rect
.bottom
- rect
.top
, hdcMem
, 0, 0, SRCCOPY
);
1220 /* No bitmap - process text if present */
1221 else if (IS_STRING_ITEM(lpitem
->fType
))
1226 UINT uFormat
= (menuBar
) ?
1227 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
:
1228 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
;
1230 if ( lpitem
->fState
& MFS_DEFAULT
)
1232 hfontOld
= SelectObject( hdc
, hMenuFontBold
);
1237 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
1238 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
1239 i
= strlen( lpitem
->text
);
1243 for (i
= 0; lpitem
->text
[i
]; i
++)
1244 if ((lpitem
->text
[i
] == '\t') || (lpitem
->text
[i
] == '\b'))
1248 if( !(TWEAK_WineLook
== WIN31_LOOK
) && (lpitem
->fState
& MF_GRAYED
))
1250 if (!(lpitem
->fState
& MF_HILITE
) )
1252 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
1253 SetTextColor(hdc
, RGB(0xff, 0xff, 0xff));
1254 DrawTextA( hdc
, lpitem
->text
, i
, &rect
, uFormat
);
1255 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
1257 SetTextColor(hdc
, RGB(0x80, 0x80, 0x80));
1260 DrawTextA( hdc
, lpitem
->text
, i
, &rect
, uFormat
);
1262 /* paint the shortcut text */
1263 if (lpitem
->text
[i
]) /* There's a tab or flush-right char */
1265 if (lpitem
->text
[i
] == '\t')
1267 rect
.left
= lpitem
->xTab
;
1268 uFormat
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
;
1272 uFormat
= DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
;
1275 if( !(TWEAK_WineLook
== WIN31_LOOK
) && (lpitem
->fState
& MF_GRAYED
))
1277 if (!(lpitem
->fState
& MF_HILITE
) )
1279 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
1280 SetTextColor(hdc
, RGB(0xff, 0xff, 0xff));
1281 DrawTextA( hdc
, lpitem
->text
+ i
+ 1, -1, &rect
, uFormat
);
1282 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
1284 SetTextColor(hdc
, RGB(0x80, 0x80, 0x80));
1286 DrawTextA( hdc
, lpitem
->text
+ i
+ 1, -1, &rect
, uFormat
);
1290 SelectObject (hdc
, hfontOld
);
1295 /***********************************************************************
1296 * MENU_DrawPopupMenu
1298 * Paint a popup menu.
1300 static void MENU_DrawPopupMenu( HWND hwnd
, HDC hdc
, HMENU hmenu
)
1302 HBRUSH hPrevBrush
= 0;
1305 TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd
, hdc
, hmenu
);
1307 GetClientRect( hwnd
, &rect
);
1309 if(TWEAK_WineLook
== WIN31_LOOK
)
1311 rect
.bottom
-= POPUP_YSHADE
* GetSystemMetrics(SM_CYBORDER
);
1312 rect
.right
-= POPUP_XSHADE
* GetSystemMetrics(SM_CXBORDER
);
1315 if((hPrevBrush
= SelectObject( hdc
, GetSysColorBrush(COLOR_MENU
) ))
1316 && (SelectObject( hdc
, hMenuFont
)))
1320 Rectangle( hdc
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1322 hPrevPen
= SelectObject( hdc
, GetStockObject( NULL_PEN
) );
1328 /* draw 3-d shade */
1329 if(TWEAK_WineLook
== WIN31_LOOK
) {
1330 SelectObject( hdc
, hShadeBrush
);
1331 SetBkMode( hdc
, TRANSPARENT
);
1332 ropPrev
= SetROP2( hdc
, R2_MASKPEN
);
1334 i
= rect
.right
; /* why SetBrushOrg() doesn't? */
1335 PatBlt( hdc
, i
& 0xfffffffe,
1336 rect
.top
+ POPUP_YSHADE
*GetSystemMetrics(SM_CYBORDER
),
1337 i
%2 + POPUP_XSHADE
*GetSystemMetrics(SM_CXBORDER
),
1338 rect
.bottom
- rect
.top
, 0x00a000c9 );
1340 PatBlt( hdc
, rect
.left
+ POPUP_XSHADE
*GetSystemMetrics(SM_CXBORDER
),
1341 i
& 0xfffffffe,rect
.right
- rect
.left
,
1342 i
%2 + POPUP_YSHADE
*GetSystemMetrics(SM_CYBORDER
), 0x00a000c9 );
1343 SelectObject( hdc
, hPrevPen
);
1344 SelectObject( hdc
, hPrevBrush
);
1345 SetROP2( hdc
, ropPrev
);
1348 DrawEdge (hdc
, &rect
, EDGE_RAISED
, BF_RECT
);
1350 /* draw menu items */
1352 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
1353 if (menu
&& menu
->nItems
)
1358 for (u
= menu
->nItems
, item
= menu
->items
; u
> 0; u
--, item
++)
1359 MENU_DrawMenuItem( hwnd
, hmenu
, menu
->hwndOwner
, hdc
, item
,
1360 menu
->Height
, FALSE
, ODA_DRAWENTIRE
);
1365 SelectObject( hdc
, hPrevBrush
);
1370 /***********************************************************************
1373 * Paint a menu bar. Returns the height of the menu bar.
1374 * called from [windows/nonclient.c]
1376 UINT
MENU_DrawMenuBar( HDC hDC
, LPRECT lprect
, HWND hwnd
,
1383 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1385 lppop
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR( (HMENU
)wndPtr
->wIDmenu
);
1386 if (lppop
== NULL
|| lprect
== NULL
)
1388 retvalue
= GetSystemMetrics(SM_CYMENU
);
1392 TRACE("(%04x, %p, %p)\n", hDC
, lprect
, lppop
);
1394 hfontOld
= SelectObject( hDC
, hMenuFont
);
1396 if (lppop
->Height
== 0)
1397 MENU_MenuBarCalcSize(hDC
, lprect
, lppop
, hwnd
);
1399 lprect
->bottom
= lprect
->top
+ lppop
->Height
;
1403 retvalue
= lppop
->Height
;
1407 FillRect(hDC
, lprect
, GetSysColorBrush(COLOR_MENU
) );
1409 if (TWEAK_WineLook
== WIN31_LOOK
)
1411 SelectObject( hDC
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1412 MoveTo16( hDC
, lprect
->left
, lprect
->bottom
);
1413 LineTo( hDC
, lprect
->right
, lprect
->bottom
);
1417 SelectObject( hDC
, GetSysColorPen(COLOR_3DFACE
));
1418 MoveTo16( hDC
, lprect
->left
, lprect
->bottom
);
1419 LineTo( hDC
, lprect
->right
, lprect
->bottom
);
1422 if (lppop
->nItems
== 0)
1424 retvalue
= GetSystemMetrics(SM_CYMENU
);
1428 for (i
= 0; i
< lppop
->nItems
; i
++)
1430 MENU_DrawMenuItem( hwnd
, (HMENU
)wndPtr
->wIDmenu
, GetWindow(hwnd
,GW_OWNER
),
1431 hDC
, &lppop
->items
[i
], lppop
->Height
, TRUE
, ODA_DRAWENTIRE
);
1433 retvalue
= lppop
->Height
;
1437 SelectObject (hDC
, hfontOld
);
1439 WIN_ReleaseWndPtr(wndPtr
);
1443 /***********************************************************************
1444 * MENU_PatchResidentPopup
1446 BOOL
MENU_PatchResidentPopup( HQUEUE16 checkQueue
, WND
* checkWnd
)
1448 WND
*pTPWnd
= MENU_GetTopPopupWnd();
1454 TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
1455 checkQueue
, checkWnd
? checkWnd
->hwndSelf
: 0, pTPWnd
->hmemTaskQ
,
1456 pTPWnd
->owner
? pTPWnd
->owner
->hwndSelf
: 0);
1458 switch( checkQueue
)
1460 case 0: /* checkWnd is the new popup owner */
1463 pTPWnd
->owner
= checkWnd
;
1464 if( pTPWnd
->hmemTaskQ
!= checkWnd
->hmemTaskQ
)
1465 hTask
= QUEUE_GetQueueTask( checkWnd
->hmemTaskQ
);
1469 case 0xFFFF: /* checkWnd is destroyed */
1470 if( pTPWnd
->owner
== checkWnd
)
1471 pTPWnd
->owner
= NULL
;
1472 MENU_ReleaseTopPopupWnd();
1475 default: /* checkQueue is exiting */
1476 if( pTPWnd
->hmemTaskQ
== checkQueue
)
1478 hTask
= QUEUE_GetQueueTask( pTPWnd
->hmemTaskQ
);
1479 hTask
= TASK_GetNextTask( hTask
);
1486 TDB
* task
= (TDB
*)GlobalLock16( hTask
);
1489 pTPWnd
->hInstance
= task
->hInstance
;
1490 pTPWnd
->hmemTaskQ
= task
->hQueue
;
1491 MENU_ReleaseTopPopupWnd();
1494 else WARN("failed to patch resident popup.\n");
1497 MENU_ReleaseTopPopupWnd();
1501 /***********************************************************************
1504 * Display a popup menu.
1506 static BOOL
MENU_ShowPopup( HWND hwndOwner
, HMENU hmenu
, UINT id
,
1507 INT x
, INT y
, INT xanchor
, INT yanchor
)
1510 WND
*wndOwner
= NULL
;
1512 TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
1513 hwndOwner
, hmenu
, id
, x
, y
, xanchor
, yanchor
);
1515 if (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
))) return FALSE
;
1516 if (menu
->FocusedItem
!= NO_SELECTED_ITEM
)
1518 menu
->items
[menu
->FocusedItem
].fState
&= ~(MF_HILITE
|MF_MOUSESELECT
);
1519 menu
->FocusedItem
= NO_SELECTED_ITEM
;
1522 /* store the owner for DrawItem*/
1523 menu
->hwndOwner
= hwndOwner
;
1525 if( (wndOwner
= WIN_FindWndPtr( hwndOwner
)) )
1529 MENU_PopupMenuCalcSize( menu
, hwndOwner
);
1531 /* adjust popup menu pos so that it fits within the desktop */
1533 width
= menu
->Width
+ GetSystemMetrics(SM_CXBORDER
);
1534 height
= menu
->Height
+ GetSystemMetrics(SM_CYBORDER
);
1536 if( x
+ width
> GetSystemMetrics(SM_CXSCREEN
))
1539 x
-= width
- xanchor
;
1540 if( x
+ width
> GetSystemMetrics(SM_CXSCREEN
))
1541 x
= GetSystemMetrics(SM_CXSCREEN
) - width
;
1545 if( y
+ height
> GetSystemMetrics(SM_CYSCREEN
))
1548 y
-= height
+ yanchor
;
1549 if( y
+ height
> GetSystemMetrics(SM_CYSCREEN
))
1550 y
= GetSystemMetrics(SM_CYSCREEN
) - height
;
1554 if( TWEAK_WineLook
== WIN31_LOOK
)
1556 width
+= POPUP_XSHADE
* GetSystemMetrics(SM_CXBORDER
); /* add space for shading */
1557 height
+= POPUP_YSHADE
* GetSystemMetrics(SM_CYBORDER
);
1560 /* NOTE: In Windows, top menu popup is not owned. */
1561 if (!pTopPopupWnd
) /* create top level popup menu window */
1563 assert( uSubPWndLevel
== 0 );
1565 pTopPopupWnd
= WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_ATOM
, NULL
,
1566 WS_POPUP
, x
, y
, width
, height
,
1567 hwndOwner
, 0, wndOwner
->hInstance
,
1571 WIN_ReleaseWndPtr(wndOwner
);
1574 menu
->hWnd
= pTopPopupWnd
->hwndSelf
;
1575 MENU_ReleaseTopPopupWnd();
1580 /* create a new window for the submenu */
1582 menu
->hWnd
= CreateWindowA( POPUPMENU_CLASS_ATOM
, NULL
,
1583 WS_POPUP
, x
, y
, width
, height
,
1584 hwndOwner
, 0, wndOwner
->hInstance
,
1588 WIN_ReleaseWndPtr(wndOwner
);
1592 else /* top level popup menu window already exists */
1594 WND
*pTPWnd
= MENU_GetTopPopupWnd();
1595 menu
->hWnd
= pTPWnd
->hwndSelf
;
1597 MENU_PatchResidentPopup( 0, wndOwner
);
1598 SendMessageA( pTPWnd
->hwndSelf
, MM_SETMENUHANDLE
, (WPARAM16
)hmenu
, 0L);
1600 /* adjust its size */
1602 SetWindowPos( menu
->hWnd
, 0, x
, y
, width
, height
,
1603 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1604 MENU_ReleaseTopPopupWnd();
1607 uSubPWndLevel
++; /* menu level counter */
1609 /* Display the window */
1611 SetWindowPos( menu
->hWnd
, HWND_TOP
, 0, 0, 0, 0,
1612 SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1613 UpdateWindow( menu
->hWnd
);
1614 WIN_ReleaseWndPtr(wndOwner
);
1621 /***********************************************************************
1624 static void MENU_SelectItem( HWND hwndOwner
, HMENU hmenu
, UINT wIndex
,
1625 BOOL sendMenuSelect
, HMENU topmenu
)
1630 TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner
, hmenu
, wIndex
, sendMenuSelect
);
1632 lppop
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
1633 if (!lppop
->nItems
) return;
1635 if (lppop
->FocusedItem
== wIndex
) return;
1636 if (lppop
->wFlags
& MF_POPUP
) hdc
= GetDC( lppop
->hWnd
);
1637 else hdc
= GetDCEx( lppop
->hWnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1639 SelectObject( hdc
, hMenuFont
);
1641 /* Clear previous highlighted item */
1642 if (lppop
->FocusedItem
!= NO_SELECTED_ITEM
)
1644 lppop
->items
[lppop
->FocusedItem
].fState
&= ~(MF_HILITE
|MF_MOUSESELECT
);
1645 MENU_DrawMenuItem(lppop
->hWnd
, hmenu
, hwndOwner
, hdc
,&lppop
->items
[lppop
->FocusedItem
],
1646 lppop
->Height
, !(lppop
->wFlags
& MF_POPUP
),
1650 /* Highlight new item (if any) */
1651 lppop
->FocusedItem
= wIndex
;
1652 if (lppop
->FocusedItem
!= NO_SELECTED_ITEM
)
1654 if(!(lppop
->items
[wIndex
].fType
& MF_SEPARATOR
)) {
1655 lppop
->items
[wIndex
].fState
|= MF_HILITE
;
1656 MENU_DrawMenuItem( lppop
->hWnd
, hmenu
, hwndOwner
, hdc
,
1657 &lppop
->items
[wIndex
], lppop
->Height
,
1658 !(lppop
->wFlags
& MF_POPUP
), ODA_SELECT
);
1662 MENUITEM
*ip
= &lppop
->items
[lppop
->FocusedItem
];
1663 SendMessageA( hwndOwner
, WM_MENUSELECT
,
1664 MAKELONG(ip
->fType
& MF_POPUP
? wIndex
: ip
->wID
,
1665 ip
->fType
| ip
->fState
| MF_MOUSESELECT
|
1666 (lppop
->wFlags
& MF_SYSMENU
)), hmenu
);
1669 else if (sendMenuSelect
) {
1672 if((pos
=MENU_FindSubMenu(&topmenu
, hmenu
))!=NO_SELECTED_ITEM
){
1673 POPUPMENU
*ptm
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( topmenu
);
1674 MENUITEM
*ip
= &ptm
->items
[pos
];
1675 SendMessageA( hwndOwner
, WM_MENUSELECT
, MAKELONG(pos
,
1676 ip
->fType
| ip
->fState
| MF_MOUSESELECT
|
1677 (ptm
->wFlags
& MF_SYSMENU
)), topmenu
);
1681 ReleaseDC( lppop
->hWnd
, hdc
);
1685 /***********************************************************************
1686 * MENU_MoveSelection
1688 * Moves currently selected item according to the offset parameter.
1689 * If there is no selection then it should select the last item if
1690 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
1692 static void MENU_MoveSelection( HWND hwndOwner
, HMENU hmenu
, INT offset
)
1697 TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner
, hmenu
, offset
);
1699 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
1700 if (!menu
->items
) return;
1702 if ( menu
->FocusedItem
!= NO_SELECTED_ITEM
)
1704 if( menu
->nItems
== 1 ) return; else
1705 for (i
= menu
->FocusedItem
+ offset
; i
>= 0 && i
< menu
->nItems
1707 if (!(menu
->items
[i
].fType
& MF_SEPARATOR
))
1709 MENU_SelectItem( hwndOwner
, hmenu
, i
, TRUE
, 0 );
1714 for ( i
= (offset
> 0) ? 0 : menu
->nItems
- 1;
1715 i
>= 0 && i
< menu
->nItems
; i
+= offset
)
1716 if (!(menu
->items
[i
].fType
& MF_SEPARATOR
))
1718 MENU_SelectItem( hwndOwner
, hmenu
, i
, TRUE
, 0 );
1724 /**********************************************************************
1727 * Set an item flags, id and text ptr. Called by InsertMenu() and
1730 static BOOL
MENU_SetItemData( MENUITEM
*item
, UINT flags
, UINT id
,
1733 LPSTR prevText
= IS_STRING_ITEM(item
->fType
) ? item
->text
: NULL
;
1735 debug_print_menuitem("MENU_SetItemData from: ", item
, "");
1737 if (IS_STRING_ITEM(flags
))
1741 flags
|= MF_SEPARATOR
;
1747 /* Item beginning with a backspace is a help item */
1753 if (!(text
= HEAP_strdupA( SystemHeap
, 0, str
))) return FALSE
;
1757 else if (IS_BITMAP_ITEM(flags
))
1758 item
->text
= (LPSTR
)(HBITMAP
)LOWORD(str
);
1759 else item
->text
= NULL
;
1761 if (flags
& MF_OWNERDRAW
)
1762 item
->dwItemData
= (DWORD
)str
;
1764 item
->dwItemData
= 0;
1766 if ((item
->fType
& MF_POPUP
) && (flags
& MF_POPUP
) && (item
->hSubMenu
!= id
) )
1767 DestroyMenu( item
->hSubMenu
); /* ModifyMenu() spec */
1769 if (flags
& MF_POPUP
)
1771 POPUPMENU
*menu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR((UINT16
)id
);
1772 if (IS_A_MENU(menu
)) menu
->wFlags
|= MF_POPUP
;
1784 if (flags
& MF_POPUP
)
1785 item
->hSubMenu
= id
;
1787 if ((item
->fType
& MF_POPUP
) && !(flags
& MF_POPUP
) )
1788 flags
|= MF_POPUP
; /* keep popup */
1790 item
->fType
= flags
& TYPE_MASK
;
1791 item
->fState
= (flags
& STATE_MASK
) &
1792 ~(MF_HILITE
| MF_MOUSESELECT
| MF_BYPOSITION
);
1795 /* Don't call SetRectEmpty here! */
1798 if (prevText
) HeapFree( SystemHeap
, 0, prevText
);
1800 debug_print_menuitem("MENU_SetItemData to : ", item
, "");
1805 /**********************************************************************
1808 * Insert a new item into a menu.
1810 static MENUITEM
*MENU_InsertItem( HMENU hMenu
, UINT pos
, UINT flags
)
1815 if (!(menu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR(hMenu
)))
1817 WARN("%04x not a menu handle\n",
1822 /* Find where to insert new item */
1824 if ((flags
& MF_BYPOSITION
) &&
1825 ((pos
== (UINT
)-1) || (pos
== menu
->nItems
)))
1827 /* Special case: append to menu */
1828 /* Some programs specify the menu length to do that */
1833 if (!MENU_FindItem( &hMenu
, &pos
, flags
))
1835 WARN("item %x not found\n",
1839 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
)))
1841 WARN("%04x not a menu handle\n",
1847 /* Create new items array */
1849 newItems
= HeapAlloc( SystemHeap
, 0, sizeof(MENUITEM
) * (menu
->nItems
+1) );
1852 WARN("allocation failed\n" );
1855 if (menu
->nItems
> 0)
1857 /* Copy the old array into the new */
1858 if (pos
> 0) memcpy( newItems
, menu
->items
, pos
* sizeof(MENUITEM
) );
1859 if (pos
< menu
->nItems
) memcpy( &newItems
[pos
+1], &menu
->items
[pos
],
1860 (menu
->nItems
-pos
)*sizeof(MENUITEM
) );
1861 HeapFree( SystemHeap
, 0, menu
->items
);
1863 menu
->items
= newItems
;
1865 memset( &newItems
[pos
], 0, sizeof(*newItems
) );
1866 menu
->Height
= 0; /* force size recalculate */
1867 return &newItems
[pos
];
1871 /**********************************************************************
1872 * MENU_ParseResource
1874 * Parse a standard menu resource and add items to the menu.
1875 * Return a pointer to the end of the resource.
1877 static LPCSTR
MENU_ParseResource( LPCSTR res
, HMENU hMenu
, BOOL unicode
)
1884 flags
= GET_WORD(res
);
1885 res
+= sizeof(WORD
);
1886 if (!(flags
& MF_POPUP
))
1889 res
+= sizeof(WORD
);
1891 if (!IS_STRING_ITEM(flags
))
1892 ERR("not a string item %04x\n", flags
);
1894 if (!unicode
) res
+= strlen(str
) + 1;
1895 else res
+= (lstrlenW((LPCWSTR
)str
) + 1) * sizeof(WCHAR
);
1896 if (flags
& MF_POPUP
)
1898 HMENU hSubMenu
= CreatePopupMenu();
1899 if (!hSubMenu
) return NULL
;
1900 if (!(res
= MENU_ParseResource( res
, hSubMenu
, unicode
)))
1902 if (!unicode
) AppendMenuA( hMenu
, flags
, (UINT
)hSubMenu
, str
);
1903 else AppendMenuW( hMenu
, flags
, (UINT
)hSubMenu
, (LPCWSTR
)str
);
1905 else /* Not a popup */
1907 if (!unicode
) AppendMenuA( hMenu
, flags
, id
, *str
? str
: NULL
);
1908 else AppendMenuW( hMenu
, flags
, id
,
1909 *(LPCWSTR
)str
? (LPCWSTR
)str
: NULL
);
1911 } while (!(flags
& MF_END
));
1916 /**********************************************************************
1917 * MENUEX_ParseResource
1919 * Parse an extended menu resource and add items to the menu.
1920 * Return a pointer to the end of the resource.
1922 static LPCSTR
MENUEX_ParseResource( LPCSTR res
, HMENU hMenu
)
1928 mii
.cbSize
= sizeof(mii
);
1929 mii
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_TYPE
;
1930 mii
.fType
= GET_DWORD(res
);
1931 res
+= sizeof(DWORD
);
1932 mii
.fState
= GET_DWORD(res
);
1933 res
+= sizeof(DWORD
);
1934 mii
.wID
= GET_DWORD(res
);
1935 res
+= sizeof(DWORD
);
1936 resinfo
= GET_WORD(res
); /* FIXME: for 16-bit apps this is a byte. */
1937 res
+= sizeof(WORD
);
1938 /* Align the text on a word boundary. */
1939 res
+= (~((int)res
- 1)) & 1;
1940 mii
.dwTypeData
= (LPWSTR
) res
;
1941 res
+= (1 + lstrlenW(mii
.dwTypeData
)) * sizeof(WCHAR
);
1942 /* Align the following fields on a dword boundary. */
1943 res
+= (~((int)res
- 1)) & 3;
1945 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1947 LPSTR newstr
= HEAP_strdupWtoA(GetProcessHeap(),
1949 TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
1950 mii
.fType
, mii
.fState
, mii
.wID
, resinfo
, newstr
);
1951 HeapFree( GetProcessHeap(), 0, newstr
);
1954 if (resinfo
& 1) { /* Pop-up? */
1955 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
1956 res
+= sizeof(DWORD
);
1957 mii
.hSubMenu
= CreatePopupMenu();
1960 if (!(res
= MENUEX_ParseResource(res
, mii
.hSubMenu
))) {
1961 DestroyMenu(mii
.hSubMenu
);
1964 mii
.fMask
|= MIIM_SUBMENU
;
1965 mii
.fType
|= MF_POPUP
;
1967 InsertMenuItemW(hMenu
, -1, MF_BYPOSITION
, &mii
);
1968 } while (!(resinfo
& MF_END
));
1973 /***********************************************************************
1976 * Return the handle of the selected sub-popup menu (if any).
1978 static HMENU
MENU_GetSubPopup( HMENU hmenu
)
1983 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
1985 if (menu
->FocusedItem
== NO_SELECTED_ITEM
) return 0;
1987 item
= &menu
->items
[menu
->FocusedItem
];
1988 if ((item
->fType
& MF_POPUP
) && (item
->fState
& MF_MOUSESELECT
))
1989 return item
->hSubMenu
;
1994 /***********************************************************************
1995 * MENU_HideSubPopups
1997 * Hide the sub-popup menus of this menu.
1999 static void MENU_HideSubPopups( HWND hwndOwner
, HMENU hmenu
,
2000 BOOL sendMenuSelect
)
2002 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);;
2004 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner
, hmenu
, sendMenuSelect
);
2006 if (menu
&& uSubPWndLevel
)
2012 if (menu
->FocusedItem
!= NO_SELECTED_ITEM
)
2014 item
= &menu
->items
[menu
->FocusedItem
];
2015 if (!(item
->fType
& MF_POPUP
) ||
2016 !(item
->fState
& MF_MOUSESELECT
)) return;
2017 item
->fState
&= ~MF_MOUSESELECT
;
2018 hsubmenu
= item
->hSubMenu
;
2021 submenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hsubmenu
);
2022 MENU_HideSubPopups( hwndOwner
, hsubmenu
, FALSE
);
2023 MENU_SelectItem( hwndOwner
, hsubmenu
, NO_SELECTED_ITEM
, sendMenuSelect
, 0 );
2025 if (submenu
->hWnd
== MENU_GetTopPopupWnd()->hwndSelf
)
2027 ShowWindow( submenu
->hWnd
, SW_HIDE
);
2032 DestroyWindow( submenu
->hWnd
);
2035 MENU_ReleaseTopPopupWnd();
2040 /***********************************************************************
2043 * Display the sub-menu of the selected item of this menu.
2044 * Return the handle of the submenu, or hmenu if no submenu to display.
2046 static HMENU
MENU_ShowSubPopup( HWND hwndOwner
, HMENU hmenu
,
2047 BOOL selectFirst
, UINT wFlags
)
2055 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner
, hmenu
, selectFirst
);
2057 if (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
))) return hmenu
;
2059 if (!(wndPtr
= WIN_FindWndPtr( menu
->hWnd
)) ||
2060 (menu
->FocusedItem
== NO_SELECTED_ITEM
))
2062 WIN_ReleaseWndPtr(wndPtr
);
2066 item
= &menu
->items
[menu
->FocusedItem
];
2067 if (!(item
->fType
& MF_POPUP
) ||
2068 (item
->fState
& (MF_GRAYED
| MF_DISABLED
)))
2070 WIN_ReleaseWndPtr(wndPtr
);
2074 /* message must be send before using item,
2075 because nearly everything may by changed by the application ! */
2077 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2078 if (!(wFlags
& TPM_NONOTIFY
))
2079 SendMessageA( hwndOwner
, WM_INITMENUPOPUP
, item
->hSubMenu
,
2080 MAKELONG( menu
->FocusedItem
, IS_SYSTEM_MENU(menu
) ));
2082 item
= &menu
->items
[menu
->FocusedItem
];
2085 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2086 if (!(item
->fState
& MF_HILITE
))
2088 if (menu
->wFlags
& MF_POPUP
) hdc
= GetDC( menu
->hWnd
);
2089 else hdc
= GetDCEx( menu
->hWnd
, 0, DCX_CACHE
| DCX_WINDOW
);
2091 SelectObject( hdc
, hMenuFont
);
2093 item
->fState
|= MF_HILITE
;
2094 MENU_DrawMenuItem( menu
->hWnd
, hmenu
, hwndOwner
, hdc
, item
, menu
->Height
, !(menu
->wFlags
& MF_POPUP
), ODA_DRAWENTIRE
);
2095 ReleaseDC( menu
->hWnd
, hdc
);
2097 if (!item
->rect
.top
&& !item
->rect
.left
&& !item
->rect
.bottom
&& !item
->rect
.right
)
2100 item
->fState
|= MF_MOUSESELECT
;
2102 if (IS_SYSTEM_MENU(menu
))
2104 MENU_InitSysMenuPopup(item
->hSubMenu
, wndPtr
->dwStyle
, GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
));
2106 NC_GetSysPopupPos( wndPtr
, &rect
);
2107 rect
.top
= rect
.bottom
;
2108 rect
.right
= GetSystemMetrics(SM_CXSIZE
);
2109 rect
.bottom
= GetSystemMetrics(SM_CYSIZE
);
2113 if (menu
->wFlags
& MF_POPUP
)
2115 rect
.left
= wndPtr
->rectWindow
.left
+ item
->rect
.right
-arrow_bitmap_width
;
2116 rect
.top
= wndPtr
->rectWindow
.top
+ item
->rect
.top
;
2117 rect
.right
= item
->rect
.left
- item
->rect
.right
+ 2*arrow_bitmap_width
;
2118 rect
.bottom
= item
->rect
.top
- item
->rect
.bottom
;
2122 rect
.left
= wndPtr
->rectWindow
.left
+ item
->rect
.left
;
2123 rect
.top
= wndPtr
->rectWindow
.top
+ item
->rect
.bottom
;
2124 rect
.right
= item
->rect
.right
- item
->rect
.left
;
2125 rect
.bottom
= item
->rect
.bottom
- item
->rect
.top
;
2129 MENU_ShowPopup( hwndOwner
, item
->hSubMenu
, menu
->FocusedItem
,
2130 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2132 MENU_MoveSelection( hwndOwner
, item
->hSubMenu
, ITEM_NEXT
);
2133 WIN_ReleaseWndPtr(wndPtr
);
2134 return item
->hSubMenu
;
2137 /***********************************************************************
2140 * Walks menu chain trying to find a menu pt maps to.
2142 static HMENU
MENU_PtMenu( HMENU hMenu
, POINT16 pt
)
2144 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hMenu
);
2145 register UINT ht
= menu
->FocusedItem
;
2147 /* try subpopup first (if any) */
2148 ht
= (ht
!= NO_SELECTED_ITEM
&&
2149 (menu
->items
[ht
].fType
& MF_POPUP
) &&
2150 (menu
->items
[ht
].fState
& MF_MOUSESELECT
))
2151 ? (UINT
) MENU_PtMenu(menu
->items
[ht
].hSubMenu
, pt
) : 0;
2153 if( !ht
) /* check the current window (avoiding WM_HITTEST) */
2155 ht
= (UINT
)NC_HandleNCHitTest( menu
->hWnd
, pt
);
2156 if( menu
->wFlags
& MF_POPUP
)
2157 ht
= (ht
!= (UINT
)HTNOWHERE
&&
2158 ht
!= (UINT
)HTERROR
) ? (UINT
)hMenu
: 0;
2161 WND
* wndPtr
= WIN_FindWndPtr(menu
->hWnd
);
2163 ht
= ( ht
== HTSYSMENU
) ? (UINT
)(wndPtr
->hSysMenu
)
2164 : ( ht
== HTMENU
) ? (UINT
)(wndPtr
->wIDmenu
) : 0;
2165 WIN_ReleaseWndPtr(wndPtr
);
2171 /***********************************************************************
2172 * MENU_ExecFocusedItem
2174 * Execute a menu item (for instance when user pressed Enter).
2175 * Return the wID of the executed item. Otherwise, -1 indicating
2176 * that no menu item wase executed;
2177 * Have to receive the flags for the TrackPopupMenu options to avoid
2178 * sending unwanted message.
2181 static INT
MENU_ExecFocusedItem( MTRACKER
* pmt
, HMENU hMenu
, UINT wFlags
)
2184 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hMenu
);
2186 TRACE("%p hmenu=0x%04x\n", pmt
, hMenu
);
2188 if (!menu
|| !menu
->nItems
||
2189 (menu
->FocusedItem
== NO_SELECTED_ITEM
)) return -1;
2191 item
= &menu
->items
[menu
->FocusedItem
];
2193 TRACE("%08x %08x %08x\n",
2194 hMenu
, item
->wID
, item
->hSubMenu
);
2196 if (!(item
->fType
& MF_POPUP
))
2198 if (!(item
->fState
& (MF_GRAYED
| MF_DISABLED
)))
2200 /* If TPM_RETURNCMD is set you return the id, but
2201 do not send a message to the owner */
2202 if(!(wFlags
& TPM_RETURNCMD
))
2204 if( menu
->wFlags
& MF_SYSMENU
)
2205 PostMessageA( pmt
->hOwnerWnd
, WM_SYSCOMMAND
, item
->wID
,
2206 MAKELPARAM((INT16
)pmt
->pt
.x
, (INT16
)pmt
->pt
.y
) );
2208 PostMessageA( pmt
->hOwnerWnd
, WM_COMMAND
, item
->wID
, 0 );
2214 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
, hMenu
, TRUE
, wFlags
);
2219 /***********************************************************************
2220 * MENU_SwitchTracking
2222 * Helper function for menu navigation routines.
2224 static void MENU_SwitchTracking( MTRACKER
* pmt
, HMENU hPtMenu
, UINT id
)
2226 POPUPMENU
*ptmenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hPtMenu
);
2227 POPUPMENU
*topmenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( pmt
->hTopMenu
);
2229 TRACE("%p hmenu=0x%04x 0x%04x\n", pmt
, hPtMenu
, id
);
2231 if( pmt
->hTopMenu
!= hPtMenu
&&
2232 !((ptmenu
->wFlags
| topmenu
->wFlags
) & MF_POPUP
) )
2234 /* both are top level menus (system and menu-bar) */
2235 MENU_HideSubPopups( pmt
->hOwnerWnd
, pmt
->hTopMenu
, FALSE
);
2236 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hTopMenu
, NO_SELECTED_ITEM
, FALSE
, 0 );
2237 pmt
->hTopMenu
= hPtMenu
;
2239 else MENU_HideSubPopups( pmt
->hOwnerWnd
, hPtMenu
, FALSE
);
2240 MENU_SelectItem( pmt
->hOwnerWnd
, hPtMenu
, id
, TRUE
, 0 );
2244 /***********************************************************************
2247 * Return TRUE if we can go on with menu tracking.
2249 static BOOL
MENU_ButtonDown( MTRACKER
* pmt
, HMENU hPtMenu
, UINT wFlags
)
2251 TRACE("%p hmenu=0x%04x\n", pmt
, hPtMenu
);
2256 POPUPMENU
*ptmenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hPtMenu
);
2259 if( IS_SYSTEM_MENU(ptmenu
) )
2260 item
= ptmenu
->items
;
2262 item
= MENU_FindItemByCoords( ptmenu
, pmt
->pt
, &id
);
2266 if( ptmenu
->FocusedItem
!= id
)
2267 MENU_SwitchTracking( pmt
, hPtMenu
, id
);
2269 /* If the popup menu is not already "popped" */
2270 if(!(item
->fState
& MF_MOUSESELECT
))
2272 pmt
->hCurrentMenu
= MENU_ShowSubPopup( pmt
->hOwnerWnd
, hPtMenu
, FALSE
, wFlags
);
2274 /* In win31, a newly popped menu always remain opened for the next buttonup */
2275 if(TWEAK_WineLook
== WIN31_LOOK
)
2276 ptmenu
->bTimeToHide
= FALSE
;
2281 /* Else the click was on the menu bar, finish the tracking */
2286 /***********************************************************************
2289 * Return the value of MENU_ExecFocusedItem if
2290 * the selected item was not a popup. Else open the popup.
2291 * A -1 return value indicates that we go on with menu tracking.
2294 static INT
MENU_ButtonUp( MTRACKER
* pmt
, HMENU hPtMenu
, UINT wFlags
)
2296 TRACE("%p hmenu=0x%04x\n", pmt
, hPtMenu
);
2301 POPUPMENU
*ptmenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hPtMenu
);
2304 if( IS_SYSTEM_MENU(ptmenu
) )
2305 item
= ptmenu
->items
;
2307 item
= MENU_FindItemByCoords( ptmenu
, pmt
->pt
, &id
);
2309 if( item
&& (ptmenu
->FocusedItem
== id
))
2311 if( !(item
->fType
& MF_POPUP
) )
2312 return MENU_ExecFocusedItem( pmt
, hPtMenu
, wFlags
);
2314 /* If we are dealing with the top-level menu and that this */
2315 /* is a click on an already "poppped" item */
2316 /* Stop the menu tracking and close the opened submenus */
2317 if((pmt
->hTopMenu
== hPtMenu
) && (ptmenu
->bTimeToHide
== TRUE
))
2320 ptmenu
->bTimeToHide
= TRUE
;
2326 /***********************************************************************
2329 * Return TRUE if we can go on with menu tracking.
2331 static BOOL
MENU_MouseMove( MTRACKER
* pmt
, HMENU hPtMenu
, UINT wFlags
)
2333 UINT id
= NO_SELECTED_ITEM
;
2334 POPUPMENU
*ptmenu
= NULL
;
2338 ptmenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hPtMenu
);
2339 if( IS_SYSTEM_MENU(ptmenu
) )
2342 MENU_FindItemByCoords( ptmenu
, pmt
->pt
, &id
);
2345 if( id
== NO_SELECTED_ITEM
)
2347 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hCurrentMenu
,
2348 NO_SELECTED_ITEM
, TRUE
, pmt
->hTopMenu
);
2351 else if( ptmenu
->FocusedItem
!= id
)
2353 MENU_SwitchTracking( pmt
, hPtMenu
, id
);
2354 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
, hPtMenu
, FALSE
, wFlags
);
2360 /***********************************************************************
2363 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
2365 static LRESULT
MENU_DoNextMenu( MTRACKER
* pmt
, UINT vk
)
2367 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( pmt
->hTopMenu
);
2369 if( (vk
== VK_LEFT
&& menu
->FocusedItem
== 0 ) ||
2370 (vk
== VK_RIGHT
&& menu
->FocusedItem
== menu
->nItems
- 1))
2376 LRESULT l
= SendMessageA( pmt
->hOwnerWnd
, WM_NEXTMENU
, vk
,
2377 (IS_SYSTEM_MENU(menu
)) ? GetSubMenu16(pmt
->hTopMenu
,0) : pmt
->hTopMenu
);
2379 TRACE("%04x [%04x] -> %04x [%04x]\n",
2380 (UINT16
)pmt
->hCurrentMenu
, (UINT16
)pmt
->hOwnerWnd
, LOWORD(l
), HIWORD(l
) );
2384 wndPtr
= WIN_FindWndPtr(pmt
->hOwnerWnd
);
2386 hNewWnd
= pmt
->hOwnerWnd
;
2387 if( IS_SYSTEM_MENU(menu
) )
2389 /* switch to the menu bar */
2391 if( wndPtr
->dwStyle
& WS_CHILD
|| !wndPtr
->wIDmenu
)
2393 WIN_ReleaseWndPtr(wndPtr
);
2397 hNewMenu
= wndPtr
->wIDmenu
;
2400 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hNewMenu
);
2401 id
= menu
->nItems
- 1;
2404 else if( wndPtr
->dwStyle
& WS_SYSMENU
)
2406 /* switch to the system menu */
2407 hNewMenu
= wndPtr
->hSysMenu
;
2411 WIN_ReleaseWndPtr(wndPtr
);
2414 WIN_ReleaseWndPtr(wndPtr
);
2416 else /* application returned a new menu to switch to */
2418 hNewMenu
= LOWORD(l
); hNewWnd
= HIWORD(l
);
2420 if( IsMenu(hNewMenu
) && IsWindow(hNewWnd
) )
2422 wndPtr
= WIN_FindWndPtr(hNewWnd
);
2424 if( wndPtr
->dwStyle
& WS_SYSMENU
&&
2425 GetSubMenu16(wndPtr
->hSysMenu
, 0) == hNewMenu
)
2427 /* get the real system menu */
2428 hNewMenu
= wndPtr
->hSysMenu
;
2430 else if( wndPtr
->dwStyle
& WS_CHILD
|| wndPtr
->wIDmenu
!= hNewMenu
)
2432 /* FIXME: Not sure what to do here, perhaps,
2433 * try to track hNewMenu as a popup? */
2435 TRACE(" -- got confused.\n");
2436 WIN_ReleaseWndPtr(wndPtr
);
2439 WIN_ReleaseWndPtr(wndPtr
);
2444 if( hNewMenu
!= pmt
->hTopMenu
)
2446 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hTopMenu
, NO_SELECTED_ITEM
,
2448 if( pmt
->hCurrentMenu
!= pmt
->hTopMenu
)
2449 MENU_HideSubPopups( pmt
->hOwnerWnd
, pmt
->hTopMenu
, FALSE
);
2452 if( hNewWnd
!= pmt
->hOwnerWnd
)
2455 pmt
->hOwnerWnd
= hNewWnd
;
2456 EVENT_Capture( pmt
->hOwnerWnd
, HTMENU
);
2459 pmt
->hTopMenu
= pmt
->hCurrentMenu
= hNewMenu
; /* all subpopups are hidden */
2460 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hTopMenu
, id
, TRUE
, 0 );
2467 /***********************************************************************
2470 * The idea is not to show the popup if the next input message is
2471 * going to hide it anyway.
2473 static BOOL
MENU_SuspendPopup( MTRACKER
* pmt
, UINT16 uMsg
)
2477 msg
.hwnd
= pmt
->hOwnerWnd
;
2479 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_REMOVE
);
2480 pmt
->trackFlags
|= TF_SKIPREMOVE
;
2485 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_NOREMOVE
);
2486 if( msg
.message
== WM_KEYUP
|| msg
.message
== WM_PAINT
)
2488 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_REMOVE
);
2489 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_NOREMOVE
);
2490 if( msg
.message
== WM_KEYDOWN
&&
2491 (msg
.wParam
== VK_LEFT
|| msg
.wParam
== VK_RIGHT
))
2493 pmt
->trackFlags
|= TF_SUSPENDPOPUP
;
2500 /* failures go through this */
2501 pmt
->trackFlags
&= ~TF_SUSPENDPOPUP
;
2505 /***********************************************************************
2508 * Handle a VK_LEFT key event in a menu.
2510 static void MENU_KeyLeft( MTRACKER
* pmt
, UINT wFlags
)
2513 HMENU hmenutmp
, hmenuprev
;
2516 hmenuprev
= hmenutmp
= pmt
->hTopMenu
;
2517 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenutmp
);
2519 /* Try to move 1 column left (if possible) */
2520 if( (prevcol
= MENU_GetStartOfPrevColumn( pmt
->hCurrentMenu
)) !=
2521 NO_SELECTED_ITEM
) {
2523 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hCurrentMenu
,
2528 /* close topmost popup */
2529 while (hmenutmp
!= pmt
->hCurrentMenu
)
2531 hmenuprev
= hmenutmp
;
2532 hmenutmp
= MENU_GetSubPopup( hmenuprev
);
2535 MENU_HideSubPopups( pmt
->hOwnerWnd
, hmenuprev
, TRUE
);
2536 pmt
->hCurrentMenu
= hmenuprev
;
2538 if ( (hmenuprev
== pmt
->hTopMenu
) && !(menu
->wFlags
& MF_POPUP
) )
2540 /* move menu bar selection if no more popups are left */
2542 if( !MENU_DoNextMenu( pmt
, VK_LEFT
) )
2543 MENU_MoveSelection( pmt
->hOwnerWnd
, pmt
->hTopMenu
, ITEM_PREV
);
2545 if ( hmenuprev
!= hmenutmp
|| pmt
->trackFlags
& TF_SUSPENDPOPUP
)
2547 /* A sublevel menu was displayed - display the next one
2548 * unless there is another displacement coming up */
2550 if( !MENU_SuspendPopup( pmt
, WM_KEYDOWN
) )
2551 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
,
2552 pmt
->hTopMenu
, TRUE
, wFlags
);
2558 /***********************************************************************
2561 * Handle a VK_RIGHT key event in a menu.
2563 static void MENU_KeyRight( MTRACKER
* pmt
, UINT wFlags
)
2566 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( pmt
->hTopMenu
);
2569 TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
2571 ((POPUPMENU
*)USER_HEAP_LIN_ADDR(pmt
->hCurrentMenu
))->
2573 pmt
->hTopMenu
, menu
->items
[0].text
);
2575 if ( (menu
->wFlags
& MF_POPUP
) || (pmt
->hCurrentMenu
!= pmt
->hTopMenu
))
2577 /* If already displaying a popup, try to display sub-popup */
2579 hmenutmp
= pmt
->hCurrentMenu
;
2580 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
, hmenutmp
, TRUE
, wFlags
);
2582 /* if subpopup was displayed then we are done */
2583 if (hmenutmp
!= pmt
->hCurrentMenu
) return;
2586 /* Check to see if there's another column */
2587 if( (nextcol
= MENU_GetStartOfNextColumn( pmt
->hCurrentMenu
)) !=
2588 NO_SELECTED_ITEM
) {
2589 TRACE("Going to %d.\n", nextcol
);
2590 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hCurrentMenu
,
2595 if (!(menu
->wFlags
& MF_POPUP
)) /* menu bar tracking */
2597 if( pmt
->hCurrentMenu
!= pmt
->hTopMenu
)
2599 MENU_HideSubPopups( pmt
->hOwnerWnd
, pmt
->hTopMenu
, FALSE
);
2600 hmenutmp
= pmt
->hCurrentMenu
= pmt
->hTopMenu
;
2601 } else hmenutmp
= 0;
2603 /* try to move to the next item */
2604 if( !MENU_DoNextMenu( pmt
, VK_RIGHT
) )
2605 MENU_MoveSelection( pmt
->hOwnerWnd
, pmt
->hTopMenu
, ITEM_NEXT
);
2607 if( hmenutmp
|| pmt
->trackFlags
& TF_SUSPENDPOPUP
)
2608 if( !MENU_SuspendPopup(pmt
, WM_KEYDOWN
) )
2609 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
,
2610 pmt
->hTopMenu
, TRUE
, wFlags
);
2614 /***********************************************************************
2617 * Menu tracking code.
2619 static INT
MENU_TrackMenu( HMENU hmenu
, UINT wFlags
, INT x
, INT y
,
2620 HWND hwnd
, const RECT
*lprect
)
2625 INT executedMenuId
= -1;
2627 BOOL enterIdleSent
= FALSE
;
2630 mt
.hCurrentMenu
= hmenu
;
2631 mt
.hTopMenu
= hmenu
;
2632 mt
.hOwnerWnd
= hwnd
;
2636 TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
2637 hmenu
, wFlags
, x
, y
, hwnd
, (lprect
) ? lprect
->left
: 0, (lprect
) ? lprect
->top
: 0,
2638 (lprect
) ? lprect
->right
: 0, (lprect
) ? lprect
->bottom
: 0);
2641 if (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
))) return FALSE
;
2643 if (wFlags
& TPM_BUTTONDOWN
) MENU_ButtonDown( &mt
, hmenu
, wFlags
);
2645 EVENT_Capture( mt
.hOwnerWnd
, HTMENU
);
2649 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( mt
.hCurrentMenu
);
2650 msg
.hwnd
= (wFlags
& TPM_ENTERIDLEEX
&& menu
->wFlags
& MF_POPUP
) ? menu
->hWnd
: 0;
2652 /* we have to keep the message in the queue until it's
2653 * clear that menu loop is not over yet. */
2655 if (!MSG_InternalGetMessage( QMSG_WIN32A
, &msg
, msg
.hwnd
, mt
.hOwnerWnd
,
2656 MSGF_MENU
, PM_NOREMOVE
, !enterIdleSent
, &enterIdleSent
)) break;
2658 TranslateMessage( &msg
);
2661 if ( (msg
.hwnd
==menu
->hWnd
) || (msg
.message
!=WM_TIMER
) )
2662 enterIdleSent
=FALSE
;
2665 if ((msg
.message
>= WM_MOUSEFIRST
) && (msg
.message
<= WM_MOUSELAST
))
2667 /* Find a menu for this mouse event */
2669 CONV_POINT32TO16( &msg
.pt
, &pt16
);
2670 hmenu
= MENU_PtMenu( mt
.hTopMenu
, pt16
);
2674 /* no WM_NC... messages in captured state */
2676 case WM_RBUTTONDBLCLK
:
2677 case WM_RBUTTONDOWN
:
2678 if (!(wFlags
& TPM_RIGHTBUTTON
)) break;
2680 case WM_LBUTTONDBLCLK
:
2681 case WM_LBUTTONDOWN
:
2682 /* If the message belongs to the menu, removes it from the queue */
2683 /* Else, end menu tracking */
2684 fRemove
= MENU_ButtonDown( &mt
, hmenu
, wFlags
);
2685 fEndMenu
= !fRemove
;
2689 if (!(wFlags
& TPM_RIGHTBUTTON
)) break;
2692 /* Check if a menu was selected by the mouse */
2695 executedMenuId
= MENU_ButtonUp( &mt
, hmenu
, wFlags
);
2697 /* End the loop if executedMenuId is an item ID */
2698 /* or if the job was done (executedMenuId = 0). */
2699 fEndMenu
= fRemove
= (executedMenuId
!= -1);
2701 /* No menu was selected by the mouse */
2702 /* if the function was called by TrackPopupMenu, continue
2703 with the menu tracking. If not, stop it */
2705 fEndMenu
= ((wFlags
& TPM_POPUPMENU
) ? FALSE
: TRUE
);
2710 /* In win95 winelook, the selected menu item must be changed every time the
2711 mouse moves. In Win31 winelook, the mouse button has to be held down */
2713 if ( (TWEAK_WineLook
> WIN31_LOOK
) ||
2714 ( (msg
.wParam
& MK_LBUTTON
) ||
2715 ((wFlags
& TPM_RIGHTBUTTON
) && (msg
.wParam
& MK_RBUTTON
))) )
2717 fEndMenu
|= !MENU_MouseMove( &mt
, hmenu
, wFlags
);
2719 } /* switch(msg.message) - mouse */
2721 else if ((msg
.message
>= WM_KEYFIRST
) && (msg
.message
<= WM_KEYLAST
))
2723 fRemove
= TRUE
; /* Keyboard messages are always removed */
2731 MENU_SelectItem( mt
.hOwnerWnd
, mt
.hCurrentMenu
,
2732 NO_SELECTED_ITEM
, FALSE
, 0 );
2735 MENU_MoveSelection( mt
.hOwnerWnd
, mt
.hCurrentMenu
,
2736 (msg
.wParam
== VK_HOME
)? ITEM_NEXT
: ITEM_PREV
);
2739 case VK_DOWN
: /* If on menu bar, pull-down the menu */
2741 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( mt
.hCurrentMenu
);
2742 if (!(menu
->wFlags
& MF_POPUP
))
2743 mt
.hCurrentMenu
= MENU_ShowSubPopup(mt
.hOwnerWnd
, mt
.hTopMenu
, TRUE
, wFlags
);
2744 else /* otherwise try to move selection */
2745 MENU_MoveSelection( mt
.hOwnerWnd
, mt
.hCurrentMenu
, ITEM_NEXT
);
2749 MENU_KeyLeft( &mt
, wFlags
);
2753 MENU_KeyRight( &mt
, wFlags
);
2763 break; /* WM_KEYDOWN */
2773 break; /* WM_SYSKEYDOWN */
2779 if (msg
.wParam
== '\r' || msg
.wParam
== ' ')
2781 executedMenuId
= MENU_ExecFocusedItem(&mt
,mt
.hCurrentMenu
, wFlags
);
2782 fEndMenu
= (executedMenuId
!= -1);
2787 /* Hack to avoid control chars. */
2788 /* We will find a better way real soon... */
2789 if ((msg
.wParam
<= 32) || (msg
.wParam
>= 127)) break;
2791 pos
= MENU_FindItemByKey( mt
.hOwnerWnd
, mt
.hCurrentMenu
,
2792 LOWORD(msg
.wParam
), FALSE
);
2793 if (pos
== (UINT
)-2) fEndMenu
= TRUE
;
2794 else if (pos
== (UINT
)-1) MessageBeep(0);
2797 MENU_SelectItem( mt
.hOwnerWnd
, mt
.hCurrentMenu
, pos
,
2799 executedMenuId
= MENU_ExecFocusedItem(&mt
,mt
.hCurrentMenu
, wFlags
);
2800 fEndMenu
= (executedMenuId
!= -1);
2804 } /* switch(msg.message) - kbd */
2808 DispatchMessageA( &msg
);
2811 if (!fEndMenu
) fRemove
= TRUE
;
2813 /* finally remove message from the queue */
2815 if (fRemove
&& !(mt
.trackFlags
& TF_SKIPREMOVE
) )
2816 PeekMessageA( &msg
, 0, msg
.message
, msg
.message
, PM_REMOVE
);
2817 else mt
.trackFlags
&= ~TF_SKIPREMOVE
;
2822 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( mt
.hTopMenu
);
2824 if( IsWindow( mt
.hOwnerWnd
) )
2826 MENU_HideSubPopups( mt
.hOwnerWnd
, mt
.hTopMenu
, FALSE
);
2828 if (menu
&& menu
->wFlags
& MF_POPUP
)
2830 ShowWindow( menu
->hWnd
, SW_HIDE
);
2833 MENU_SelectItem( mt
.hOwnerWnd
, mt
.hTopMenu
, NO_SELECTED_ITEM
, FALSE
, 0 );
2834 SendMessageA( mt
.hOwnerWnd
, WM_MENUSELECT
, MAKELONG(0,0xffff), 0 );
2837 /* Reset the variable for hiding menu */
2838 menu
->bTimeToHide
= FALSE
;
2840 /* The return value is only used by TrackPopupMenu */
2841 return ((executedMenuId
!= -1) ? executedMenuId
: 0);
2844 /***********************************************************************
2847 static BOOL
MENU_InitTracking(HWND hWnd
, HMENU hMenu
, BOOL bPopup
, UINT wFlags
)
2849 TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd
, hMenu
);
2853 /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
2854 if (!(wFlags
& TPM_NONOTIFY
))
2855 SendMessageA( hWnd
, WM_ENTERMENULOOP
, bPopup
, 0 );
2857 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
, HTCAPTION
);
2859 if (!(wFlags
& TPM_NONOTIFY
))
2860 SendMessageA( hWnd
, WM_INITMENU
, hMenu
, 0 );
2864 /***********************************************************************
2867 static BOOL
MENU_ExitTracking(HWND hWnd
)
2869 TRACE("hwnd=0x%04x\n", hWnd
);
2871 SendMessageA( hWnd
, WM_EXITMENULOOP
, 0, 0 );
2876 /***********************************************************************
2877 * MENU_TrackMouseMenuBar
2879 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2881 void MENU_TrackMouseMenuBar( WND
* wndPtr
, INT ht
, POINT pt
)
2883 HWND hWnd
= wndPtr
->hwndSelf
;
2884 HMENU hMenu
= (ht
== HTSYSMENU
) ? wndPtr
->hSysMenu
: wndPtr
->wIDmenu
;
2885 UINT wFlags
= TPM_ENTERIDLEEX
| TPM_BUTTONDOWN
| TPM_LEFTALIGN
| TPM_LEFTBUTTON
;
2887 TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr
, ht
, pt
.x
, pt
.y
);
2891 MENU_InitTracking( hWnd
, hMenu
, FALSE
, wFlags
);
2892 MENU_TrackMenu( hMenu
, wFlags
, pt
.x
, pt
.y
, hWnd
, NULL
);
2893 MENU_ExitTracking(hWnd
);
2898 /***********************************************************************
2899 * MENU_TrackKbdMenuBar
2901 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2903 void MENU_TrackKbdMenuBar( WND
* wndPtr
, UINT wParam
, INT vkey
)
2905 UINT uItem
= NO_SELECTED_ITEM
;
2907 UINT wFlags
= TPM_ENTERIDLEEX
| TPM_LEFTALIGN
| TPM_LEFTBUTTON
;
2909 /* find window that has a menu */
2911 while( wndPtr
->dwStyle
& WS_CHILD
)
2912 if( !(wndPtr
= wndPtr
->parent
) ) return;
2914 /* check if we have to track a system menu */
2916 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_MINIMIZE
)) ||
2917 !wndPtr
->wIDmenu
|| vkey
== VK_SPACE
)
2919 if( !(wndPtr
->dwStyle
& WS_SYSMENU
) ) return;
2920 hTrackMenu
= wndPtr
->hSysMenu
;
2922 wParam
|= HTSYSMENU
; /* prevent item lookup */
2925 hTrackMenu
= wndPtr
->wIDmenu
;
2927 if (IsMenu( hTrackMenu
))
2929 MENU_InitTracking( wndPtr
->hwndSelf
, hTrackMenu
, FALSE
, wFlags
);
2931 if( vkey
&& vkey
!= VK_SPACE
)
2933 uItem
= MENU_FindItemByKey( wndPtr
->hwndSelf
, hTrackMenu
,
2934 vkey
, (wParam
& HTSYSMENU
) );
2935 if( uItem
>= (UINT
)(-2) )
2937 if( uItem
== (UINT
)(-1) ) MessageBeep(0);
2944 MENU_SelectItem( wndPtr
->hwndSelf
, hTrackMenu
, uItem
, TRUE
, 0 );
2946 if( uItem
== NO_SELECTED_ITEM
)
2947 MENU_MoveSelection( wndPtr
->hwndSelf
, hTrackMenu
, ITEM_NEXT
);
2949 PostMessageA( wndPtr
->hwndSelf
, WM_KEYDOWN
, VK_DOWN
, 0L );
2951 MENU_TrackMenu( hTrackMenu
, wFlags
, 0, 0, wndPtr
->hwndSelf
, NULL
);
2954 MENU_ExitTracking (wndPtr
->hwndSelf
);
2959 /**********************************************************************
2960 * TrackPopupMenu16 (USER.416)
2962 BOOL16 WINAPI
TrackPopupMenu16( HMENU16 hMenu
, UINT16 wFlags
, INT16 x
, INT16 y
,
2963 INT16 nReserved
, HWND16 hWnd
, const RECT16
*lpRect
)
2967 CONV_RECT16TO32( lpRect
, &r
);
2968 return TrackPopupMenu( hMenu
, wFlags
, x
, y
, nReserved
, hWnd
,
2969 lpRect
? &r
: NULL
);
2973 /**********************************************************************
2974 * TrackPopupMenu (USER32.549)
2976 * Like the win32 API, the function return the command ID only if the
2977 * flag TPM_RETURNCMD is on.
2980 BOOL WINAPI
TrackPopupMenu( HMENU hMenu
, UINT wFlags
, INT x
, INT y
,
2981 INT nReserved
, HWND hWnd
, const RECT
*lpRect
)
2985 MENU_InitTracking(hWnd
, hMenu
, TRUE
, wFlags
);
2987 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2988 if (!(wFlags
& TPM_NONOTIFY
))
2989 SendMessageA( hWnd
, WM_INITMENUPOPUP
, hMenu
, 0);
2991 if (MENU_ShowPopup( hWnd
, hMenu
, 0, x
, y
, 0, 0 ))
2992 ret
= MENU_TrackMenu( hMenu
, wFlags
| TPM_POPUPMENU
, 0, 0, hWnd
, lpRect
);
2993 MENU_ExitTracking(hWnd
);
2995 if( (!(wFlags
& TPM_RETURNCMD
)) && (ret
!= FALSE
) )
3001 /**********************************************************************
3002 * TrackPopupMenuEx (USER32.550)
3004 BOOL WINAPI
TrackPopupMenuEx( HMENU hMenu
, UINT wFlags
, INT x
, INT y
,
3005 HWND hWnd
, LPTPMPARAMS lpTpm
)
3007 FIXME("not fully implemented\n" );
3008 return TrackPopupMenu( hMenu
, wFlags
, x
, y
, 0, hWnd
,
3009 lpTpm
? &lpTpm
->rcExclude
: NULL
);
3012 /***********************************************************************
3015 * NOTE: Windows has totally different (and undocumented) popup wndproc.
3017 LRESULT WINAPI
PopupMenuWndProc( HWND hwnd
, UINT message
, WPARAM wParam
,
3020 WND
* wndPtr
= WIN_FindWndPtr(hwnd
);
3023 TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
3024 hwnd
, message
, wParam
, lParam
);
3030 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
3031 SetWindowLongA( hwnd
, 0, (LONG
)cs
->lpCreateParams
);
3036 case WM_MOUSEACTIVATE
: /* We don't want to be activated */
3037 retvalue
= MA_NOACTIVATE
;
3043 BeginPaint( hwnd
, &ps
);
3044 MENU_DrawPopupMenu( hwnd
, ps
.hdc
,
3045 (HMENU
)GetWindowLongA( hwnd
, 0 ) );
3046 EndPaint( hwnd
, &ps
);
3056 /* zero out global pointer in case resident popup window
3057 * was somehow destroyed. */
3059 if(MENU_GetTopPopupWnd() )
3061 if( hwnd
== pTopPopupWnd
->hwndSelf
)
3063 ERR("resident popup destroyed!\n");
3065 MENU_DestroyTopPopupWnd();
3070 MENU_ReleaseTopPopupWnd();
3078 if( !(*(HMENU
*)wndPtr
->wExtra
) )
3079 ERR("no menu to display\n");
3082 *(HMENU
*)wndPtr
->wExtra
= 0;
3085 case MM_SETMENUHANDLE
:
3087 *(HMENU
*)wndPtr
->wExtra
= (HMENU
)wParam
;
3090 case MM_GETMENUHANDLE
:
3092 retvalue
= *(HMENU
*)wndPtr
->wExtra
;
3096 retvalue
= DefWindowProcA( hwnd
, message
, wParam
, lParam
);
3101 WIN_ReleaseWndPtr(wndPtr
);
3106 /***********************************************************************
3107 * MENU_GetMenuBarHeight
3109 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3111 UINT
MENU_GetMenuBarHeight( HWND hwnd
, UINT menubarWidth
,
3112 INT orgX
, INT orgY
)
3120 TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
3121 hwnd
, menubarWidth
, orgX
, orgY
);
3123 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
3126 if (!(lppop
= (LPPOPUPMENU
)USER_HEAP_LIN_ADDR((HMENU16
)wndPtr
->wIDmenu
)))
3128 WIN_ReleaseWndPtr(wndPtr
);
3132 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
3133 SelectObject( hdc
, hMenuFont
);
3134 SetRect(&rectBar
, orgX
, orgY
, orgX
+menubarWidth
, orgY
+GetSystemMetrics(SM_CYMENU
));
3135 MENU_MenuBarCalcSize( hdc
, &rectBar
, lppop
, hwnd
);
3136 ReleaseDC( hwnd
, hdc
);
3137 retvalue
= lppop
->Height
;
3138 WIN_ReleaseWndPtr(wndPtr
);
3143 /*******************************************************************
3144 * ChangeMenu16 (USER.153)
3146 BOOL16 WINAPI
ChangeMenu16( HMENU16 hMenu
, UINT16 pos
, SEGPTR data
,
3147 UINT16 id
, UINT16 flags
)
3149 TRACE("menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
3150 hMenu
, pos
, (DWORD
)data
, id
, flags
);
3151 if (flags
& MF_APPEND
) return AppendMenu16( hMenu
, flags
& ~MF_APPEND
,
3154 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
3155 /* for MF_DELETE. We should check the parameters for all others */
3156 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
3158 if (flags
& MF_DELETE
) return DeleteMenu16(hMenu
, pos
, flags
& ~MF_DELETE
);
3159 if (flags
& MF_CHANGE
) return ModifyMenu16(hMenu
, pos
, flags
& ~MF_CHANGE
,
3161 if (flags
& MF_REMOVE
) return RemoveMenu16(hMenu
,
3162 flags
& MF_BYPOSITION
? pos
: id
,
3163 flags
& ~MF_REMOVE
);
3164 /* Default: MF_INSERT */
3165 return InsertMenu16( hMenu
, pos
, flags
, id
, data
);
3169 /*******************************************************************
3170 * ChangeMenu32A (USER32.23)
3172 BOOL WINAPI
ChangeMenuA( HMENU hMenu
, UINT pos
, LPCSTR data
,
3173 UINT id
, UINT flags
)
3175 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3176 hMenu
, pos
, (DWORD
)data
, id
, flags
);
3177 if (flags
& MF_APPEND
) return AppendMenuA( hMenu
, flags
& ~MF_APPEND
,
3179 if (flags
& MF_DELETE
) return DeleteMenu(hMenu
, pos
, flags
& ~MF_DELETE
);
3180 if (flags
& MF_CHANGE
) return ModifyMenuA(hMenu
, pos
, flags
& ~MF_CHANGE
,
3182 if (flags
& MF_REMOVE
) return RemoveMenu( hMenu
,
3183 flags
& MF_BYPOSITION
? pos
: id
,
3184 flags
& ~MF_REMOVE
);
3185 /* Default: MF_INSERT */
3186 return InsertMenuA( hMenu
, pos
, flags
, id
, data
);
3190 /*******************************************************************
3191 * ChangeMenu32W (USER32.24)
3193 BOOL WINAPI
ChangeMenuW( HMENU hMenu
, UINT pos
, LPCWSTR data
,
3194 UINT id
, UINT flags
)
3196 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3197 hMenu
, pos
, (DWORD
)data
, id
, flags
);
3198 if (flags
& MF_APPEND
) return AppendMenuW( hMenu
, flags
& ~MF_APPEND
,
3200 if (flags
& MF_DELETE
) return DeleteMenu(hMenu
, pos
, flags
& ~MF_DELETE
);
3201 if (flags
& MF_CHANGE
) return ModifyMenuW(hMenu
, pos
, flags
& ~MF_CHANGE
,
3203 if (flags
& MF_REMOVE
) return RemoveMenu( hMenu
,
3204 flags
& MF_BYPOSITION
? pos
: id
,
3205 flags
& ~MF_REMOVE
);
3206 /* Default: MF_INSERT */
3207 return InsertMenuW( hMenu
, pos
, flags
, id
, data
);
3211 /*******************************************************************
3212 * CheckMenuItem16 (USER.154)
3214 BOOL16 WINAPI
CheckMenuItem16( HMENU16 hMenu
, UINT16 id
, UINT16 flags
)
3216 return (BOOL16
)CheckMenuItem( hMenu
, id
, flags
);
3220 /*******************************************************************
3221 * CheckMenuItem (USER32.46)
3223 DWORD WINAPI
CheckMenuItem( HMENU hMenu
, UINT id
, UINT flags
)
3228 TRACE("menu=%04x id=%04x flags=%04x\n", hMenu
, id
, flags
);
3229 if (!(item
= MENU_FindItem( &hMenu
, &id
, flags
))) return -1;
3230 ret
= item
->fState
& MF_CHECKED
;
3231 if (flags
& MF_CHECKED
) item
->fState
|= MF_CHECKED
;
3232 else item
->fState
&= ~MF_CHECKED
;
3237 /**********************************************************************
3238 * EnableMenuItem16 (USER.155)
3240 UINT16 WINAPI
EnableMenuItem16( HMENU16 hMenu
, UINT16 wItemID
, UINT16 wFlags
)
3242 return EnableMenuItem( hMenu
, wItemID
, wFlags
);
3246 /**********************************************************************
3247 * EnableMenuItem32 (USER32.170)
3249 UINT WINAPI
EnableMenuItem( HMENU hMenu
, UINT wItemID
, UINT wFlags
)
3255 TRACE("(%04x, %04X, %04X) !\n",
3256 hMenu
, wItemID
, wFlags
);
3258 /* Get the Popupmenu to access the owner menu */
3259 if (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
)))
3262 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
)))
3265 oldflags
= item
->fState
& (MF_GRAYED
| MF_DISABLED
);
3266 item
->fState
^= (oldflags
^ wFlags
) & (MF_GRAYED
| MF_DISABLED
);
3268 /* In win95 if the close item in the system menu change update the close button */
3269 if (TWEAK_WineLook
== WIN95_LOOK
)
3270 if((item
->wID
== SC_CLOSE
) && (oldflags
!= wFlags
))
3272 if (menu
->hSysMenuOwner
!= 0)
3274 POPUPMENU
* parentMenu
;
3276 /* Get the parent menu to access*/
3277 if (!(parentMenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(menu
->hSysMenuOwner
)))
3280 /* Refresh the frame to reflect the change*/
3281 SetWindowPos(parentMenu
->hWnd
, 0, 0, 0, 0, 0,
3282 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
);
3290 /*******************************************************************
3291 * GetMenuString16 (USER.161)
3293 INT16 WINAPI
GetMenuString16( HMENU16 hMenu
, UINT16 wItemID
,
3294 LPSTR str
, INT16 nMaxSiz
, UINT16 wFlags
)
3296 return GetMenuStringA( hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
3300 /*******************************************************************
3301 * GetMenuString32A (USER32.268)
3303 INT WINAPI
GetMenuStringA( HMENU hMenu
, UINT wItemID
,
3304 LPSTR str
, INT nMaxSiz
, UINT wFlags
)
3308 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3309 hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
3310 if (!str
|| !nMaxSiz
) return 0;
3312 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return 0;
3313 if (!IS_STRING_ITEM(item
->fType
)) return 0;
3314 lstrcpynA( str
, item
->text
, nMaxSiz
);
3315 TRACE("returning '%s'\n", str
);
3320 /*******************************************************************
3321 * GetMenuString32W (USER32.269)
3323 INT WINAPI
GetMenuStringW( HMENU hMenu
, UINT wItemID
,
3324 LPWSTR str
, INT nMaxSiz
, UINT wFlags
)
3328 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3329 hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
3330 if (!str
|| !nMaxSiz
) return 0;
3332 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return 0;
3333 if (!IS_STRING_ITEM(item
->fType
)) return 0;
3334 lstrcpynAtoW( str
, item
->text
, nMaxSiz
);
3335 return lstrlenW(str
);
3339 /**********************************************************************
3340 * HiliteMenuItem16 (USER.162)
3342 BOOL16 WINAPI
HiliteMenuItem16( HWND16 hWnd
, HMENU16 hMenu
, UINT16 wItemID
,
3345 return HiliteMenuItem( hWnd
, hMenu
, wItemID
, wHilite
);
3349 /**********************************************************************
3350 * HiliteMenuItem32 (USER32.318)
3352 BOOL WINAPI
HiliteMenuItem( HWND hWnd
, HMENU hMenu
, UINT wItemID
,
3356 TRACE("(%04x, %04x, %04x, %04x);\n",
3357 hWnd
, hMenu
, wItemID
, wHilite
);
3358 if (!MENU_FindItem( &hMenu
, &wItemID
, wHilite
)) return FALSE
;
3359 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
))) return FALSE
;
3360 if (menu
->FocusedItem
== wItemID
) return TRUE
;
3361 MENU_HideSubPopups( hWnd
, hMenu
, FALSE
);
3362 MENU_SelectItem( hWnd
, hMenu
, wItemID
, TRUE
, 0 );
3367 /**********************************************************************
3368 * GetMenuState16 (USER.250)
3370 UINT16 WINAPI
GetMenuState16( HMENU16 hMenu
, UINT16 wItemID
, UINT16 wFlags
)
3372 return GetMenuState( hMenu
, wItemID
, wFlags
);
3376 /**********************************************************************
3377 * GetMenuState (USER32.267)
3379 UINT WINAPI
GetMenuState( HMENU hMenu
, UINT wItemID
, UINT wFlags
)
3382 TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
3383 hMenu
, wItemID
, wFlags
);
3384 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return -1;
3385 debug_print_menuitem (" item: ", item
, "");
3386 if (item
->fType
& MF_POPUP
)
3388 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( item
->hSubMenu
);
3389 if (!menu
) return -1;
3390 else return (menu
->nItems
<< 8) | ((item
->fState
|item
->fType
) & 0xff);
3394 /* We used to (from way back then) mask the result to 0xff. */
3395 /* I don't know why and it seems wrong as the documented */
3396 /* return flag MF_SEPARATOR is outside that mask. */
3397 return (item
->fType
| item
->fState
);
3402 /**********************************************************************
3403 * GetMenuItemCount16 (USER.263)
3405 INT16 WINAPI
GetMenuItemCount16( HMENU16 hMenu
)
3407 LPPOPUPMENU menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
);
3408 if (!IS_A_MENU(menu
)) return -1;
3409 TRACE("(%04x) returning %d\n",
3410 hMenu
, menu
->nItems
);
3411 return menu
->nItems
;
3415 /**********************************************************************
3416 * GetMenuItemCount32 (USER32.262)
3418 INT WINAPI
GetMenuItemCount( HMENU hMenu
)
3420 LPPOPUPMENU menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
);
3421 if (!IS_A_MENU(menu
)) return -1;
3422 TRACE("(%04x) returning %d\n",
3423 hMenu
, menu
->nItems
);
3424 return menu
->nItems
;
3427 /**********************************************************************
3428 * GetMenuItemID16 (USER.264)
3430 UINT16 WINAPI
GetMenuItemID16( HMENU16 hMenu
, INT16 nPos
)
3432 return (UINT16
) GetMenuItemID (hMenu
, nPos
);
3435 /**********************************************************************
3436 * GetMenuItemID32 (USER32.263)
3438 UINT WINAPI
GetMenuItemID( HMENU hMenu
, INT nPos
)
3442 if (!(lpmi
= MENU_FindItem(&hMenu
,&nPos
,MF_BYPOSITION
))) return 0;
3443 if (lpmi
->fType
& MF_POPUP
) return -1;
3448 /*******************************************************************
3449 * InsertMenu16 (USER.410)
3451 BOOL16 WINAPI
InsertMenu16( HMENU16 hMenu
, UINT16 pos
, UINT16 flags
,
3452 UINT16 id
, SEGPTR data
)
3454 UINT pos32
= (UINT
)pos
;
3455 if ((pos
== (UINT16
)-1) && (flags
& MF_BYPOSITION
)) pos32
= (UINT
)-1;
3456 if (IS_STRING_ITEM(flags
) && data
)
3457 return InsertMenuA( hMenu
, pos32
, flags
, id
,
3458 (LPSTR
)PTR_SEG_TO_LIN(data
) );
3459 return InsertMenuA( hMenu
, pos32
, flags
, id
, (LPSTR
)data
);
3463 /*******************************************************************
3464 * InsertMenu32A (USER32.322)
3466 BOOL WINAPI
InsertMenuA( HMENU hMenu
, UINT pos
, UINT flags
,
3467 UINT id
, LPCSTR str
)
3471 if (IS_STRING_ITEM(flags
) && str
)
3472 TRACE("hMenu %04x, pos %d, flags %08x, "
3473 "id %04x, str '%s'\n",
3474 hMenu
, pos
, flags
, id
, str
);
3475 else TRACE("hMenu %04x, pos %d, flags %08x, "
3476 "id %04x, str %08lx (not a string)\n",
3477 hMenu
, pos
, flags
, id
, (DWORD
)str
);
3479 if (!(item
= MENU_InsertItem( hMenu
, pos
, flags
))) return FALSE
;
3481 if (!(MENU_SetItemData( item
, flags
, id
, str
)))
3483 RemoveMenu( hMenu
, pos
, flags
);
3487 if (flags
& MF_POPUP
) /* Set the MF_POPUP flag on the popup-menu */
3488 ((POPUPMENU
*)USER_HEAP_LIN_ADDR((HMENU16
)id
))->wFlags
|= MF_POPUP
;
3490 item
->hCheckBit
= item
->hUnCheckBit
= 0;
3495 /*******************************************************************
3496 * InsertMenu32W (USER32.325)
3498 BOOL WINAPI
InsertMenuW( HMENU hMenu
, UINT pos
, UINT flags
,
3499 UINT id
, LPCWSTR str
)
3503 if (IS_STRING_ITEM(flags
) && str
)
3505 LPSTR newstr
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
3506 ret
= InsertMenuA( hMenu
, pos
, flags
, id
, newstr
);
3507 HeapFree( GetProcessHeap(), 0, newstr
);
3510 else return InsertMenuA( hMenu
, pos
, flags
, id
, (LPCSTR
)str
);
3514 /*******************************************************************
3515 * AppendMenu16 (USER.411)
3517 BOOL16 WINAPI
AppendMenu16(HMENU16 hMenu
, UINT16 flags
, UINT16 id
, SEGPTR data
)
3519 return InsertMenu16( hMenu
, -1, flags
| MF_BYPOSITION
, id
, data
);
3523 /*******************************************************************
3524 * AppendMenu32A (USER32.5)
3526 BOOL WINAPI
AppendMenuA( HMENU hMenu
, UINT flags
,
3527 UINT id
, LPCSTR data
)
3529 return InsertMenuA( hMenu
, -1, flags
| MF_BYPOSITION
, id
, data
);
3533 /*******************************************************************
3534 * AppendMenu32W (USER32.6)
3536 BOOL WINAPI
AppendMenuW( HMENU hMenu
, UINT flags
,
3537 UINT id
, LPCWSTR data
)
3539 return InsertMenuW( hMenu
, -1, flags
| MF_BYPOSITION
, id
, data
);
3543 /**********************************************************************
3544 * RemoveMenu16 (USER.412)
3546 BOOL16 WINAPI
RemoveMenu16( HMENU16 hMenu
, UINT16 nPos
, UINT16 wFlags
)
3548 return RemoveMenu( hMenu
, nPos
, wFlags
);
3552 /**********************************************************************
3553 * RemoveMenu (USER32.441)
3555 BOOL WINAPI
RemoveMenu( HMENU hMenu
, UINT nPos
, UINT wFlags
)
3560 TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu
, nPos
, wFlags
);
3561 if (!(item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
3562 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
))) return FALSE
;
3566 MENU_FreeItemData( item
);
3568 if (--menu
->nItems
== 0)
3570 HeapFree( SystemHeap
, 0, menu
->items
);
3575 while(nPos
< menu
->nItems
)
3581 menu
->items
= HeapReAlloc( SystemHeap
, 0, menu
->items
,
3582 menu
->nItems
* sizeof(MENUITEM
) );
3588 /**********************************************************************
3589 * DeleteMenu16 (USER.413)
3591 BOOL16 WINAPI
DeleteMenu16( HMENU16 hMenu
, UINT16 nPos
, UINT16 wFlags
)
3593 return DeleteMenu( hMenu
, nPos
, wFlags
);
3597 /**********************************************************************
3598 * DeleteMenu32 (USER32.129)
3600 BOOL WINAPI
DeleteMenu( HMENU hMenu
, UINT nPos
, UINT wFlags
)
3602 MENUITEM
*item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
);
3603 if (!item
) return FALSE
;
3604 if (item
->fType
& MF_POPUP
) DestroyMenu( item
->hSubMenu
);
3605 /* nPos is now the position of the item */
3606 RemoveMenu( hMenu
, nPos
, wFlags
| MF_BYPOSITION
);
3611 /*******************************************************************
3612 * ModifyMenu16 (USER.414)
3614 BOOL16 WINAPI
ModifyMenu16( HMENU16 hMenu
, UINT16 pos
, UINT16 flags
,
3615 UINT16 id
, SEGPTR data
)
3617 if (IS_STRING_ITEM(flags
))
3618 return ModifyMenuA( hMenu
, pos
, flags
, id
,
3619 (LPSTR
)PTR_SEG_TO_LIN(data
) );
3620 return ModifyMenuA( hMenu
, pos
, flags
, id
, (LPSTR
)data
);
3624 /*******************************************************************
3625 * ModifyMenu32A (USER32.397)
3627 BOOL WINAPI
ModifyMenuA( HMENU hMenu
, UINT pos
, UINT flags
,
3628 UINT id
, LPCSTR str
)
3632 if (IS_STRING_ITEM(flags
))
3634 TRACE("%04x %d %04x %04x '%s'\n",
3635 hMenu
, pos
, flags
, id
, str
? str
: "#NULL#" );
3636 if (!str
) return FALSE
;
3640 TRACE("%04x %d %04x %04x %08lx\n",
3641 hMenu
, pos
, flags
, id
, (DWORD
)str
);
3644 if (!(item
= MENU_FindItem( &hMenu
, &pos
, flags
))) return FALSE
;
3645 return MENU_SetItemData( item
, flags
, id
, str
);
3649 /*******************************************************************
3650 * ModifyMenu32W (USER32.398)
3652 BOOL WINAPI
ModifyMenuW( HMENU hMenu
, UINT pos
, UINT flags
,
3653 UINT id
, LPCWSTR str
)
3657 if (IS_STRING_ITEM(flags
) && str
)
3659 LPSTR newstr
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
3660 ret
= ModifyMenuA( hMenu
, pos
, flags
, id
, newstr
);
3661 HeapFree( GetProcessHeap(), 0, newstr
);
3664 else return ModifyMenuA( hMenu
, pos
, flags
, id
, (LPCSTR
)str
);
3668 /**********************************************************************
3669 * CreatePopupMenu16 (USER.415)
3671 HMENU16 WINAPI
CreatePopupMenu16(void)
3673 return CreatePopupMenu();
3677 /**********************************************************************
3678 * CreatePopupMenu32 (USER32.82)
3680 HMENU WINAPI
CreatePopupMenu(void)
3685 if (!(hmenu
= CreateMenu())) return 0;
3686 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
3687 menu
->wFlags
|= MF_POPUP
;
3688 menu
->bTimeToHide
= FALSE
;
3693 /**********************************************************************
3694 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
3696 DWORD WINAPI
GetMenuCheckMarkDimensions(void)
3698 return MAKELONG( check_bitmap_width
, check_bitmap_height
);
3702 /**********************************************************************
3703 * SetMenuItemBitmaps16 (USER.418)
3705 BOOL16 WINAPI
SetMenuItemBitmaps16( HMENU16 hMenu
, UINT16 nPos
, UINT16 wFlags
,
3706 HBITMAP16 hNewUnCheck
, HBITMAP16 hNewCheck
)
3708 return SetMenuItemBitmaps( hMenu
, nPos
, wFlags
, hNewUnCheck
, hNewCheck
);
3712 /**********************************************************************
3713 * SetMenuItemBitmaps32 (USER32.490)
3715 BOOL WINAPI
SetMenuItemBitmaps( HMENU hMenu
, UINT nPos
, UINT wFlags
,
3716 HBITMAP hNewUnCheck
, HBITMAP hNewCheck
)
3719 TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
3720 hMenu
, nPos
, wFlags
, hNewCheck
, hNewUnCheck
);
3721 if (!(item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
3723 if (!hNewCheck
&& !hNewUnCheck
)
3725 item
->fState
&= ~MF_USECHECKBITMAPS
;
3727 else /* Install new bitmaps */
3729 item
->hCheckBit
= hNewCheck
;
3730 item
->hUnCheckBit
= hNewUnCheck
;
3731 item
->fState
|= MF_USECHECKBITMAPS
;
3737 /**********************************************************************
3738 * CreateMenu16 (USER.151)
3740 HMENU16 WINAPI
CreateMenu16(void)
3742 return CreateMenu();
3746 /**********************************************************************
3747 * CreateMenu (USER32.81)
3749 HMENU WINAPI
CreateMenu(void)
3753 if (!(hMenu
= USER_HEAP_ALLOC( sizeof(POPUPMENU
) ))) return 0;
3754 menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
);
3756 ZeroMemory(menu
, sizeof(POPUPMENU
));
3757 menu
->wMagic
= MENU_MAGIC
;
3758 menu
->FocusedItem
= NO_SELECTED_ITEM
;
3759 menu
->bTimeToHide
= FALSE
;
3761 TRACE("return %04x\n", hMenu
);
3767 /**********************************************************************
3768 * DestroyMenu16 (USER.152)
3770 BOOL16 WINAPI
DestroyMenu16( HMENU16 hMenu
)
3772 return DestroyMenu( hMenu
);
3776 /**********************************************************************
3777 * DestroyMenu32 (USER32.134)
3779 BOOL WINAPI
DestroyMenu( HMENU hMenu
)
3781 TRACE("(%04x)\n", hMenu
);
3783 /* Silently ignore attempts to destroy default system popup */
3785 if (hMenu
&& hMenu
!= MENU_DefSysPopup
)
3787 LPPOPUPMENU lppop
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
);
3788 WND
*pTPWnd
= MENU_GetTopPopupWnd();
3790 if( pTPWnd
&& (hMenu
== *(HMENU
*)pTPWnd
->wExtra
) )
3791 *(UINT
*)pTPWnd
->wExtra
= 0;
3793 if (IS_A_MENU( lppop
))
3795 lppop
->wMagic
= 0; /* Mark it as destroyed */
3797 if ((lppop
->wFlags
& MF_POPUP
) && lppop
->hWnd
&&
3798 (!pTPWnd
|| (lppop
->hWnd
!= pTPWnd
->hwndSelf
)))
3799 DestroyWindow( lppop
->hWnd
);
3801 if (lppop
->items
) /* recursively destroy submenus */
3804 MENUITEM
*item
= lppop
->items
;
3805 for (i
= lppop
->nItems
; i
> 0; i
--, item
++)
3807 if (item
->fType
& MF_POPUP
) DestroyMenu(item
->hSubMenu
);
3808 MENU_FreeItemData( item
);
3810 HeapFree( SystemHeap
, 0, lppop
->items
);
3812 USER_HEAP_FREE( hMenu
);
3813 MENU_ReleaseTopPopupWnd();
3817 MENU_ReleaseTopPopupWnd();
3821 return (hMenu
!= MENU_DefSysPopup
);
3825 /**********************************************************************
3826 * GetSystemMenu16 (USER.156)
3828 HMENU16 WINAPI
GetSystemMenu16( HWND16 hWnd
, BOOL16 bRevert
)
3830 return GetSystemMenu( hWnd
, bRevert
);
3834 /**********************************************************************
3835 * GetSystemMenu32 (USER32.291)
3837 HMENU WINAPI
GetSystemMenu( HWND hWnd
, BOOL bRevert
)
3839 WND
*wndPtr
= WIN_FindWndPtr( hWnd
);
3844 if( wndPtr
->hSysMenu
)
3848 DestroyMenu(wndPtr
->hSysMenu
);
3849 wndPtr
->hSysMenu
= 0;
3853 POPUPMENU
*menu
= (POPUPMENU
*)
3854 USER_HEAP_LIN_ADDR(wndPtr
->hSysMenu
);
3855 if( IS_A_MENU(menu
) )
3857 if( menu
->nItems
> 0 && menu
->items
[0].hSubMenu
== MENU_DefSysPopup
)
3858 menu
->items
[0].hSubMenu
= MENU_CopySysPopup();
3862 WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
3863 wndPtr
->hSysMenu
, hWnd
);
3864 wndPtr
->hSysMenu
= 0;
3869 if(!wndPtr
->hSysMenu
&& (wndPtr
->dwStyle
& WS_SYSMENU
) )
3870 wndPtr
->hSysMenu
= MENU_GetSysMenu( hWnd
, (HMENU
)(-1) );
3872 if( wndPtr
->hSysMenu
)
3875 retvalue
= GetSubMenu16(wndPtr
->hSysMenu
, 0);
3877 /* Store the dummy sysmenu handle to facilitate the refresh */
3878 /* of the close button if the SC_CLOSE item change */
3879 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(retvalue
);
3880 if ( IS_A_MENU(menu
) )
3881 menu
->hSysMenuOwner
= wndPtr
->hSysMenu
;
3883 WIN_ReleaseWndPtr(wndPtr
);
3889 /*******************************************************************
3890 * SetSystemMenu16 (USER.280)
3892 BOOL16 WINAPI
SetSystemMenu16( HWND16 hwnd
, HMENU16 hMenu
)
3894 return SetSystemMenu( hwnd
, hMenu
);
3898 /*******************************************************************
3899 * SetSystemMenu32 (USER32.508)
3901 BOOL WINAPI
SetSystemMenu( HWND hwnd
, HMENU hMenu
)
3903 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3907 if (wndPtr
->hSysMenu
) DestroyMenu( wndPtr
->hSysMenu
);
3908 wndPtr
->hSysMenu
= MENU_GetSysMenu( hwnd
, hMenu
);
3909 WIN_ReleaseWndPtr(wndPtr
);
3916 /**********************************************************************
3917 * GetMenu16 (USER.157)
3919 HMENU16 WINAPI
GetMenu16( HWND16 hWnd
)
3921 return (HMENU16
)GetMenu(hWnd
);
3925 /**********************************************************************
3926 * GetMenu32 (USER32.257)
3928 HMENU WINAPI
GetMenu( HWND hWnd
)
3931 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
3932 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
))
3934 retvalue
= (HMENU
)wndPtr
->wIDmenu
;
3939 WIN_ReleaseWndPtr(wndPtr
);
3944 /**********************************************************************
3945 * SetMenu16 (USER.158)
3947 BOOL16 WINAPI
SetMenu16( HWND16 hWnd
, HMENU16 hMenu
)
3949 return SetMenu( hWnd
, hMenu
);
3953 /**********************************************************************
3954 * SetMenu32 (USER32.487)
3956 BOOL WINAPI
SetMenu( HWND hWnd
, HMENU hMenu
)
3958 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
3960 TRACE("(%04x, %04x);\n", hWnd
, hMenu
);
3962 if (hMenu
&& !IsMenu(hMenu
))
3964 WARN("hMenu is not a menu handle\n");
3969 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
))
3971 if (GetCapture() == hWnd
) ReleaseCapture();
3973 wndPtr
->wIDmenu
= (UINT
)hMenu
;
3978 if (!(lpmenu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
)))
3980 WIN_ReleaseWndPtr(wndPtr
);
3983 lpmenu
->hWnd
= hWnd
;
3984 lpmenu
->wFlags
&= ~MF_POPUP
; /* Can't be a popup */
3985 lpmenu
->Height
= 0; /* Make sure we recalculate the size */
3987 if (IsWindowVisible(hWnd
))
3988 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3989 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3990 WIN_ReleaseWndPtr(wndPtr
);
3993 WIN_ReleaseWndPtr(wndPtr
);
3999 /**********************************************************************
4000 * GetSubMenu16 (USER.159)
4002 HMENU16 WINAPI
GetSubMenu16( HMENU16 hMenu
, INT16 nPos
)
4004 return GetSubMenu( hMenu
, nPos
);
4008 /**********************************************************************
4009 * GetSubMenu32 (USER32.288)
4011 HMENU WINAPI
GetSubMenu( HMENU hMenu
, INT nPos
)
4015 if (!(lpmi
= MENU_FindItem(&hMenu
,&nPos
,MF_BYPOSITION
))) return 0;
4016 if (!(lpmi
->fType
& MF_POPUP
)) return 0;
4017 return lpmi
->hSubMenu
;
4021 /**********************************************************************
4022 * DrawMenuBar16 (USER.160)
4024 void WINAPI
DrawMenuBar16( HWND16 hWnd
)
4026 DrawMenuBar( hWnd
);
4030 /**********************************************************************
4031 * DrawMenuBar (USER32.161)
4033 BOOL WINAPI
DrawMenuBar( HWND hWnd
)
4036 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
4037 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
) && wndPtr
->wIDmenu
)
4039 lppop
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR((HMENU16
)wndPtr
->wIDmenu
);
4042 WIN_ReleaseWndPtr(wndPtr
);
4046 lppop
->Height
= 0; /* Make sure we call MENU_MenuBarCalcSize */
4047 lppop
->hwndOwner
= hWnd
;
4048 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4049 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4050 WIN_ReleaseWndPtr(wndPtr
);
4053 WIN_ReleaseWndPtr(wndPtr
);
4058 /***********************************************************************
4059 * EndMenu (USER.187) (USER32.175)
4061 void WINAPI
EndMenu(void)
4064 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
4071 /***********************************************************************
4072 * LookupMenuHandle (USER.217)
4074 HMENU16 WINAPI
LookupMenuHandle16( HMENU16 hmenu
, INT16 id
)
4076 HMENU hmenu32
= hmenu
;
4078 if (!MENU_FindItem( &hmenu32
, &id32
, MF_BYCOMMAND
)) return 0;
4079 else return hmenu32
;
4083 /**********************************************************************
4084 * LoadMenu16 (USER.150)
4086 HMENU16 WINAPI
LoadMenu16( HINSTANCE16 instance
, SEGPTR name
)
4094 char *str
= (char *)PTR_SEG_TO_LIN( name
);
4095 TRACE("(%04x,'%s')\n", instance
, str
);
4096 if (str
[0] == '#') name
= (SEGPTR
)atoi( str
+ 1 );
4099 TRACE("(%04x,%04x)\n",instance
,LOWORD(name
));
4101 if (!name
) return 0;
4103 /* check for Win32 module */
4104 if (HIWORD(instance
))
4105 return LoadMenuA(instance
,PTR_SEG_TO_LIN(name
));
4106 instance
= GetExePtr( instance
);
4108 if (!(hRsrc
= FindResource16( instance
, name
, RT_MENU16
))) return 0;
4109 if (!(handle
= LoadResource16( instance
, hRsrc
))) return 0;
4110 hMenu
= LoadMenuIndirect16(LockResource16(handle
));
4111 FreeResource16( handle
);
4116 /*****************************************************************
4117 * LoadMenu32A (USER32.370)
4119 HMENU WINAPI
LoadMenuA( HINSTANCE instance
, LPCSTR name
)
4121 HRSRC hrsrc
= FindResourceA( instance
, name
, RT_MENUA
);
4122 if (!hrsrc
) return 0;
4123 return LoadMenuIndirectA( (LPCVOID
)LoadResource( instance
, hrsrc
));
4127 /*****************************************************************
4128 * LoadMenu32W (USER32.373)
4130 HMENU WINAPI
LoadMenuW( HINSTANCE instance
, LPCWSTR name
)
4132 HRSRC hrsrc
= FindResourceW( instance
, name
, RT_MENUW
);
4133 if (!hrsrc
) return 0;
4134 return LoadMenuIndirectW( (LPCVOID
)LoadResource( instance
, hrsrc
));
4138 /**********************************************************************
4139 * LoadMenuIndirect16 (USER.220)
4141 HMENU16 WINAPI
LoadMenuIndirect16( LPCVOID
template )
4144 WORD version
, offset
;
4145 LPCSTR p
= (LPCSTR
)template;
4147 TRACE("(%p)\n", template );
4148 version
= GET_WORD(p
);
4152 WARN("version must be 0 for Win16\n" );
4155 offset
= GET_WORD(p
);
4156 p
+= sizeof(WORD
) + offset
;
4157 if (!(hMenu
= CreateMenu())) return 0;
4158 if (!MENU_ParseResource( p
, hMenu
, FALSE
))
4160 DestroyMenu( hMenu
);
4167 /**********************************************************************
4168 * LoadMenuIndirect32A (USER32.371)
4170 HMENU WINAPI
LoadMenuIndirectA( LPCVOID
template )
4173 WORD version
, offset
;
4174 LPCSTR p
= (LPCSTR
)template;
4176 TRACE("%p\n", template );
4177 version
= GET_WORD(p
);
4182 offset
= GET_WORD(p
);
4183 p
+= sizeof(WORD
) + offset
;
4184 if (!(hMenu
= CreateMenu())) return 0;
4185 if (!MENU_ParseResource( p
, hMenu
, TRUE
))
4187 DestroyMenu( hMenu
);
4192 offset
= GET_WORD(p
);
4193 p
+= sizeof(WORD
) + offset
;
4194 if (!(hMenu
= CreateMenu())) return 0;
4195 if (!MENUEX_ParseResource( p
, hMenu
))
4197 DestroyMenu( hMenu
);
4202 ERR("version %d not supported.\n", version
);
4208 /**********************************************************************
4209 * LoadMenuIndirect32W (USER32.372)
4211 HMENU WINAPI
LoadMenuIndirectW( LPCVOID
template )
4213 /* FIXME: is there anything different between A and W? */
4214 return LoadMenuIndirectA( template );
4218 /**********************************************************************
4219 * IsMenu16 (USER.358)
4221 BOOL16 WINAPI
IsMenu16( HMENU16 hmenu
)
4223 LPPOPUPMENU menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hmenu
);
4224 return IS_A_MENU(menu
);
4228 /**********************************************************************
4229 * IsMenu32 (USER32.346)
4231 BOOL WINAPI
IsMenu(HMENU hmenu
)
4233 LPPOPUPMENU menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hmenu
);
4234 return IS_A_MENU(menu
);
4237 /**********************************************************************
4238 * GetMenuItemInfo32_common
4241 static BOOL
GetMenuItemInfo_common ( HMENU hmenu
, UINT item
, BOOL bypos
,
4242 LPMENUITEMINFOA lpmii
, BOOL unicode
)
4244 MENUITEM
*menu
= MENU_FindItem (&hmenu
, &item
, bypos
? MF_BYPOSITION
: 0);
4246 debug_print_menuitem("GetMenuItemInfo32_common: ", menu
, "");
4251 if (lpmii
->fMask
& MIIM_TYPE
) {
4252 lpmii
->fType
= menu
->fType
;
4253 switch (MENU_ITEM_TYPE(menu
->fType
)) {
4255 if (menu
->text
&& lpmii
->dwTypeData
&& lpmii
->cch
) {
4257 lstrcpynAtoW((LPWSTR
) lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4258 lpmii
->cch
= lstrlenW((LPWSTR
)menu
->text
);
4260 lstrcpynA(lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4261 lpmii
->cch
= lstrlenA(menu
->text
);
4267 lpmii
->dwTypeData
= menu
->text
;
4274 if (lpmii
->fMask
& MIIM_STRING
) {
4276 lstrcpynAtoW((LPWSTR
) lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4277 lpmii
->cch
= lstrlenW((LPWSTR
)menu
->text
);
4279 lstrcpynA(lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4280 lpmii
->cch
= lstrlenA(menu
->text
);
4284 if (lpmii
->fMask
& MIIM_FTYPE
)
4285 lpmii
->fType
= menu
->fType
;
4287 if (lpmii
->fMask
& MIIM_BITMAP
)
4288 lpmii
->hbmpItem
= menu
->hbmpItem
;
4290 if (lpmii
->fMask
& MIIM_STATE
)
4291 lpmii
->fState
= menu
->fState
;
4293 if (lpmii
->fMask
& MIIM_ID
)
4294 lpmii
->wID
= menu
->wID
;
4296 if (lpmii
->fMask
& MIIM_SUBMENU
)
4297 lpmii
->hSubMenu
= menu
->hSubMenu
;
4299 if (lpmii
->fMask
& MIIM_CHECKMARKS
) {
4300 lpmii
->hbmpChecked
= menu
->hCheckBit
;
4301 lpmii
->hbmpUnchecked
= menu
->hUnCheckBit
;
4303 if (lpmii
->fMask
& MIIM_DATA
)
4304 lpmii
->dwItemData
= menu
->dwItemData
;
4309 /**********************************************************************
4310 * GetMenuItemInfoA (USER32.264)
4312 BOOL WINAPI
GetMenuItemInfoA( HMENU hmenu
, UINT item
, BOOL bypos
,
4313 LPMENUITEMINFOA lpmii
)
4315 return GetMenuItemInfo_common (hmenu
, item
, bypos
, lpmii
, FALSE
);
4318 /**********************************************************************
4319 * GetMenuItemInfoW (USER32.265)
4321 BOOL WINAPI
GetMenuItemInfoW( HMENU hmenu
, UINT item
, BOOL bypos
,
4322 LPMENUITEMINFOW lpmii
)
4324 return GetMenuItemInfo_common (hmenu
, item
, bypos
,
4325 (LPMENUITEMINFOA
)lpmii
, TRUE
);
4328 /**********************************************************************
4329 * SetMenuItemInfo32_common
4332 static BOOL
SetMenuItemInfo_common(MENUITEM
* menu
,
4333 const MENUITEMINFOA
*lpmii
,
4336 if (!menu
) return FALSE
;
4338 if (lpmii
->fMask
& MIIM_TYPE
) {
4339 /* Get rid of old string. */
4340 if ( IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4341 HeapFree(SystemHeap
, 0, menu
->text
);
4345 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4346 menu
->fType
&= ~MENU_ITEM_TYPE(menu
->fType
);
4347 menu
->fType
|= MENU_ITEM_TYPE(lpmii
->fType
);
4349 menu
->text
= lpmii
->dwTypeData
;
4351 if (IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4353 menu
->text
= HEAP_strdupWtoA(SystemHeap
, 0, (LPWSTR
) lpmii
->dwTypeData
);
4355 menu
->text
= HEAP_strdupA(SystemHeap
, 0, lpmii
->dwTypeData
);
4359 if (lpmii
->fMask
& MIIM_FTYPE
) {
4360 /* free the string when the type is changing */
4361 if ( (!IS_STRING_ITEM(lpmii
->fType
)) && IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4362 HeapFree(SystemHeap
, 0, menu
->text
);
4365 menu
->fType
&= ~MENU_ITEM_TYPE(menu
->fType
);
4366 menu
->fType
|= MENU_ITEM_TYPE(lpmii
->fType
);
4369 if (lpmii
->fMask
& MIIM_STRING
) {
4370 /* free the string when used */
4371 if ( IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4372 HeapFree(SystemHeap
, 0, menu
->text
);
4374 menu
->text
= HEAP_strdupWtoA(SystemHeap
, 0, (LPWSTR
) lpmii
->dwTypeData
);
4376 menu
->text
= HEAP_strdupA(SystemHeap
, 0, lpmii
->dwTypeData
);
4380 if (lpmii
->fMask
& MIIM_STATE
)
4382 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
4383 menu
->fState
= lpmii
->fState
;
4386 if (lpmii
->fMask
& MIIM_ID
)
4387 menu
->wID
= lpmii
->wID
;
4389 if (lpmii
->fMask
& MIIM_SUBMENU
) {
4390 menu
->hSubMenu
= lpmii
->hSubMenu
;
4391 if (menu
->hSubMenu
) {
4392 POPUPMENU
*subMenu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR((UINT16
)menu
->hSubMenu
);
4393 if (IS_A_MENU(subMenu
)) {
4394 subMenu
->wFlags
|= MF_POPUP
;
4395 menu
->fType
|= MF_POPUP
;
4398 /* FIXME: Return an error ? */
4399 menu
->fType
&= ~MF_POPUP
;
4402 menu
->fType
&= ~MF_POPUP
;
4405 if (lpmii
->fMask
& MIIM_CHECKMARKS
)
4407 menu
->hCheckBit
= lpmii
->hbmpChecked
;
4408 menu
->hUnCheckBit
= lpmii
->hbmpUnchecked
;
4410 if (lpmii
->fMask
& MIIM_DATA
)
4411 menu
->dwItemData
= lpmii
->dwItemData
;
4413 debug_print_menuitem("SetMenuItemInfo32_common: ", menu
, "");
4417 /**********************************************************************
4418 * SetMenuItemInfo32A (USER32.491)
4420 BOOL WINAPI
SetMenuItemInfoA(HMENU hmenu
, UINT item
, BOOL bypos
,
4421 const MENUITEMINFOA
*lpmii
)
4423 return SetMenuItemInfo_common(MENU_FindItem(&hmenu
, &item
, bypos
? MF_BYPOSITION
: 0),
4427 /**********************************************************************
4428 * SetMenuItemInfo32W (USER32.492)
4430 BOOL WINAPI
SetMenuItemInfoW(HMENU hmenu
, UINT item
, BOOL bypos
,
4431 const MENUITEMINFOW
*lpmii
)
4433 return SetMenuItemInfo_common(MENU_FindItem(&hmenu
, &item
, bypos
? MF_BYPOSITION
: 0),
4434 (const MENUITEMINFOA
*)lpmii
, TRUE
);
4437 /**********************************************************************
4438 * SetMenuDefaultItem (USER32.489)
4441 BOOL WINAPI
SetMenuDefaultItem(HMENU hmenu
, UINT uItem
, UINT bypos
)
4447 TRACE("(0x%x,%d,%d)\n", hmenu
, uItem
, bypos
);
4449 if (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hmenu
))) return FALSE
;
4451 /* reset all default-item flags */
4453 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
4455 item
->fState
&= ~MFS_DEFAULT
;
4458 /* no default item */
4467 if ( uItem
>= menu
->nItems
) return FALSE
;
4468 item
[uItem
].fState
|= MFS_DEFAULT
;
4473 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
4475 if (item
->wID
== uItem
)
4477 item
->fState
|= MFS_DEFAULT
;
4486 /**********************************************************************
4487 * GetMenuDefaultItem (USER32.260)
4489 UINT WINAPI
GetMenuDefaultItem(HMENU hmenu
, UINT bypos
, UINT flags
)
4495 TRACE("(0x%x,%d,%d)\n", hmenu
, bypos
, flags
);
4497 if (!(menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hmenu
))) return -1;
4499 /* find default item */
4503 if (! item
) return -1;
4505 while ( !( item
->fState
& MFS_DEFAULT
) )
4508 if (i
>= menu
->nItems
) return -1;
4511 /* default: don't return disabled items */
4512 if ( (!(GMDI_USEDISABLED
& flags
)) && (item
->fState
& MFS_DISABLED
)) return -1;
4514 /* search rekursiv when needed */
4515 if ( (item
->fType
& MF_POPUP
) && (flags
& GMDI_GOINTOPOPUPS
) )
4518 ret
= GetMenuDefaultItem( item
->hSubMenu
, bypos
, flags
);
4519 if ( -1 != ret
) return ret
;
4521 /* when item not found in submenu, return the popup item */
4523 return ( bypos
) ? i
: item
->wID
;
4527 /*******************************************************************
4528 * InsertMenuItem16 (USER.441)
4532 BOOL16 WINAPI
InsertMenuItem16( HMENU16 hmenu
, UINT16 pos
, BOOL16 byposition
,
4533 const MENUITEMINFO16
*mii
)
4537 miia
.cbSize
= sizeof(miia
);
4538 miia
.fMask
= mii
->fMask
;
4539 miia
.dwTypeData
= mii
->dwTypeData
;
4540 miia
.fType
= mii
->fType
;
4541 miia
.fState
= mii
->fState
;
4542 miia
.wID
= mii
->wID
;
4543 miia
.hSubMenu
= mii
->hSubMenu
;
4544 miia
.hbmpChecked
= mii
->hbmpChecked
;
4545 miia
.hbmpUnchecked
= mii
->hbmpUnchecked
;
4546 miia
.dwItemData
= mii
->dwItemData
;
4547 miia
.cch
= mii
->cch
;
4548 if (IS_STRING_ITEM(miia
.fType
))
4549 miia
.dwTypeData
= PTR_SEG_TO_LIN(miia
.dwTypeData
);
4550 return InsertMenuItemA( hmenu
, pos
, byposition
, &miia
);
4554 /**********************************************************************
4555 * InsertMenuItem32A (USER32.323)
4557 BOOL WINAPI
InsertMenuItemA(HMENU hMenu
, UINT uItem
, BOOL bypos
,
4558 const MENUITEMINFOA
*lpmii
)
4560 MENUITEM
*item
= MENU_InsertItem(hMenu
, uItem
, bypos
? MF_BYPOSITION
: 0 );
4561 return SetMenuItemInfo_common(item
, lpmii
, FALSE
);
4565 /**********************************************************************
4566 * InsertMenuItem32W (USER32.324)
4568 BOOL WINAPI
InsertMenuItemW(HMENU hMenu
, UINT uItem
, BOOL bypos
,
4569 const MENUITEMINFOW
*lpmii
)
4571 MENUITEM
*item
= MENU_InsertItem(hMenu
, uItem
, bypos
? MF_BYPOSITION
: 0 );
4572 return SetMenuItemInfo_common(item
, (const MENUITEMINFOA
*)lpmii
, TRUE
);
4575 /**********************************************************************
4576 * CheckMenuRadioItem32 (USER32.47)
4579 BOOL WINAPI
CheckMenuRadioItem(HMENU hMenu
,
4580 UINT first
, UINT last
, UINT check
,
4583 MENUITEM
*mifirst
, *milast
, *micheck
;
4584 HMENU mfirst
= hMenu
, mlast
= hMenu
, mcheck
= hMenu
;
4586 TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
4587 hMenu
, first
, last
, check
, bypos
);
4589 mifirst
= MENU_FindItem (&mfirst
, &first
, bypos
);
4590 milast
= MENU_FindItem (&mlast
, &last
, bypos
);
4591 micheck
= MENU_FindItem (&mcheck
, &check
, bypos
);
4593 if (mifirst
== NULL
|| milast
== NULL
|| micheck
== NULL
||
4594 mifirst
> milast
|| mfirst
!= mlast
|| mfirst
!= mcheck
||
4595 micheck
> milast
|| micheck
< mifirst
)
4598 while (mifirst
<= milast
)
4600 if (mifirst
== micheck
)
4602 mifirst
->fType
|= MFT_RADIOCHECK
;
4603 mifirst
->fState
|= MFS_CHECKED
;
4605 mifirst
->fType
&= ~MFT_RADIOCHECK
;
4606 mifirst
->fState
&= ~MFS_CHECKED
;
4614 /**********************************************************************
4615 * CheckMenuRadioItem16 (not a Windows API)
4618 BOOL16 WINAPI
CheckMenuRadioItem16(HMENU16 hMenu
,
4619 UINT16 first
, UINT16 last
, UINT16 check
,
4622 return CheckMenuRadioItem (hMenu
, first
, last
, check
, bypos
);
4625 /**********************************************************************
4626 * GetMenuItemRect32 (USER32.266)
4628 * ATTENTION: Here, the returned values in rect are the screen
4629 * coordinates of the item just like if the menu was
4630 * always on the upper left side of the application.
4633 BOOL WINAPI
GetMenuItemRect (HWND hwnd
, HMENU hMenu
, UINT uItem
,
4636 POPUPMENU
*itemMenu
;
4640 TRACE("(0x%x,0x%x,%d,%p)\n", hwnd
, hMenu
, uItem
, rect
);
4642 item
= MENU_FindItem (&hMenu
, &uItem
, MF_BYPOSITION
);
4643 referenceHwnd
= hwnd
;
4647 itemMenu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
);
4648 if (itemMenu
== NULL
)
4651 if(itemMenu
->hWnd
== 0)
4653 referenceHwnd
= itemMenu
->hWnd
;
4656 if ((rect
== NULL
) || (item
== NULL
))
4661 MapWindowPoints(referenceHwnd
, 0, (LPPOINT
)rect
, 2);
4666 /**********************************************************************
4667 * GetMenuItemRect16 (USER.665)
4670 BOOL16 WINAPI
GetMenuItemRect16 (HWND16 hwnd
, HMENU16 hMenu
, UINT16 uItem
,
4676 if (!rect
) return FALSE
;
4677 res
= GetMenuItemRect (hwnd
, hMenu
, uItem
, &r32
);
4678 CONV_RECT32TO16 (&r32
, rect
);
4682 /**********************************************************************
4686 * MIM_APPLYTOSUBMENUS
4687 * actually use the items to draw the menu
4689 BOOL WINAPI
SetMenuInfo (HMENU hMenu
, LPCMENUINFO lpmi
)
4693 TRACE("(0x%04x %p)\n", hMenu
, lpmi
);
4695 if (lpmi
&& (lpmi
->cbSize
==sizeof(MENUINFO
)) && (menu
=(POPUPMENU
*)USER_HEAP_LIN_ADDR(hMenu
)))
4698 if (lpmi
->fMask
& MIM_BACKGROUND
)
4699 menu
->hbrBack
= lpmi
->hbrBack
;
4701 if (lpmi
->fMask
& MIM_HELPID
)
4702 menu
->dwContextHelpID
= lpmi
->dwContextHelpID
;
4704 if (lpmi
->fMask
& MIM_MAXHEIGHT
)
4705 menu
->cyMax
= lpmi
->cyMax
;
4707 if (lpmi
->fMask
& MIM_MENUDATA
)
4708 menu
->dwMenuData
= lpmi
->dwMenuData
;
4710 if (lpmi
->fMask
& MIM_STYLE
)
4711 menu
->dwStyle
= lpmi
->dwStyle
;
4718 /**********************************************************************
4725 BOOL WINAPI
GetMenuInfo (HMENU hMenu
, LPMENUINFO lpmi
)
4728 TRACE("(0x%04x %p)\n", hMenu
, lpmi
);
4730 if (lpmi
&& (menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
)))
4733 if (lpmi
->fMask
& MIM_BACKGROUND
)
4734 lpmi
->hbrBack
= menu
->hbrBack
;
4736 if (lpmi
->fMask
& MIM_HELPID
)
4737 lpmi
->dwContextHelpID
= menu
->dwContextHelpID
;
4739 if (lpmi
->fMask
& MIM_MAXHEIGHT
)
4740 lpmi
->cyMax
= menu
->cyMax
;
4742 if (lpmi
->fMask
& MIM_MENUDATA
)
4743 lpmi
->dwMenuData
= menu
->dwMenuData
;
4745 if (lpmi
->fMask
& MIM_STYLE
)
4746 lpmi
->dwStyle
= menu
->dwStyle
;
4753 /**********************************************************************
4754 * SetMenuContextHelpId16 (USER.384)
4756 BOOL16 WINAPI
SetMenuContextHelpId16( HMENU16 hMenu
, DWORD dwContextHelpID
)
4758 return SetMenuContextHelpId( hMenu
, dwContextHelpID
);
4762 /**********************************************************************
4763 * SetMenuContextHelpId (USER32.488)
4765 BOOL WINAPI
SetMenuContextHelpId( HMENU hMenu
, DWORD dwContextHelpID
)
4769 TRACE("(0x%04x 0x%08lx)\n", hMenu
, dwContextHelpID
);
4771 if ((menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
)))
4773 menu
->dwContextHelpID
= dwContextHelpID
;
4779 /**********************************************************************
4780 * GetMenuContextHelpId16 (USER.385)
4782 DWORD WINAPI
GetMenuContextHelpId16( HMENU16 hMenu
)
4784 return GetMenuContextHelpId( hMenu
);
4787 /**********************************************************************
4788 * GetMenuContextHelpId (USER32.488)
4790 DWORD WINAPI
GetMenuContextHelpId( HMENU hMenu
)
4794 TRACE("(0x%04x)\n", hMenu
);
4796 if ((menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
)))
4798 return menu
->dwContextHelpID
;
4803 /**********************************************************************
4804 * MenuItemFromPoint (USER32.387)
4806 UINT WINAPI
MenuItemFromPoint(HWND hWnd
, HMENU hMenu
, POINT ptScreen
)
4808 FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
4809 hWnd
, hMenu
, ptScreen
.x
, ptScreen
.y
);