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
);
271 /***********************************************************************
274 * Validate the given menu handle and returns the menu structure pointer.
276 POPUPMENU
*MENU_GetMenu(HMENU hMenu
)
279 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
);
280 if (!IS_A_MENU(menu
))
282 ERR("invalid menu handle=%x, ptr=%p, magic=%x\n", hMenu
, menu
, menu
? menu
->wMagic
:0);
288 /***********************************************************************
291 * Return the default system menu.
293 static HMENU
MENU_CopySysPopup(void)
295 HMENU hMenu
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
298 POPUPMENU
* menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
);
299 menu
->wFlags
|= MF_SYSMENU
| MF_POPUP
;
300 SetMenuDefaultItem(hMenu
, SC_CLOSE
, FALSE
);
304 ERR("Unable to load default system menu\n" );
307 TRACE("returning %x.\n", hMenu
);
312 /***********************************************************************
313 * MENU_GetTopPopupWnd()
315 * Return the locked pointer pTopPopupWnd.
317 static WND
*MENU_GetTopPopupWnd()
319 return WIN_LockWndPtr(pTopPopupWnd
);
321 /***********************************************************************
322 * MENU_ReleaseTopPopupWnd()
324 * Realease the locked pointer pTopPopupWnd.
326 static void MENU_ReleaseTopPopupWnd()
328 WIN_ReleaseWndPtr(pTopPopupWnd
);
330 /***********************************************************************
331 * MENU_DestroyTopPopupWnd()
333 * Destroy the locked pointer pTopPopupWnd.
335 static void MENU_DestroyTopPopupWnd()
337 WND
*tmpWnd
= pTopPopupWnd
;
339 WIN_ReleaseWndPtr(tmpWnd
);
344 /**********************************************************************
347 * Create a copy of the system menu. System menu in Windows is
348 * a special menu-bar with the single entry - system menu popup.
349 * This popup is presented to the outside world as a "system menu".
350 * However, the real system menu handle is sometimes seen in the
351 * WM_MENUSELECT paramemters (and Word 6 likes it this way).
353 HMENU
MENU_GetSysMenu( HWND hWnd
, HMENU hPopupMenu
)
357 if ((hMenu
= CreateMenu()))
359 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hMenu
);
360 menu
->wFlags
= MF_SYSMENU
;
363 if (hPopupMenu
== (HMENU
)(-1))
364 hPopupMenu
= MENU_CopySysPopup();
365 else if( !hPopupMenu
) hPopupMenu
= MENU_DefSysPopup
;
369 InsertMenuA( hMenu
, -1, MF_SYSMENU
| MF_POPUP
| MF_BYPOSITION
, hPopupMenu
, NULL
);
371 menu
->items
[0].fType
= MF_SYSMENU
| MF_POPUP
;
372 menu
->items
[0].fState
= 0;
373 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR(hPopupMenu
);
374 menu
->wFlags
|= MF_SYSMENU
;
376 TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu
, hPopupMenu
);
379 DestroyMenu( hMenu
);
381 ERR("failed to load system menu!\n");
386 /***********************************************************************
389 * Menus initialisation.
394 NONCLIENTMETRICSA ncm
;
396 static unsigned char shade_bits
[16] = { 0x55, 0, 0xAA, 0,
401 /* Load menu bitmaps */
402 hStdCheck
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK
));
403 hStdRadioCheck
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK
));
404 hStdMnArrow
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW
));
405 /* Load system buttons bitmaps */
406 hBmpMinimize
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE
));
407 hBmpMinimizeD
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED
));
408 hBmpMaximize
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE
));
409 hBmpMaximizeD
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED
));
410 hBmpClose
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE
));
411 hBmpCloseD
= LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED
));
416 GetObjectA( hStdCheck
, sizeof(bm
), &bm
);
417 check_bitmap_width
= bm
.bmWidth
;
418 check_bitmap_height
= bm
.bmHeight
;
422 /* Assume that radio checks have the same size as regular check. */
429 GetObjectA( hStdMnArrow
, sizeof(bm
), &bm
);
430 arrow_bitmap_width
= bm
.bmWidth
;
431 arrow_bitmap_height
= bm
.bmHeight
;
435 if (! (hBitmap
= CreateBitmap( 8, 8, 1, 1, shade_bits
)))
438 if(!(hShadeBrush
= CreatePatternBrush( hBitmap
)))
441 DeleteObject( hBitmap
);
442 if (!(MENU_DefSysPopup
= MENU_CopySysPopup()))
445 ncm
.cbSize
= sizeof (NONCLIENTMETRICSA
);
446 if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICSA
), &ncm
, 0)))
449 if (!(hMenuFont
= CreateFontIndirectA( &ncm
.lfMenuFont
)))
452 ncm
.lfMenuFont
.lfWeight
+= 300;
453 if ( ncm
.lfMenuFont
.lfWeight
> 1000)
454 ncm
.lfMenuFont
.lfWeight
= 1000;
456 if (!(hMenuFontBold
= CreateFontIndirectA( &ncm
.lfMenuFont
)))
462 /***********************************************************************
463 * MENU_InitSysMenuPopup
465 * Grey the appropriate items in System menu.
467 static void MENU_InitSysMenuPopup( HMENU hmenu
, DWORD style
, DWORD clsStyle
)
471 gray
= !(style
& WS_THICKFRAME
) || (style
& (WS_MAXIMIZE
| WS_MINIMIZE
));
472 EnableMenuItem( hmenu
, SC_SIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
473 gray
= ((style
& WS_MAXIMIZE
) != 0);
474 EnableMenuItem( hmenu
, SC_MOVE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
475 gray
= !(style
& WS_MINIMIZEBOX
) || (style
& WS_MINIMIZE
);
476 EnableMenuItem( hmenu
, SC_MINIMIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
477 gray
= !(style
& WS_MAXIMIZEBOX
) || (style
& WS_MAXIMIZE
);
478 EnableMenuItem( hmenu
, SC_MAXIMIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
479 gray
= !(style
& (WS_MAXIMIZE
| WS_MINIMIZE
));
480 EnableMenuItem( hmenu
, SC_RESTORE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
481 gray
= (clsStyle
& CS_NOCLOSE
) != 0;
483 /* The menu item must keep its state if it's disabled */
485 EnableMenuItem( hmenu
, SC_CLOSE
, MF_GRAYED
);
489 /******************************************************************************
491 * UINT32 MENU_GetStartOfNextColumn(
494 *****************************************************************************/
496 static UINT
MENU_GetStartOfNextColumn(
499 POPUPMENU
*menu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR(hMenu
);
500 UINT i
= menu
->FocusedItem
+ 1;
503 return NO_SELECTED_ITEM
;
505 if( i
== NO_SELECTED_ITEM
)
508 for( ; i
< menu
->nItems
; ++i
) {
509 if (menu
->items
[i
].fType
& MF_MENUBARBREAK
)
513 return NO_SELECTED_ITEM
;
517 /******************************************************************************
519 * UINT32 MENU_GetStartOfPrevColumn(
522 *****************************************************************************/
524 static UINT
MENU_GetStartOfPrevColumn(
527 POPUPMENU
const *menu
= (POPUPMENU
*)USER_HEAP_LIN_ADDR(hMenu
);
531 return NO_SELECTED_ITEM
;
533 if( menu
->FocusedItem
== 0 || menu
->FocusedItem
== NO_SELECTED_ITEM
)
534 return NO_SELECTED_ITEM
;
536 /* Find the start of the column */
538 for(i
= menu
->FocusedItem
; i
!= 0 &&
539 !(menu
->items
[i
].fType
& MF_MENUBARBREAK
);
543 return NO_SELECTED_ITEM
;
545 for(--i
; i
!= 0; --i
) {
546 if (menu
->items
[i
].fType
& MF_MENUBARBREAK
)
550 TRACE("ret %d.\n", i
);
557 /***********************************************************************
560 * Find a menu item. Return a pointer on the item, and modifies *hmenu
561 * in case the item was in a sub-menu.
563 static MENUITEM
*MENU_FindItem( HMENU
*hmenu
, UINT
*nPos
, UINT wFlags
)
568 if (((*hmenu
)==0xffff) || (!(menu
= MENU_GetMenu(*hmenu
)))) return NULL
;
569 if (wFlags
& MF_BYPOSITION
)
571 if (*nPos
>= menu
->nItems
) return NULL
;
572 return &menu
->items
[*nPos
];
576 MENUITEM
*item
= menu
->items
;
577 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
579 if (item
->wID
== *nPos
)
584 else if (item
->fType
& MF_POPUP
)
586 HMENU hsubmenu
= item
->hSubMenu
;
587 MENUITEM
*subitem
= MENU_FindItem( &hsubmenu
, nPos
, wFlags
);
599 /***********************************************************************
602 * Find a Sub menu. Return the position of the submenu, and modifies
603 * *hmenu in case it is found in another sub-menu.
604 * If the submenu cannot be found, NO_SELECTED_ITEM is returned.
606 UINT
MENU_FindSubMenu( HMENU
*hmenu
, HMENU hSubTarget
)
611 if (((*hmenu
)==0xffff) ||
612 (!(menu
= MENU_GetMenu(*hmenu
))))
613 return NO_SELECTED_ITEM
;
615 for (i
= 0; i
< menu
->nItems
; i
++, item
++) {
616 if(!(item
->fType
& MF_POPUP
)) continue;
617 if (item
->hSubMenu
== hSubTarget
) {
621 HMENU hsubmenu
= item
->hSubMenu
;
622 UINT pos
= MENU_FindSubMenu( &hsubmenu
, hSubTarget
);
623 if (pos
!= NO_SELECTED_ITEM
) {
629 return NO_SELECTED_ITEM
;
632 /***********************************************************************
635 static void MENU_FreeItemData( MENUITEM
* item
)
638 if (IS_STRING_ITEM(item
->fType
) && item
->text
)
639 HeapFree( SystemHeap
, 0, item
->text
);
642 /***********************************************************************
643 * MENU_FindItemByCoords
645 * Find the item at the specified coordinates (screen coords). Does
646 * not work for child windows and therefore should not be called for
647 * an arbitrary system menu.
649 static MENUITEM
*MENU_FindItemByCoords( POPUPMENU
*menu
,
650 POINT pt
, UINT
*pos
)
656 if (!GetWindowRect(menu
->hWnd
,&wrect
)) return NULL
;
657 pt
.x
-= wrect
.left
;pt
.y
-= wrect
.top
;
659 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
661 if ((pt
.x
>= item
->rect
.left
) && (pt
.x
< item
->rect
.right
) &&
662 (pt
.y
>= item
->rect
.top
) && (pt
.y
< item
->rect
.bottom
))
672 /***********************************************************************
675 * Find the menu item selected by a key press.
676 * Return item id, -1 if none, -2 if we should close the menu.
678 static UINT
MENU_FindItemByKey( HWND hwndOwner
, HMENU hmenu
,
679 UINT key
, BOOL forceMenuChar
)
681 TRACE("\tlooking for '%c' in [%04x]\n", (char)key
, (UINT16
)hmenu
);
683 if (!IsMenu( hmenu
))
685 WND
* w
= WIN_FindWndPtr(hwndOwner
);
686 hmenu
= GetSubMenu(w
->hSysMenu
, 0);
687 WIN_ReleaseWndPtr(w
);
692 POPUPMENU
*menu
= MENU_GetMenu( hmenu
);
693 MENUITEM
*item
= menu
->items
;
701 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
703 if (item
->text
&& (IS_STRING_ITEM(item
->fType
)))
705 char *p
= item
->text
- 2;
708 p
= strchr (p
+ 2, '&');
710 while (p
!= NULL
&& p
[1] == '&');
711 if (p
&& (toupper(p
[1]) == key
)) return i
;
715 menuchar
= SendMessageA( hwndOwner
, WM_MENUCHAR
,
716 MAKEWPARAM( key
, menu
->wFlags
), hmenu
);
717 if (HIWORD(menuchar
) == 2) return LOWORD(menuchar
);
718 if (HIWORD(menuchar
) == 1) return (UINT
)(-2);
722 /***********************************************************************
725 * Load the bitmap associated with the magic menu item and its style
728 static HBITMAP
MENU_LoadMagicItem(UINT id
, BOOL hilite
, DWORD dwItemData
)
731 * Magic menu item id's section
732 * These magic id's are used by windows to insert "standard" mdi
733 * buttons (minimize,restore,close) on menu. Under windows,
734 * these magic id's make sure the right things appear when those
735 * bitmap buttons are pressed/selected/released.
739 { case HBMMENU_SYSTEM
:
740 return (dwItemData
) ?
741 (HBITMAP
)dwItemData
:
742 (hilite
? hBmpMinimizeD
: hBmpMinimize
);
743 case HBMMENU_MBAR_RESTORE
:
744 return (hilite
? hBmpMaximizeD
: hBmpMaximize
);
745 case HBMMENU_MBAR_MINIMIZE
:
746 return (hilite
? hBmpMinimizeD
: hBmpMinimize
);
747 case HBMMENU_MBAR_CLOSE
:
748 return (hilite
? hBmpCloseD
: hBmpClose
);
749 case HBMMENU_CALLBACK
:
750 case HBMMENU_MBAR_CLOSE_D
:
751 case HBMMENU_MBAR_MINIMIZE_D
:
752 case HBMMENU_POPUP_CLOSE
:
753 case HBMMENU_POPUP_RESTORE
:
754 case HBMMENU_POPUP_MAXIMIZE
:
755 case HBMMENU_POPUP_MINIMIZE
:
757 FIXME("Magic 0x%08x not implemented\n", id
);
763 /***********************************************************************
766 * Calculate the size of the menu item and store it in lpitem->rect.
768 static void MENU_CalcItemSize( HDC hdc
, MENUITEM
*lpitem
, HWND hwndOwner
,
769 INT orgX
, INT orgY
, BOOL menuBar
)
773 TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc
, hwndOwner
, orgX
, orgY
);
774 debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem
,
775 (menuBar
? " (MenuBar)" : ""));
777 SetRect( &lpitem
->rect
, orgX
, orgY
, orgX
, orgY
);
779 if (lpitem
->fType
& MF_OWNERDRAW
)
781 MEASUREITEMSTRUCT mis
;
782 mis
.CtlType
= ODT_MENU
;
784 mis
.itemID
= lpitem
->wID
;
785 mis
.itemData
= (DWORD
)lpitem
->dwItemData
;
788 SendMessageA( hwndOwner
, WM_MEASUREITEM
, 0, (LPARAM
)&mis
);
789 lpitem
->rect
.bottom
+= mis
.itemHeight
;
790 lpitem
->rect
.right
+= mis
.itemWidth
;
791 TRACE("id=%04x size=%dx%d\n",
792 lpitem
->wID
, mis
.itemWidth
, mis
.itemHeight
);
796 if (lpitem
->fType
& MF_SEPARATOR
)
798 lpitem
->rect
.bottom
+= SEPARATOR_HEIGHT
;
804 lpitem
->rect
.right
+= 2 * check_bitmap_width
;
805 if (lpitem
->fType
& MF_POPUP
)
806 lpitem
->rect
.right
+= arrow_bitmap_width
;
809 if (IS_BITMAP_ITEM(lpitem
->fType
))
814 /* Check if there is a magic menu item associated with this item */
815 if((LOWORD((int)lpitem
->text
))<12)
817 resBmp
= MENU_LoadMagicItem((int)lpitem
->text
, (lpitem
->fType
& MF_HILITE
),
821 resBmp
= (HBITMAP
)lpitem
->text
;
823 if (GetObjectA(resBmp
, sizeof(bm
), &bm
))
825 lpitem
->rect
.right
+= bm
.bmWidth
;
826 lpitem
->rect
.bottom
+= bm
.bmHeight
;
832 /* If we get here, then it must be a text item */
833 if (IS_STRING_ITEM( lpitem
->fType
))
836 GetTextExtentPoint32A(hdc
, lpitem
->text
, strlen(lpitem
->text
), &size
);
838 lpitem
->rect
.right
+= size
.cx
;
839 if (TWEAK_WineLook
== WIN31_LOOK
)
840 lpitem
->rect
.bottom
+= MAX( size
.cy
, GetSystemMetrics(SM_CYMENU
) );
842 lpitem
->rect
.bottom
+= MAX (size
.cy
, GetSystemMetrics(SM_CYMENU
)-1);
847 lpitem
->rect
.right
+= MENU_BAR_ITEMS_SPACE
;
849 else if ((p
= strchr( lpitem
->text
, '\t' )) != NULL
)
851 /* Item contains a tab (only meaningful in popup menus) */
852 GetTextExtentPoint32A(hdc
, lpitem
->text
, (int)(p
- lpitem
->text
) , &size
);
853 lpitem
->xTab
= check_bitmap_width
+ MENU_TAB_SPACE
+ size
.cx
;
854 lpitem
->rect
.right
+= MENU_TAB_SPACE
;
858 if (strchr( lpitem
->text
, '\b' ))
859 lpitem
->rect
.right
+= MENU_TAB_SPACE
;
860 lpitem
->xTab
= lpitem
->rect
.right
- check_bitmap_width
861 - arrow_bitmap_width
;
864 TRACE("(%d,%d)-(%d,%d)\n", lpitem
->rect
.left
, lpitem
->rect
.top
, lpitem
->rect
.right
, lpitem
->rect
.bottom
);
868 /***********************************************************************
869 * MENU_PopupMenuCalcSize
871 * Calculate the size of a popup menu.
873 static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop
, HWND hwndOwner
)
878 int orgX
, orgY
, maxX
, maxTab
, maxTabWidth
;
880 lppop
->Width
= lppop
->Height
= 0;
881 if (lppop
->nItems
== 0) return;
884 SelectObject( hdc
, hMenuFont
);
887 maxX
= (TWEAK_WineLook
== WIN31_LOOK
) ? GetSystemMetrics(SM_CXBORDER
) : 2 ;
889 while (start
< lppop
->nItems
)
891 lpitem
= &lppop
->items
[start
];
893 orgY
= (TWEAK_WineLook
== WIN31_LOOK
) ? GetSystemMetrics(SM_CYBORDER
) : 2;
895 maxTab
= maxTabWidth
= 0;
897 /* Parse items until column break or end of menu */
898 for (i
= start
; i
< lppop
->nItems
; i
++, lpitem
++)
901 (lpitem
->fType
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
903 MENU_CalcItemSize( hdc
, lpitem
, hwndOwner
, orgX
, orgY
, FALSE
);
905 if (lpitem
->fType
& MF_MENUBARBREAK
) orgX
++;
906 maxX
= MAX( maxX
, lpitem
->rect
.right
);
907 orgY
= lpitem
->rect
.bottom
;
908 if (IS_STRING_ITEM(lpitem
->fType
) && lpitem
->xTab
)
910 maxTab
= MAX( maxTab
, lpitem
->xTab
);
911 maxTabWidth
= MAX(maxTabWidth
,lpitem
->rect
.right
-lpitem
->xTab
);
915 /* Finish the column (set all items to the largest width found) */
916 maxX
= MAX( maxX
, maxTab
+ maxTabWidth
);
917 for (lpitem
= &lppop
->items
[start
]; start
< i
; start
++, lpitem
++)
919 lpitem
->rect
.right
= maxX
;
920 if (IS_STRING_ITEM(lpitem
->fType
) && lpitem
->xTab
)
921 lpitem
->xTab
= maxTab
;
924 lppop
->Height
= MAX( lppop
->Height
, orgY
);
929 /* space for 3d border */
930 if(TWEAK_WineLook
> WIN31_LOOK
)
940 /***********************************************************************
941 * MENU_MenuBarCalcSize
943 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
944 * height is off by 1 pixel which causes lengthy window relocations when
945 * active document window is maximized/restored.
947 * Calculate the size of the menu bar.
949 static void MENU_MenuBarCalcSize( HDC hdc
, LPRECT lprect
,
950 LPPOPUPMENU lppop
, HWND hwndOwner
)
953 int start
, i
, orgX
, orgY
, maxY
, helpPos
;
955 if ((lprect
== NULL
) || (lppop
== NULL
)) return;
956 if (lppop
->nItems
== 0) return;
957 TRACE("left=%d top=%d right=%d bottom=%d\n",
958 lprect
->left
, lprect
->top
, lprect
->right
, lprect
->bottom
);
959 lppop
->Width
= lprect
->right
- lprect
->left
;
964 while (start
< lppop
->nItems
)
966 lpitem
= &lppop
->items
[start
];
970 /* Parse items until line break or end of menu */
971 for (i
= start
; i
< lppop
->nItems
; i
++, lpitem
++)
973 if ((helpPos
== -1) && (lpitem
->fType
& MF_HELP
)) helpPos
= i
;
975 (lpitem
->fType
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
977 TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
979 debug_print_menuitem (" item: ", lpitem
, "");
980 MENU_CalcItemSize( hdc
, lpitem
, hwndOwner
, orgX
, orgY
, TRUE
);
982 if (lpitem
->rect
.right
> lprect
->right
)
984 if (i
!= start
) break;
985 else lpitem
->rect
.right
= lprect
->right
;
987 maxY
= MAX( maxY
, lpitem
->rect
.bottom
);
988 orgX
= lpitem
->rect
.right
;
991 /* Finish the line (set all items to the largest height found) */
992 while (start
< i
) lppop
->items
[start
++].rect
.bottom
= maxY
;
995 lprect
->bottom
= maxY
;
996 lppop
->Height
= lprect
->bottom
- lprect
->top
;
998 /* Flush right all magic items and items between the MF_HELP and */
999 /* the last item (if several lines, only move the last line) */
1000 lpitem
= &lppop
->items
[lppop
->nItems
-1];
1001 orgY
= lpitem
->rect
.top
;
1002 orgX
= lprect
->right
;
1003 for (i
= lppop
->nItems
- 1; i
>= helpPos
; i
--, lpitem
--)
1005 if ( !IS_BITMAP_ITEM(lpitem
->fType
) && ((helpPos
==-1) ? TRUE
: (helpPos
>i
) ))
1007 if (lpitem
->rect
.top
!= orgY
) break; /* Other line */
1008 if (lpitem
->rect
.right
>= orgX
) break; /* Too far right already */
1009 lpitem
->rect
.left
+= orgX
- lpitem
->rect
.right
;
1010 lpitem
->rect
.right
= orgX
;
1011 orgX
= lpitem
->rect
.left
;
1015 /***********************************************************************
1018 * Draw a single menu item.
1020 static void MENU_DrawMenuItem( HWND hwnd
, HMENU hmenu
, HWND hwndOwner
, HDC hdc
, MENUITEM
*lpitem
,
1021 UINT height
, BOOL menuBar
, UINT odaction
)
1025 debug_print_menuitem("MENU_DrawMenuItem: ", lpitem
, "");
1027 if (lpitem
->fType
& MF_SYSMENU
)
1029 if( !IsIconic(hwnd
) ) {
1030 if (TWEAK_WineLook
> WIN31_LOOK
)
1031 NC_DrawSysButton95( hwnd
, hdc
,
1033 (MF_HILITE
| MF_MOUSESELECT
) );
1035 NC_DrawSysButton( hwnd
, hdc
,
1037 (MF_HILITE
| MF_MOUSESELECT
) );
1043 if (lpitem
->fType
& MF_OWNERDRAW
)
1047 dis
.CtlType
= ODT_MENU
;
1049 dis
.itemID
= lpitem
->wID
;
1050 dis
.itemData
= (DWORD
)lpitem
->dwItemData
;
1052 if (lpitem
->fState
& MF_CHECKED
) dis
.itemState
|= ODS_CHECKED
;
1053 if (lpitem
->fState
& MF_GRAYED
) dis
.itemState
|= ODS_GRAYED
;
1054 if (lpitem
->fState
& MF_HILITE
) dis
.itemState
|= ODS_SELECTED
;
1055 dis
.itemAction
= odaction
; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
1056 dis
.hwndItem
= hmenu
;
1058 dis
.rcItem
= lpitem
->rect
;
1059 TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
1060 "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner
,
1061 dis
.itemID
, dis
.itemState
, dis
.itemAction
, dis
.hwndItem
,
1062 dis
.hDC
, dis
.rcItem
.left
, dis
.rcItem
.top
, dis
.rcItem
.right
,
1064 SendMessageA( hwndOwner
, WM_DRAWITEM
, 0, (LPARAM
)&dis
);
1068 TRACE("rect={%d,%d,%d,%d}\n", lpitem
->rect
.left
, lpitem
->rect
.top
,
1069 lpitem
->rect
.right
,lpitem
->rect
.bottom
);
1071 if (menuBar
&& (lpitem
->fType
& MF_SEPARATOR
)) return;
1073 rect
= lpitem
->rect
;
1075 if ((lpitem
->fState
& MF_HILITE
) && !(IS_BITMAP_ITEM(lpitem
->fType
)))
1076 if ((menuBar
) && (TWEAK_WineLook
==WIN98_LOOK
))
1077 DrawEdge(hdc
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
1079 FillRect( hdc
, &rect
, GetSysColorBrush(COLOR_HIGHLIGHT
) );
1081 FillRect( hdc
, &rect
, GetSysColorBrush(COLOR_MENU
) );
1083 SetBkMode( hdc
, TRANSPARENT
);
1085 /* vertical separator */
1086 if (!menuBar
&& (lpitem
->fType
& MF_MENUBARBREAK
))
1088 if (TWEAK_WineLook
> WIN31_LOOK
)
1092 rc
.bottom
= height
- 3;
1093 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_LEFT
);
1097 SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1098 MoveTo16( hdc
, rect
.left
, 0 );
1099 LineTo( hdc
, rect
.left
, height
);
1103 /* horizontal separator */
1104 if (lpitem
->fType
& MF_SEPARATOR
)
1106 if (TWEAK_WineLook
> WIN31_LOOK
)
1111 rc
.top
+= SEPARATOR_HEIGHT
/ 2;
1112 DrawEdge (hdc
, &rc
, EDGE_ETCHED
, BF_TOP
);
1116 SelectObject( hdc
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1117 MoveTo16( hdc
, rect
.left
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
1118 LineTo( hdc
, rect
.right
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
1125 if ((lpitem
->fState
& MF_HILITE
) && !(IS_BITMAP_ITEM(lpitem
->fType
)) )
1127 if (lpitem
->fState
& MF_GRAYED
)
1128 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
1130 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
1131 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
1135 if (lpitem
->fState
& MF_GRAYED
)
1136 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
1138 SetTextColor( hdc
, GetSysColor( COLOR_MENUTEXT
) );
1139 SetBkColor( hdc
, GetSysColor( COLOR_MENU
) );
1142 /* helper lines for debugging */
1143 /* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1144 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1145 MoveTo16( hdc, rect.left, (rect.top + rect.bottom)/2 );
1146 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1151 INT y
= rect
.top
+ rect
.bottom
;
1153 /* Draw the check mark
1156 * Custom checkmark bitmaps are monochrome but not always 1bpp.
1159 if (lpitem
->fState
& MF_CHECKED
)
1161 HBITMAP bm
= lpitem
->hCheckBit
? lpitem
->hCheckBit
:
1162 ((lpitem
->fType
& MFT_RADIOCHECK
) ? hStdRadioCheck
: hStdCheck
);
1163 HDC hdcMem
= CreateCompatibleDC( hdc
);
1165 SelectObject( hdcMem
, bm
);
1166 BitBlt( hdc
, rect
.left
, (y
- check_bitmap_height
) / 2,
1167 check_bitmap_width
, check_bitmap_height
,
1168 hdcMem
, 0, 0, SRCCOPY
);
1171 else if (lpitem
->hUnCheckBit
)
1173 HDC hdcMem
= CreateCompatibleDC( hdc
);
1175 SelectObject( hdcMem
, lpitem
->hUnCheckBit
);
1176 BitBlt( hdc
, rect
.left
, (y
- check_bitmap_height
) / 2,
1177 check_bitmap_width
, check_bitmap_height
,
1178 hdcMem
, 0, 0, SRCCOPY
);
1182 /* Draw the popup-menu arrow */
1183 if (lpitem
->fType
& MF_POPUP
)
1185 HDC hdcMem
= CreateCompatibleDC( hdc
);
1187 SelectObject( hdcMem
, hStdMnArrow
);
1188 BitBlt( hdc
, rect
.right
- arrow_bitmap_width
- 1,
1189 (y
- arrow_bitmap_height
) / 2,
1190 arrow_bitmap_width
, arrow_bitmap_height
,
1191 hdcMem
, 0, 0, SRCCOPY
);
1195 rect
.left
+= check_bitmap_width
;
1196 rect
.right
-= arrow_bitmap_width
;
1199 /* Draw the item text or bitmap */
1200 if (IS_BITMAP_ITEM(lpitem
->fType
))
1205 HDC hdcMem
= CreateCompatibleDC( hdc
);
1208 * Check if there is a magic menu item associated with this item
1209 * and load the appropriate bitmap
1211 if((LOWORD((int)lpitem
->text
)) < 12)
1213 resBmp
= MENU_LoadMagicItem((int)lpitem
->text
, (lpitem
->fState
& MF_HILITE
),
1214 lpitem
->dwItemData
);
1217 resBmp
= (HBITMAP
)lpitem
->text
;
1222 GetObjectA( resBmp
, sizeof(bm
), &bm
);
1224 SelectObject(hdcMem
,resBmp
);
1226 /* handle fontsize > bitmap_height */
1227 top
= ((rect
.bottom
-rect
.top
)>bm
.bmHeight
) ?
1228 rect
.top
+(rect
.bottom
-rect
.top
-bm
.bmHeight
)/2 : rect
.top
;
1230 BitBlt( hdc
, rect
.left
, top
, rect
.right
- rect
.left
,
1231 rect
.bottom
- rect
.top
, hdcMem
, 0, 0, SRCCOPY
);
1238 /* No bitmap - process text if present */
1239 else if (IS_STRING_ITEM(lpitem
->fType
))
1244 UINT uFormat
= (menuBar
) ?
1245 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
:
1246 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
;
1248 if ( lpitem
->fState
& MFS_DEFAULT
)
1250 hfontOld
= SelectObject( hdc
, hMenuFontBold
);
1255 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
1256 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
1257 i
= strlen( lpitem
->text
);
1261 for (i
= 0; lpitem
->text
[i
]; i
++)
1262 if ((lpitem
->text
[i
] == '\t') || (lpitem
->text
[i
] == '\b'))
1266 if( !(TWEAK_WineLook
== WIN31_LOOK
) && (lpitem
->fState
& MF_GRAYED
))
1268 if (!(lpitem
->fState
& MF_HILITE
) )
1270 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
1271 SetTextColor(hdc
, RGB(0xff, 0xff, 0xff));
1272 DrawTextA( hdc
, lpitem
->text
, i
, &rect
, uFormat
);
1273 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
1275 SetTextColor(hdc
, RGB(0x80, 0x80, 0x80));
1278 DrawTextA( hdc
, lpitem
->text
, i
, &rect
, uFormat
);
1280 /* paint the shortcut text */
1281 if (lpitem
->text
[i
]) /* There's a tab or flush-right char */
1283 if (lpitem
->text
[i
] == '\t')
1285 rect
.left
= lpitem
->xTab
;
1286 uFormat
= DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
;
1290 uFormat
= DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
;
1293 if( !(TWEAK_WineLook
== WIN31_LOOK
) && (lpitem
->fState
& MF_GRAYED
))
1295 if (!(lpitem
->fState
& MF_HILITE
) )
1297 ++rect
.left
; ++rect
.top
; ++rect
.right
; ++rect
.bottom
;
1298 SetTextColor(hdc
, RGB(0xff, 0xff, 0xff));
1299 DrawTextA( hdc
, lpitem
->text
+ i
+ 1, -1, &rect
, uFormat
);
1300 --rect
.left
; --rect
.top
; --rect
.right
; --rect
.bottom
;
1302 SetTextColor(hdc
, RGB(0x80, 0x80, 0x80));
1304 DrawTextA( hdc
, lpitem
->text
+ i
+ 1, -1, &rect
, uFormat
);
1308 SelectObject (hdc
, hfontOld
);
1313 /***********************************************************************
1314 * MENU_DrawPopupMenu
1316 * Paint a popup menu.
1318 static void MENU_DrawPopupMenu( HWND hwnd
, HDC hdc
, HMENU hmenu
)
1320 HBRUSH hPrevBrush
= 0;
1323 TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd
, hdc
, hmenu
);
1325 GetClientRect( hwnd
, &rect
);
1327 if(TWEAK_WineLook
== WIN31_LOOK
)
1329 rect
.bottom
-= POPUP_YSHADE
* GetSystemMetrics(SM_CYBORDER
);
1330 rect
.right
-= POPUP_XSHADE
* GetSystemMetrics(SM_CXBORDER
);
1333 if((hPrevBrush
= SelectObject( hdc
, GetSysColorBrush(COLOR_MENU
) ))
1334 && (SelectObject( hdc
, hMenuFont
)))
1338 Rectangle( hdc
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1340 hPrevPen
= SelectObject( hdc
, GetStockObject( NULL_PEN
) );
1346 /* draw 3-d shade */
1347 if(TWEAK_WineLook
== WIN31_LOOK
) {
1348 SelectObject( hdc
, hShadeBrush
);
1349 SetBkMode( hdc
, TRANSPARENT
);
1350 ropPrev
= SetROP2( hdc
, R2_MASKPEN
);
1352 i
= rect
.right
; /* why SetBrushOrg() doesn't? */
1353 PatBlt( hdc
, i
& 0xfffffffe,
1354 rect
.top
+ POPUP_YSHADE
*GetSystemMetrics(SM_CYBORDER
),
1355 i
%2 + POPUP_XSHADE
*GetSystemMetrics(SM_CXBORDER
),
1356 rect
.bottom
- rect
.top
, 0x00a000c9 );
1358 PatBlt( hdc
, rect
.left
+ POPUP_XSHADE
*GetSystemMetrics(SM_CXBORDER
),
1359 i
& 0xfffffffe,rect
.right
- rect
.left
,
1360 i
%2 + POPUP_YSHADE
*GetSystemMetrics(SM_CYBORDER
), 0x00a000c9 );
1361 SelectObject( hdc
, hPrevPen
);
1362 SelectObject( hdc
, hPrevBrush
);
1363 SetROP2( hdc
, ropPrev
);
1366 DrawEdge (hdc
, &rect
, EDGE_RAISED
, BF_RECT
);
1368 /* draw menu items */
1370 menu
= MENU_GetMenu( hmenu
);
1371 if (menu
&& menu
->nItems
)
1376 for (u
= menu
->nItems
, item
= menu
->items
; u
> 0; u
--, item
++)
1377 MENU_DrawMenuItem( hwnd
, hmenu
, menu
->hwndOwner
, hdc
, item
,
1378 menu
->Height
, FALSE
, ODA_DRAWENTIRE
);
1383 SelectObject( hdc
, hPrevBrush
);
1388 /***********************************************************************
1391 * Paint a menu bar. Returns the height of the menu bar.
1392 * called from [windows/nonclient.c]
1394 UINT
MENU_DrawMenuBar( HDC hDC
, LPRECT lprect
, HWND hwnd
,
1401 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1403 lppop
= MENU_GetMenu ((HMENU
)wndPtr
->wIDmenu
);
1404 if (lppop
== NULL
|| lprect
== NULL
)
1406 retvalue
= GetSystemMetrics(SM_CYMENU
);
1410 TRACE("(%04x, %p, %p)\n", hDC
, lprect
, lppop
);
1412 hfontOld
= SelectObject( hDC
, hMenuFont
);
1414 if (lppop
->Height
== 0)
1415 MENU_MenuBarCalcSize(hDC
, lprect
, lppop
, hwnd
);
1417 lprect
->bottom
= lprect
->top
+ lppop
->Height
;
1421 retvalue
= lppop
->Height
;
1425 FillRect(hDC
, lprect
, GetSysColorBrush(COLOR_MENU
) );
1427 if (TWEAK_WineLook
== WIN31_LOOK
)
1429 SelectObject( hDC
, GetSysColorPen(COLOR_WINDOWFRAME
) );
1430 MoveTo16( hDC
, lprect
->left
, lprect
->bottom
);
1431 LineTo( hDC
, lprect
->right
, lprect
->bottom
);
1435 SelectObject( hDC
, GetSysColorPen(COLOR_3DFACE
));
1436 MoveTo16( hDC
, lprect
->left
, lprect
->bottom
);
1437 LineTo( hDC
, lprect
->right
, lprect
->bottom
);
1440 if (lppop
->nItems
== 0)
1442 retvalue
= GetSystemMetrics(SM_CYMENU
);
1446 for (i
= 0; i
< lppop
->nItems
; i
++)
1448 MENU_DrawMenuItem( hwnd
, (HMENU
)wndPtr
->wIDmenu
, GetWindow(hwnd
,GW_OWNER
),
1449 hDC
, &lppop
->items
[i
], lppop
->Height
, TRUE
, ODA_DRAWENTIRE
);
1451 retvalue
= lppop
->Height
;
1455 SelectObject (hDC
, hfontOld
);
1457 WIN_ReleaseWndPtr(wndPtr
);
1461 /***********************************************************************
1462 * MENU_PatchResidentPopup
1464 BOOL
MENU_PatchResidentPopup( HQUEUE16 checkQueue
, WND
* checkWnd
)
1466 WND
*pTPWnd
= MENU_GetTopPopupWnd();
1472 TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
1473 checkQueue
, checkWnd
? checkWnd
->hwndSelf
: 0, pTPWnd
->hmemTaskQ
,
1474 pTPWnd
->owner
? pTPWnd
->owner
->hwndSelf
: 0);
1476 switch( checkQueue
)
1478 case 0: /* checkWnd is the new popup owner */
1481 pTPWnd
->owner
= checkWnd
;
1482 if( pTPWnd
->hmemTaskQ
!= checkWnd
->hmemTaskQ
)
1483 hTask
= QUEUE_GetQueueTask( checkWnd
->hmemTaskQ
);
1487 case 0xFFFF: /* checkWnd is destroyed */
1488 if( pTPWnd
->owner
== checkWnd
)
1489 pTPWnd
->owner
= NULL
;
1490 MENU_ReleaseTopPopupWnd();
1493 default: /* checkQueue is exiting */
1494 if( pTPWnd
->hmemTaskQ
== checkQueue
)
1496 hTask
= QUEUE_GetQueueTask( pTPWnd
->hmemTaskQ
);
1497 hTask
= TASK_GetNextTask( hTask
);
1504 TDB
* task
= (TDB
*)GlobalLock16( hTask
);
1507 pTPWnd
->hInstance
= task
->hInstance
;
1508 pTPWnd
->hmemTaskQ
= task
->hQueue
;
1509 MENU_ReleaseTopPopupWnd();
1512 else WARN("failed to patch resident popup.\n");
1515 MENU_ReleaseTopPopupWnd();
1519 /***********************************************************************
1522 * Display a popup menu.
1524 static BOOL
MENU_ShowPopup( HWND hwndOwner
, HMENU hmenu
, UINT id
,
1525 INT x
, INT y
, INT xanchor
, INT yanchor
)
1528 WND
*wndOwner
= NULL
;
1530 TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
1531 hwndOwner
, hmenu
, id
, x
, y
, xanchor
, yanchor
);
1533 if (!(menu
= MENU_GetMenu( hmenu
))) return FALSE
;
1534 if (menu
->FocusedItem
!= NO_SELECTED_ITEM
)
1536 menu
->items
[menu
->FocusedItem
].fState
&= ~(MF_HILITE
|MF_MOUSESELECT
);
1537 menu
->FocusedItem
= NO_SELECTED_ITEM
;
1540 /* store the owner for DrawItem*/
1541 menu
->hwndOwner
= hwndOwner
;
1543 if( (wndOwner
= WIN_FindWndPtr( hwndOwner
)) )
1547 MENU_PopupMenuCalcSize( menu
, hwndOwner
);
1549 /* adjust popup menu pos so that it fits within the desktop */
1551 width
= menu
->Width
+ GetSystemMetrics(SM_CXBORDER
);
1552 height
= menu
->Height
+ GetSystemMetrics(SM_CYBORDER
);
1554 if( x
+ width
> GetSystemMetrics(SM_CXSCREEN
))
1557 x
-= width
- xanchor
;
1558 if( x
+ width
> GetSystemMetrics(SM_CXSCREEN
))
1559 x
= GetSystemMetrics(SM_CXSCREEN
) - width
;
1563 if( y
+ height
> GetSystemMetrics(SM_CYSCREEN
))
1566 y
-= height
+ yanchor
;
1567 if( y
+ height
> GetSystemMetrics(SM_CYSCREEN
))
1568 y
= GetSystemMetrics(SM_CYSCREEN
) - height
;
1572 if( TWEAK_WineLook
== WIN31_LOOK
)
1574 width
+= POPUP_XSHADE
* GetSystemMetrics(SM_CXBORDER
); /* add space for shading */
1575 height
+= POPUP_YSHADE
* GetSystemMetrics(SM_CYBORDER
);
1578 /* NOTE: In Windows, top menu popup is not owned. */
1579 if (!pTopPopupWnd
) /* create top level popup menu window */
1581 assert( uSubPWndLevel
== 0 );
1583 pTopPopupWnd
= WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_ATOM
, NULL
,
1584 WS_POPUP
, x
, y
, width
, height
,
1585 hwndOwner
, 0, wndOwner
->hInstance
,
1589 WIN_ReleaseWndPtr(wndOwner
);
1592 menu
->hWnd
= pTopPopupWnd
->hwndSelf
;
1593 MENU_ReleaseTopPopupWnd();
1598 /* create a new window for the submenu */
1600 menu
->hWnd
= CreateWindowA( POPUPMENU_CLASS_ATOM
, NULL
,
1601 WS_POPUP
, x
, y
, width
, height
,
1602 hwndOwner
, 0, wndOwner
->hInstance
,
1606 WIN_ReleaseWndPtr(wndOwner
);
1610 else /* top level popup menu window already exists */
1612 WND
*pTPWnd
= MENU_GetTopPopupWnd();
1613 menu
->hWnd
= pTPWnd
->hwndSelf
;
1615 MENU_PatchResidentPopup( 0, wndOwner
);
1616 SendMessageA( pTPWnd
->hwndSelf
, MM_SETMENUHANDLE
, (WPARAM16
)hmenu
, 0L);
1618 /* adjust its size */
1620 SetWindowPos( menu
->hWnd
, 0, x
, y
, width
, height
,
1621 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_NOREDRAW
);
1622 MENU_ReleaseTopPopupWnd();
1625 uSubPWndLevel
++; /* menu level counter */
1627 /* Display the window */
1629 SetWindowPos( menu
->hWnd
, HWND_TOP
, 0, 0, 0, 0,
1630 SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1631 UpdateWindow( menu
->hWnd
);
1632 WIN_ReleaseWndPtr(wndOwner
);
1639 /***********************************************************************
1642 static void MENU_SelectItem( HWND hwndOwner
, HMENU hmenu
, UINT wIndex
,
1643 BOOL sendMenuSelect
, HMENU topmenu
)
1648 TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner
, hmenu
, wIndex
, sendMenuSelect
);
1650 lppop
= MENU_GetMenu( hmenu
);
1651 if ((!lppop
) || (!lppop
->nItems
)) return;
1653 if (lppop
->FocusedItem
== wIndex
) return;
1654 if (lppop
->wFlags
& MF_POPUP
) hdc
= GetDC( lppop
->hWnd
);
1655 else hdc
= GetDCEx( lppop
->hWnd
, 0, DCX_CACHE
| DCX_WINDOW
);
1657 SelectObject( hdc
, hMenuFont
);
1659 /* Clear previous highlighted item */
1660 if (lppop
->FocusedItem
!= NO_SELECTED_ITEM
)
1662 lppop
->items
[lppop
->FocusedItem
].fState
&= ~(MF_HILITE
|MF_MOUSESELECT
);
1663 MENU_DrawMenuItem(lppop
->hWnd
, hmenu
, hwndOwner
, hdc
,&lppop
->items
[lppop
->FocusedItem
],
1664 lppop
->Height
, !(lppop
->wFlags
& MF_POPUP
),
1668 /* Highlight new item (if any) */
1669 lppop
->FocusedItem
= wIndex
;
1670 if (lppop
->FocusedItem
!= NO_SELECTED_ITEM
)
1672 if(!(lppop
->items
[wIndex
].fType
& MF_SEPARATOR
)) {
1673 lppop
->items
[wIndex
].fState
|= MF_HILITE
;
1674 MENU_DrawMenuItem( lppop
->hWnd
, hmenu
, hwndOwner
, hdc
,
1675 &lppop
->items
[wIndex
], lppop
->Height
,
1676 !(lppop
->wFlags
& MF_POPUP
), ODA_SELECT
);
1680 MENUITEM
*ip
= &lppop
->items
[lppop
->FocusedItem
];
1681 SendMessageA( hwndOwner
, WM_MENUSELECT
,
1682 MAKELONG(ip
->fType
& MF_POPUP
? wIndex
: ip
->wID
,
1683 ip
->fType
| ip
->fState
| MF_MOUSESELECT
|
1684 (lppop
->wFlags
& MF_SYSMENU
)), hmenu
);
1687 else if (sendMenuSelect
) {
1690 if((pos
=MENU_FindSubMenu(&topmenu
, hmenu
))!=NO_SELECTED_ITEM
){
1691 POPUPMENU
*ptm
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( topmenu
);
1692 MENUITEM
*ip
= &ptm
->items
[pos
];
1693 SendMessageA( hwndOwner
, WM_MENUSELECT
, MAKELONG(pos
,
1694 ip
->fType
| ip
->fState
| MF_MOUSESELECT
|
1695 (ptm
->wFlags
& MF_SYSMENU
)), topmenu
);
1699 ReleaseDC( lppop
->hWnd
, hdc
);
1703 /***********************************************************************
1704 * MENU_MoveSelection
1706 * Moves currently selected item according to the offset parameter.
1707 * If there is no selection then it should select the last item if
1708 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
1710 static void MENU_MoveSelection( HWND hwndOwner
, HMENU hmenu
, INT offset
)
1715 TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner
, hmenu
, offset
);
1717 menu
= MENU_GetMenu( hmenu
);
1718 if ((!menu
) || (!menu
->items
)) return;
1720 if ( menu
->FocusedItem
!= NO_SELECTED_ITEM
)
1722 if( menu
->nItems
== 1 ) return; else
1723 for (i
= menu
->FocusedItem
+ offset
; i
>= 0 && i
< menu
->nItems
1725 if (!(menu
->items
[i
].fType
& MF_SEPARATOR
))
1727 MENU_SelectItem( hwndOwner
, hmenu
, i
, TRUE
, 0 );
1732 for ( i
= (offset
> 0) ? 0 : menu
->nItems
- 1;
1733 i
>= 0 && i
< menu
->nItems
; i
+= offset
)
1734 if (!(menu
->items
[i
].fType
& MF_SEPARATOR
))
1736 MENU_SelectItem( hwndOwner
, hmenu
, i
, TRUE
, 0 );
1742 /**********************************************************************
1745 * Set an item flags, id and text ptr. Called by InsertMenu() and
1748 static BOOL
MENU_SetItemData( MENUITEM
*item
, UINT flags
, UINT id
,
1751 LPSTR prevText
= IS_STRING_ITEM(item
->fType
) ? item
->text
: NULL
;
1753 debug_print_menuitem("MENU_SetItemData from: ", item
, "");
1755 if (IS_STRING_ITEM(flags
))
1759 flags
|= MF_SEPARATOR
;
1765 /* Item beginning with a backspace is a help item */
1771 if (!(text
= HEAP_strdupA( SystemHeap
, 0, str
))) return FALSE
;
1775 else if (IS_BITMAP_ITEM(flags
))
1776 item
->text
= (LPSTR
)(HBITMAP
)LOWORD(str
);
1777 else item
->text
= NULL
;
1779 if (flags
& MF_OWNERDRAW
)
1780 item
->dwItemData
= (DWORD
)str
;
1782 item
->dwItemData
= 0;
1784 if ((item
->fType
& MF_POPUP
) && (flags
& MF_POPUP
) && (item
->hSubMenu
!= id
) )
1785 DestroyMenu( item
->hSubMenu
); /* ModifyMenu() spec */
1787 if (flags
& MF_POPUP
)
1789 POPUPMENU
*menu
= MENU_GetMenu((UINT16
)id
);
1790 if (menu
) menu
->wFlags
|= MF_POPUP
;
1802 if (flags
& MF_POPUP
)
1803 item
->hSubMenu
= id
;
1805 if ((item
->fType
& MF_POPUP
) && !(flags
& MF_POPUP
) )
1806 flags
|= MF_POPUP
; /* keep popup */
1808 item
->fType
= flags
& TYPE_MASK
;
1809 item
->fState
= (flags
& STATE_MASK
) &
1810 ~(MF_HILITE
| MF_MOUSESELECT
| MF_BYPOSITION
);
1813 /* Don't call SetRectEmpty here! */
1816 if (prevText
) HeapFree( SystemHeap
, 0, prevText
);
1818 debug_print_menuitem("MENU_SetItemData to : ", item
, "");
1823 /**********************************************************************
1826 * Insert a new item into a menu.
1828 static MENUITEM
*MENU_InsertItem( HMENU hMenu
, UINT pos
, UINT flags
)
1833 if (!(menu
= MENU_GetMenu(hMenu
)))
1836 /* Find where to insert new item */
1838 if ((pos
==(UINT
)-1) || ((flags
& MF_BYPOSITION
) && (pos
== menu
->nItems
))) {
1839 /* Special case: append to menu */
1840 /* Some programs specify the menu length to do that */
1843 if (!MENU_FindItem( &hMenu
, &pos
, flags
))
1845 FIXME("item %x not found\n", pos
);
1848 if (!(menu
= MENU_GetMenu(hMenu
)))
1852 /* Create new items array */
1854 newItems
= HeapAlloc( SystemHeap
, 0, sizeof(MENUITEM
) * (menu
->nItems
+1) );
1857 WARN("allocation failed\n" );
1860 if (menu
->nItems
> 0)
1862 /* Copy the old array into the new */
1863 if (pos
> 0) memcpy( newItems
, menu
->items
, pos
* sizeof(MENUITEM
) );
1864 if (pos
< menu
->nItems
) memcpy( &newItems
[pos
+1], &menu
->items
[pos
],
1865 (menu
->nItems
-pos
)*sizeof(MENUITEM
) );
1866 HeapFree( SystemHeap
, 0, menu
->items
);
1868 menu
->items
= newItems
;
1870 memset( &newItems
[pos
], 0, sizeof(*newItems
) );
1871 menu
->Height
= 0; /* force size recalculate */
1872 return &newItems
[pos
];
1876 /**********************************************************************
1877 * MENU_ParseResource
1879 * Parse a standard menu resource and add items to the menu.
1880 * Return a pointer to the end of the resource.
1882 static LPCSTR
MENU_ParseResource( LPCSTR res
, HMENU hMenu
, BOOL unicode
)
1889 flags
= GET_WORD(res
);
1890 res
+= sizeof(WORD
);
1891 if (!(flags
& MF_POPUP
))
1894 res
+= sizeof(WORD
);
1896 if (!IS_STRING_ITEM(flags
))
1897 ERR("not a string item %04x\n", flags
);
1899 if (!unicode
) res
+= strlen(str
) + 1;
1900 else res
+= (lstrlenW((LPCWSTR
)str
) + 1) * sizeof(WCHAR
);
1901 if (flags
& MF_POPUP
)
1903 HMENU hSubMenu
= CreatePopupMenu();
1904 if (!hSubMenu
) return NULL
;
1905 if (!(res
= MENU_ParseResource( res
, hSubMenu
, unicode
)))
1907 if (!unicode
) AppendMenuA( hMenu
, flags
, (UINT
)hSubMenu
, str
);
1908 else AppendMenuW( hMenu
, flags
, (UINT
)hSubMenu
, (LPCWSTR
)str
);
1910 else /* Not a popup */
1912 if (!unicode
) AppendMenuA( hMenu
, flags
, id
, *str
? str
: NULL
);
1913 else AppendMenuW( hMenu
, flags
, id
,
1914 *(LPCWSTR
)str
? (LPCWSTR
)str
: NULL
);
1916 } while (!(flags
& MF_END
));
1921 /**********************************************************************
1922 * MENUEX_ParseResource
1924 * Parse an extended menu resource and add items to the menu.
1925 * Return a pointer to the end of the resource.
1927 static LPCSTR
MENUEX_ParseResource( LPCSTR res
, HMENU hMenu
)
1933 mii
.cbSize
= sizeof(mii
);
1934 mii
.fMask
= MIIM_STATE
| MIIM_ID
| MIIM_TYPE
;
1935 mii
.fType
= GET_DWORD(res
);
1936 res
+= sizeof(DWORD
);
1937 mii
.fState
= GET_DWORD(res
);
1938 res
+= sizeof(DWORD
);
1939 mii
.wID
= GET_DWORD(res
);
1940 res
+= sizeof(DWORD
);
1941 resinfo
= GET_WORD(res
); /* FIXME: for 16-bit apps this is a byte. */
1942 res
+= sizeof(WORD
);
1943 /* Align the text on a word boundary. */
1944 res
+= (~((int)res
- 1)) & 1;
1945 mii
.dwTypeData
= (LPWSTR
) res
;
1946 res
+= (1 + lstrlenW(mii
.dwTypeData
)) * sizeof(WCHAR
);
1947 /* Align the following fields on a dword boundary. */
1948 res
+= (~((int)res
- 1)) & 3;
1950 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1952 LPSTR newstr
= HEAP_strdupWtoA(GetProcessHeap(),
1954 TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
1955 mii
.fType
, mii
.fState
, mii
.wID
, resinfo
, newstr
);
1956 HeapFree( GetProcessHeap(), 0, newstr
);
1959 if (resinfo
& 1) { /* Pop-up? */
1960 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
1961 res
+= sizeof(DWORD
);
1962 mii
.hSubMenu
= CreatePopupMenu();
1965 if (!(res
= MENUEX_ParseResource(res
, mii
.hSubMenu
))) {
1966 DestroyMenu(mii
.hSubMenu
);
1969 mii
.fMask
|= MIIM_SUBMENU
;
1970 mii
.fType
|= MF_POPUP
;
1972 InsertMenuItemW(hMenu
, -1, MF_BYPOSITION
, &mii
);
1973 } while (!(resinfo
& MF_END
));
1978 /***********************************************************************
1981 * Return the handle of the selected sub-popup menu (if any).
1983 static HMENU
MENU_GetSubPopup( HMENU hmenu
)
1988 menu
= MENU_GetMenu( hmenu
);
1990 if ((!menu
) || (menu
->FocusedItem
== NO_SELECTED_ITEM
)) return 0;
1992 item
= &menu
->items
[menu
->FocusedItem
];
1993 if ((item
->fType
& MF_POPUP
) && (item
->fState
& MF_MOUSESELECT
))
1994 return item
->hSubMenu
;
1999 /***********************************************************************
2000 * MENU_HideSubPopups
2002 * Hide the sub-popup menus of this menu.
2004 static void MENU_HideSubPopups( HWND hwndOwner
, HMENU hmenu
,
2005 BOOL sendMenuSelect
)
2007 POPUPMENU
*menu
= MENU_GetMenu( hmenu
);
2009 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner
, hmenu
, sendMenuSelect
);
2011 if (menu
&& uSubPWndLevel
)
2017 if (menu
->FocusedItem
!= NO_SELECTED_ITEM
)
2019 item
= &menu
->items
[menu
->FocusedItem
];
2020 if (!(item
->fType
& MF_POPUP
) ||
2021 !(item
->fState
& MF_MOUSESELECT
)) return;
2022 item
->fState
&= ~MF_MOUSESELECT
;
2023 hsubmenu
= item
->hSubMenu
;
2026 submenu
= MENU_GetMenu( hsubmenu
);
2027 MENU_HideSubPopups( hwndOwner
, hsubmenu
, FALSE
);
2028 MENU_SelectItem( hwndOwner
, hsubmenu
, NO_SELECTED_ITEM
, sendMenuSelect
, 0 );
2030 if (submenu
->hWnd
== MENU_GetTopPopupWnd()->hwndSelf
)
2032 ShowWindow( submenu
->hWnd
, SW_HIDE
);
2037 DestroyWindow( submenu
->hWnd
);
2040 MENU_ReleaseTopPopupWnd();
2045 /***********************************************************************
2048 * Display the sub-menu of the selected item of this menu.
2049 * Return the handle of the submenu, or hmenu if no submenu to display.
2051 static HMENU
MENU_ShowSubPopup( HWND hwndOwner
, HMENU hmenu
,
2052 BOOL selectFirst
, UINT wFlags
)
2060 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner
, hmenu
, selectFirst
);
2062 if (!(menu
= MENU_GetMenu( hmenu
))) return hmenu
;
2064 if (!(wndPtr
= WIN_FindWndPtr( menu
->hWnd
)) ||
2065 (menu
->FocusedItem
== NO_SELECTED_ITEM
))
2067 WIN_ReleaseWndPtr(wndPtr
);
2071 item
= &menu
->items
[menu
->FocusedItem
];
2072 if (!(item
->fType
& MF_POPUP
) ||
2073 (item
->fState
& (MF_GRAYED
| MF_DISABLED
)))
2075 WIN_ReleaseWndPtr(wndPtr
);
2079 /* message must be send before using item,
2080 because nearly everything may by changed by the application ! */
2082 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2083 if (!(wFlags
& TPM_NONOTIFY
))
2084 SendMessageA( hwndOwner
, WM_INITMENUPOPUP
, item
->hSubMenu
,
2085 MAKELONG( menu
->FocusedItem
, IS_SYSTEM_MENU(menu
) ));
2087 item
= &menu
->items
[menu
->FocusedItem
];
2090 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2091 if (!(item
->fState
& MF_HILITE
))
2093 if (menu
->wFlags
& MF_POPUP
) hdc
= GetDC( menu
->hWnd
);
2094 else hdc
= GetDCEx( menu
->hWnd
, 0, DCX_CACHE
| DCX_WINDOW
);
2096 SelectObject( hdc
, hMenuFont
);
2098 item
->fState
|= MF_HILITE
;
2099 MENU_DrawMenuItem( menu
->hWnd
, hmenu
, hwndOwner
, hdc
, item
, menu
->Height
, !(menu
->wFlags
& MF_POPUP
), ODA_DRAWENTIRE
);
2100 ReleaseDC( menu
->hWnd
, hdc
);
2102 if (!item
->rect
.top
&& !item
->rect
.left
&& !item
->rect
.bottom
&& !item
->rect
.right
)
2105 item
->fState
|= MF_MOUSESELECT
;
2107 if (IS_SYSTEM_MENU(menu
))
2109 MENU_InitSysMenuPopup(item
->hSubMenu
, wndPtr
->dwStyle
, GetClassLongA(wndPtr
->hwndSelf
, GCL_STYLE
));
2111 NC_GetSysPopupPos( wndPtr
, &rect
);
2112 rect
.top
= rect
.bottom
;
2113 rect
.right
= GetSystemMetrics(SM_CXSIZE
);
2114 rect
.bottom
= GetSystemMetrics(SM_CYSIZE
);
2118 if (menu
->wFlags
& MF_POPUP
)
2120 rect
.left
= wndPtr
->rectWindow
.left
+ item
->rect
.right
-arrow_bitmap_width
;
2121 rect
.top
= wndPtr
->rectWindow
.top
+ item
->rect
.top
;
2122 rect
.right
= item
->rect
.left
- item
->rect
.right
+ 2*arrow_bitmap_width
;
2123 rect
.bottom
= item
->rect
.top
- item
->rect
.bottom
;
2127 rect
.left
= wndPtr
->rectWindow
.left
+ item
->rect
.left
;
2128 rect
.top
= wndPtr
->rectWindow
.top
+ item
->rect
.bottom
;
2129 rect
.right
= item
->rect
.right
- item
->rect
.left
;
2130 rect
.bottom
= item
->rect
.bottom
- item
->rect
.top
;
2134 MENU_ShowPopup( hwndOwner
, item
->hSubMenu
, menu
->FocusedItem
,
2135 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
2137 MENU_MoveSelection( hwndOwner
, item
->hSubMenu
, ITEM_NEXT
);
2138 WIN_ReleaseWndPtr(wndPtr
);
2139 return item
->hSubMenu
;
2142 /***********************************************************************
2145 * Walks menu chain trying to find a menu pt maps to.
2147 static HMENU
MENU_PtMenu( HMENU hMenu
, POINT16 pt
)
2149 POPUPMENU
*menu
= MENU_GetMenu( hMenu
);
2150 register UINT ht
= menu
->FocusedItem
;
2152 /* try subpopup first (if any) */
2153 ht
= (ht
!= NO_SELECTED_ITEM
&&
2154 (menu
->items
[ht
].fType
& MF_POPUP
) &&
2155 (menu
->items
[ht
].fState
& MF_MOUSESELECT
))
2156 ? (UINT
) MENU_PtMenu(menu
->items
[ht
].hSubMenu
, pt
) : 0;
2158 if( !ht
) /* check the current window (avoiding WM_HITTEST) */
2160 ht
= (UINT
)NC_HandleNCHitTest( menu
->hWnd
, pt
);
2161 if( menu
->wFlags
& MF_POPUP
)
2162 ht
= (ht
!= (UINT
)HTNOWHERE
&&
2163 ht
!= (UINT
)HTERROR
) ? (UINT
)hMenu
: 0;
2166 WND
* wndPtr
= WIN_FindWndPtr(menu
->hWnd
);
2168 ht
= ( ht
== HTSYSMENU
) ? (UINT
)(wndPtr
->hSysMenu
)
2169 : ( ht
== HTMENU
) ? (UINT
)(wndPtr
->wIDmenu
) : 0;
2170 WIN_ReleaseWndPtr(wndPtr
);
2176 /***********************************************************************
2177 * MENU_ExecFocusedItem
2179 * Execute a menu item (for instance when user pressed Enter).
2180 * Return the wID of the executed item. Otherwise, -1 indicating
2181 * that no menu item wase executed;
2182 * Have to receive the flags for the TrackPopupMenu options to avoid
2183 * sending unwanted message.
2186 static INT
MENU_ExecFocusedItem( MTRACKER
* pmt
, HMENU hMenu
, UINT wFlags
)
2189 POPUPMENU
*menu
= MENU_GetMenu( hMenu
);
2191 TRACE("%p hmenu=0x%04x\n", pmt
, hMenu
);
2193 if (!menu
|| !menu
->nItems
||
2194 (menu
->FocusedItem
== NO_SELECTED_ITEM
)) return -1;
2196 item
= &menu
->items
[menu
->FocusedItem
];
2198 TRACE("%08x %08x %08x\n",
2199 hMenu
, item
->wID
, item
->hSubMenu
);
2201 if (!(item
->fType
& MF_POPUP
))
2203 if (!(item
->fState
& (MF_GRAYED
| MF_DISABLED
)))
2205 /* If TPM_RETURNCMD is set you return the id, but
2206 do not send a message to the owner */
2207 if(!(wFlags
& TPM_RETURNCMD
))
2209 if( menu
->wFlags
& MF_SYSMENU
)
2210 PostMessageA( pmt
->hOwnerWnd
, WM_SYSCOMMAND
, item
->wID
,
2211 MAKELPARAM((INT16
)pmt
->pt
.x
, (INT16
)pmt
->pt
.y
) );
2213 PostMessageA( pmt
->hOwnerWnd
, WM_COMMAND
, item
->wID
, 0 );
2219 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
, hMenu
, TRUE
, wFlags
);
2224 /***********************************************************************
2225 * MENU_SwitchTracking
2227 * Helper function for menu navigation routines.
2229 static void MENU_SwitchTracking( MTRACKER
* pmt
, HMENU hPtMenu
, UINT id
)
2231 POPUPMENU
*ptmenu
= MENU_GetMenu( hPtMenu
);
2232 POPUPMENU
*topmenu
= MENU_GetMenu( pmt
->hTopMenu
);
2234 TRACE("%p hmenu=0x%04x 0x%04x\n", pmt
, hPtMenu
, id
);
2236 if( pmt
->hTopMenu
!= hPtMenu
&&
2237 !((ptmenu
->wFlags
| topmenu
->wFlags
) & MF_POPUP
) )
2239 /* both are top level menus (system and menu-bar) */
2240 MENU_HideSubPopups( pmt
->hOwnerWnd
, pmt
->hTopMenu
, FALSE
);
2241 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hTopMenu
, NO_SELECTED_ITEM
, FALSE
, 0 );
2242 pmt
->hTopMenu
= hPtMenu
;
2244 else MENU_HideSubPopups( pmt
->hOwnerWnd
, hPtMenu
, FALSE
);
2245 MENU_SelectItem( pmt
->hOwnerWnd
, hPtMenu
, id
, TRUE
, 0 );
2249 /***********************************************************************
2252 * Return TRUE if we can go on with menu tracking.
2254 static BOOL
MENU_ButtonDown( MTRACKER
* pmt
, HMENU hPtMenu
, UINT wFlags
)
2256 TRACE("%p hmenu=0x%04x\n", pmt
, hPtMenu
);
2261 POPUPMENU
*ptmenu
= MENU_GetMenu( hPtMenu
);
2264 if( IS_SYSTEM_MENU(ptmenu
) )
2265 item
= ptmenu
->items
;
2267 item
= MENU_FindItemByCoords( ptmenu
, pmt
->pt
, &id
);
2271 if( ptmenu
->FocusedItem
!= id
)
2272 MENU_SwitchTracking( pmt
, hPtMenu
, id
);
2274 /* If the popup menu is not already "popped" */
2275 if(!(item
->fState
& MF_MOUSESELECT
))
2277 pmt
->hCurrentMenu
= MENU_ShowSubPopup( pmt
->hOwnerWnd
, hPtMenu
, FALSE
, wFlags
);
2279 /* In win31, a newly popped menu always remain opened for the next buttonup */
2280 if(TWEAK_WineLook
== WIN31_LOOK
)
2281 ptmenu
->bTimeToHide
= FALSE
;
2286 /* Else the click was on the menu bar, finish the tracking */
2291 /***********************************************************************
2294 * Return the value of MENU_ExecFocusedItem if
2295 * the selected item was not a popup. Else open the popup.
2296 * A -1 return value indicates that we go on with menu tracking.
2299 static INT
MENU_ButtonUp( MTRACKER
* pmt
, HMENU hPtMenu
, UINT wFlags
)
2301 TRACE("%p hmenu=0x%04x\n", pmt
, hPtMenu
);
2306 POPUPMENU
*ptmenu
= MENU_GetMenu( hPtMenu
);
2309 if( IS_SYSTEM_MENU(ptmenu
) )
2310 item
= ptmenu
->items
;
2312 item
= MENU_FindItemByCoords( ptmenu
, pmt
->pt
, &id
);
2314 if( item
&& (ptmenu
->FocusedItem
== id
))
2316 if( !(item
->fType
& MF_POPUP
) )
2317 return MENU_ExecFocusedItem( pmt
, hPtMenu
, wFlags
);
2319 /* If we are dealing with the top-level menu and that this */
2320 /* is a click on an already "poppped" item */
2321 /* Stop the menu tracking and close the opened submenus */
2322 if((pmt
->hTopMenu
== hPtMenu
) && (ptmenu
->bTimeToHide
== TRUE
))
2325 ptmenu
->bTimeToHide
= TRUE
;
2331 /***********************************************************************
2334 * Return TRUE if we can go on with menu tracking.
2336 static BOOL
MENU_MouseMove( MTRACKER
* pmt
, HMENU hPtMenu
, UINT wFlags
)
2338 UINT id
= NO_SELECTED_ITEM
;
2339 POPUPMENU
*ptmenu
= NULL
;
2343 ptmenu
= MENU_GetMenu( hPtMenu
);
2344 if( IS_SYSTEM_MENU(ptmenu
) )
2347 MENU_FindItemByCoords( ptmenu
, pmt
->pt
, &id
);
2350 if( id
== NO_SELECTED_ITEM
)
2352 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hCurrentMenu
,
2353 NO_SELECTED_ITEM
, TRUE
, pmt
->hTopMenu
);
2356 else if( ptmenu
->FocusedItem
!= id
)
2358 MENU_SwitchTracking( pmt
, hPtMenu
, id
);
2359 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
, hPtMenu
, FALSE
, wFlags
);
2365 /***********************************************************************
2368 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
2370 static LRESULT
MENU_DoNextMenu( MTRACKER
* pmt
, UINT vk
)
2372 POPUPMENU
*menu
= MENU_GetMenu( pmt
->hTopMenu
);
2374 if( (vk
== VK_LEFT
&& menu
->FocusedItem
== 0 ) ||
2375 (vk
== VK_RIGHT
&& menu
->FocusedItem
== menu
->nItems
- 1))
2381 LRESULT l
= SendMessageA( pmt
->hOwnerWnd
, WM_NEXTMENU
, vk
,
2382 (IS_SYSTEM_MENU(menu
)) ? GetSubMenu16(pmt
->hTopMenu
,0) : pmt
->hTopMenu
);
2384 TRACE("%04x [%04x] -> %04x [%04x]\n",
2385 (UINT16
)pmt
->hCurrentMenu
, (UINT16
)pmt
->hOwnerWnd
, LOWORD(l
), HIWORD(l
) );
2389 wndPtr
= WIN_FindWndPtr(pmt
->hOwnerWnd
);
2391 hNewWnd
= pmt
->hOwnerWnd
;
2392 if( IS_SYSTEM_MENU(menu
) )
2394 /* switch to the menu bar */
2396 if( wndPtr
->dwStyle
& WS_CHILD
|| !wndPtr
->wIDmenu
)
2398 WIN_ReleaseWndPtr(wndPtr
);
2402 hNewMenu
= wndPtr
->wIDmenu
;
2405 menu
= MENU_GetMenu( hNewMenu
);
2406 id
= menu
->nItems
- 1;
2409 else if( wndPtr
->dwStyle
& WS_SYSMENU
)
2411 /* switch to the system menu */
2412 hNewMenu
= wndPtr
->hSysMenu
;
2416 WIN_ReleaseWndPtr(wndPtr
);
2419 WIN_ReleaseWndPtr(wndPtr
);
2421 else /* application returned a new menu to switch to */
2423 hNewMenu
= LOWORD(l
); hNewWnd
= HIWORD(l
);
2425 if( IsMenu(hNewMenu
) && IsWindow(hNewWnd
) )
2427 wndPtr
= WIN_FindWndPtr(hNewWnd
);
2429 if( wndPtr
->dwStyle
& WS_SYSMENU
&&
2430 GetSubMenu16(wndPtr
->hSysMenu
, 0) == hNewMenu
)
2432 /* get the real system menu */
2433 hNewMenu
= wndPtr
->hSysMenu
;
2435 else if( wndPtr
->dwStyle
& WS_CHILD
|| wndPtr
->wIDmenu
!= hNewMenu
)
2437 /* FIXME: Not sure what to do here, perhaps,
2438 * try to track hNewMenu as a popup? */
2440 TRACE(" -- got confused.\n");
2441 WIN_ReleaseWndPtr(wndPtr
);
2444 WIN_ReleaseWndPtr(wndPtr
);
2449 if( hNewMenu
!= pmt
->hTopMenu
)
2451 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hTopMenu
, NO_SELECTED_ITEM
,
2453 if( pmt
->hCurrentMenu
!= pmt
->hTopMenu
)
2454 MENU_HideSubPopups( pmt
->hOwnerWnd
, pmt
->hTopMenu
, FALSE
);
2457 if( hNewWnd
!= pmt
->hOwnerWnd
)
2460 pmt
->hOwnerWnd
= hNewWnd
;
2461 EVENT_Capture( pmt
->hOwnerWnd
, HTMENU
);
2464 pmt
->hTopMenu
= pmt
->hCurrentMenu
= hNewMenu
; /* all subpopups are hidden */
2465 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hTopMenu
, id
, TRUE
, 0 );
2472 /***********************************************************************
2475 * The idea is not to show the popup if the next input message is
2476 * going to hide it anyway.
2478 static BOOL
MENU_SuspendPopup( MTRACKER
* pmt
, UINT16 uMsg
)
2482 msg
.hwnd
= pmt
->hOwnerWnd
;
2484 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_REMOVE
);
2485 pmt
->trackFlags
|= TF_SKIPREMOVE
;
2490 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_NOREMOVE
);
2491 if( msg
.message
== WM_KEYUP
|| msg
.message
== WM_PAINT
)
2493 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_REMOVE
);
2494 PeekMessageA( &msg
, 0, 0, 0, PM_NOYIELD
| PM_NOREMOVE
);
2495 if( msg
.message
== WM_KEYDOWN
&&
2496 (msg
.wParam
== VK_LEFT
|| msg
.wParam
== VK_RIGHT
))
2498 pmt
->trackFlags
|= TF_SUSPENDPOPUP
;
2505 /* failures go through this */
2506 pmt
->trackFlags
&= ~TF_SUSPENDPOPUP
;
2510 /***********************************************************************
2513 * Handle a VK_LEFT key event in a menu.
2515 static void MENU_KeyLeft( MTRACKER
* pmt
, UINT wFlags
)
2518 HMENU hmenutmp
, hmenuprev
;
2521 hmenuprev
= hmenutmp
= pmt
->hTopMenu
;
2522 menu
= MENU_GetMenu( hmenutmp
);
2524 /* Try to move 1 column left (if possible) */
2525 if( (prevcol
= MENU_GetStartOfPrevColumn( pmt
->hCurrentMenu
)) !=
2526 NO_SELECTED_ITEM
) {
2528 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hCurrentMenu
,
2533 /* close topmost popup */
2534 while (hmenutmp
!= pmt
->hCurrentMenu
)
2536 hmenuprev
= hmenutmp
;
2537 hmenutmp
= MENU_GetSubPopup( hmenuprev
);
2540 MENU_HideSubPopups( pmt
->hOwnerWnd
, hmenuprev
, TRUE
);
2541 pmt
->hCurrentMenu
= hmenuprev
;
2543 if ( (hmenuprev
== pmt
->hTopMenu
) && !(menu
->wFlags
& MF_POPUP
) )
2545 /* move menu bar selection if no more popups are left */
2547 if( !MENU_DoNextMenu( pmt
, VK_LEFT
) )
2548 MENU_MoveSelection( pmt
->hOwnerWnd
, pmt
->hTopMenu
, ITEM_PREV
);
2550 if ( hmenuprev
!= hmenutmp
|| pmt
->trackFlags
& TF_SUSPENDPOPUP
)
2552 /* A sublevel menu was displayed - display the next one
2553 * unless there is another displacement coming up */
2555 if( !MENU_SuspendPopup( pmt
, WM_KEYDOWN
) )
2556 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
,
2557 pmt
->hTopMenu
, TRUE
, wFlags
);
2563 /***********************************************************************
2566 * Handle a VK_RIGHT key event in a menu.
2568 static void MENU_KeyRight( MTRACKER
* pmt
, UINT wFlags
)
2571 POPUPMENU
*menu
= MENU_GetMenu( pmt
->hTopMenu
);
2574 TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
2576 (MENU_GetMenu(pmt
->hCurrentMenu
))->
2578 pmt
->hTopMenu
, menu
->items
[0].text
);
2580 if ( (menu
->wFlags
& MF_POPUP
) || (pmt
->hCurrentMenu
!= pmt
->hTopMenu
))
2582 /* If already displaying a popup, try to display sub-popup */
2584 hmenutmp
= pmt
->hCurrentMenu
;
2585 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
, hmenutmp
, TRUE
, wFlags
);
2587 /* if subpopup was displayed then we are done */
2588 if (hmenutmp
!= pmt
->hCurrentMenu
) return;
2591 /* Check to see if there's another column */
2592 if( (nextcol
= MENU_GetStartOfNextColumn( pmt
->hCurrentMenu
)) !=
2593 NO_SELECTED_ITEM
) {
2594 TRACE("Going to %d.\n", nextcol
);
2595 MENU_SelectItem( pmt
->hOwnerWnd
, pmt
->hCurrentMenu
,
2600 if (!(menu
->wFlags
& MF_POPUP
)) /* menu bar tracking */
2602 if( pmt
->hCurrentMenu
!= pmt
->hTopMenu
)
2604 MENU_HideSubPopups( pmt
->hOwnerWnd
, pmt
->hTopMenu
, FALSE
);
2605 hmenutmp
= pmt
->hCurrentMenu
= pmt
->hTopMenu
;
2606 } else hmenutmp
= 0;
2608 /* try to move to the next item */
2609 if( !MENU_DoNextMenu( pmt
, VK_RIGHT
) )
2610 MENU_MoveSelection( pmt
->hOwnerWnd
, pmt
->hTopMenu
, ITEM_NEXT
);
2612 if( hmenutmp
|| pmt
->trackFlags
& TF_SUSPENDPOPUP
)
2613 if( !MENU_SuspendPopup(pmt
, WM_KEYDOWN
) )
2614 pmt
->hCurrentMenu
= MENU_ShowSubPopup(pmt
->hOwnerWnd
,
2615 pmt
->hTopMenu
, TRUE
, wFlags
);
2619 /***********************************************************************
2622 * Menu tracking code.
2624 static INT
MENU_TrackMenu( HMENU hmenu
, UINT wFlags
, INT x
, INT y
,
2625 HWND hwnd
, const RECT
*lprect
)
2630 INT executedMenuId
= -1;
2632 BOOL enterIdleSent
= FALSE
;
2635 mt
.hCurrentMenu
= hmenu
;
2636 mt
.hTopMenu
= hmenu
;
2637 mt
.hOwnerWnd
= hwnd
;
2641 TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
2642 hmenu
, wFlags
, x
, y
, hwnd
, (lprect
) ? lprect
->left
: 0, (lprect
) ? lprect
->top
: 0,
2643 (lprect
) ? lprect
->right
: 0, (lprect
) ? lprect
->bottom
: 0);
2646 if (!(menu
= MENU_GetMenu( hmenu
))) return FALSE
;
2648 if (wFlags
& TPM_BUTTONDOWN
)
2650 /* Get the result in order to start the tracking or not */
2651 fRemove
= MENU_ButtonDown( &mt
, hmenu
, wFlags
);
2652 fEndMenu
= !fRemove
;
2655 EVENT_Capture( mt
.hOwnerWnd
, HTMENU
);
2659 menu
= MENU_GetMenu( mt
.hCurrentMenu
);
2660 msg
.hwnd
= (wFlags
& TPM_ENTERIDLEEX
&& menu
->wFlags
& MF_POPUP
) ? menu
->hWnd
: 0;
2662 /* we have to keep the message in the queue until it's
2663 * clear that menu loop is not over yet. */
2665 if (!MSG_InternalGetMessage( QMSG_WIN32A
, &msg
, msg
.hwnd
, mt
.hOwnerWnd
,
2666 MSGF_MENU
, PM_NOREMOVE
, !enterIdleSent
, &enterIdleSent
)) break;
2668 TranslateMessage( &msg
);
2671 if ( (msg
.hwnd
==menu
->hWnd
) || (msg
.message
!=WM_TIMER
) )
2672 enterIdleSent
=FALSE
;
2675 if ((msg
.message
>= WM_MOUSEFIRST
) && (msg
.message
<= WM_MOUSELAST
))
2677 /* Find a menu for this mouse event */
2679 CONV_POINT32TO16( &msg
.pt
, &pt16
);
2680 hmenu
= MENU_PtMenu( mt
.hTopMenu
, pt16
);
2684 /* no WM_NC... messages in captured state */
2686 case WM_RBUTTONDBLCLK
:
2687 case WM_RBUTTONDOWN
:
2688 if (!(wFlags
& TPM_RIGHTBUTTON
)) break;
2690 case WM_LBUTTONDBLCLK
:
2691 case WM_LBUTTONDOWN
:
2692 /* If the message belongs to the menu, removes it from the queue */
2693 /* Else, end menu tracking */
2694 fRemove
= MENU_ButtonDown( &mt
, hmenu
, wFlags
);
2695 fEndMenu
= !fRemove
;
2699 if (!(wFlags
& TPM_RIGHTBUTTON
)) break;
2702 /* Check if a menu was selected by the mouse */
2705 executedMenuId
= MENU_ButtonUp( &mt
, hmenu
, wFlags
);
2707 /* End the loop if executedMenuId is an item ID */
2708 /* or if the job was done (executedMenuId = 0). */
2709 fEndMenu
= fRemove
= (executedMenuId
!= -1);
2711 /* No menu was selected by the mouse */
2712 /* if the function was called by TrackPopupMenu, continue
2713 with the menu tracking. If not, stop it */
2715 fEndMenu
= ((wFlags
& TPM_POPUPMENU
) ? FALSE
: TRUE
);
2720 /* In win95 winelook, the selected menu item must be changed every time the
2721 mouse moves. In Win31 winelook, the mouse button has to be held down */
2723 if ( (TWEAK_WineLook
> WIN31_LOOK
) ||
2724 ( (msg
.wParam
& MK_LBUTTON
) ||
2725 ((wFlags
& TPM_RIGHTBUTTON
) && (msg
.wParam
& MK_RBUTTON
))) )
2727 fEndMenu
|= !MENU_MouseMove( &mt
, hmenu
, wFlags
);
2729 } /* switch(msg.message) - mouse */
2731 else if ((msg
.message
>= WM_KEYFIRST
) && (msg
.message
<= WM_KEYLAST
))
2733 fRemove
= TRUE
; /* Keyboard messages are always removed */
2741 MENU_SelectItem( mt
.hOwnerWnd
, mt
.hCurrentMenu
,
2742 NO_SELECTED_ITEM
, FALSE
, 0 );
2745 MENU_MoveSelection( mt
.hOwnerWnd
, mt
.hCurrentMenu
,
2746 (msg
.wParam
== VK_HOME
)? ITEM_NEXT
: ITEM_PREV
);
2749 case VK_DOWN
: /* If on menu bar, pull-down the menu */
2751 menu
= MENU_GetMenu( mt
.hCurrentMenu
);
2752 if (!(menu
->wFlags
& MF_POPUP
))
2753 mt
.hCurrentMenu
= MENU_ShowSubPopup(mt
.hOwnerWnd
, mt
.hTopMenu
, TRUE
, wFlags
);
2754 else /* otherwise try to move selection */
2755 MENU_MoveSelection( mt
.hOwnerWnd
, mt
.hCurrentMenu
, ITEM_NEXT
);
2759 MENU_KeyLeft( &mt
, wFlags
);
2763 MENU_KeyRight( &mt
, wFlags
);
2773 break; /* WM_KEYDOWN */
2783 break; /* WM_SYSKEYDOWN */
2789 if (msg
.wParam
== '\r' || msg
.wParam
== ' ')
2791 executedMenuId
= MENU_ExecFocusedItem(&mt
,mt
.hCurrentMenu
, wFlags
);
2792 fEndMenu
= (executedMenuId
!= -1);
2797 /* Hack to avoid control chars. */
2798 /* We will find a better way real soon... */
2799 if ((msg
.wParam
<= 32) || (msg
.wParam
>= 127)) break;
2801 pos
= MENU_FindItemByKey( mt
.hOwnerWnd
, mt
.hCurrentMenu
,
2802 LOWORD(msg
.wParam
), FALSE
);
2803 if (pos
== (UINT
)-2) fEndMenu
= TRUE
;
2804 else if (pos
== (UINT
)-1) MessageBeep(0);
2807 MENU_SelectItem( mt
.hOwnerWnd
, mt
.hCurrentMenu
, pos
,
2809 executedMenuId
= MENU_ExecFocusedItem(&mt
,mt
.hCurrentMenu
, wFlags
);
2810 fEndMenu
= (executedMenuId
!= -1);
2814 } /* switch(msg.message) - kbd */
2818 DispatchMessageA( &msg
);
2821 if (!fEndMenu
) fRemove
= TRUE
;
2823 /* finally remove message from the queue */
2825 if (fRemove
&& !(mt
.trackFlags
& TF_SKIPREMOVE
) )
2826 PeekMessageA( &msg
, 0, msg
.message
, msg
.message
, PM_REMOVE
);
2827 else mt
.trackFlags
&= ~TF_SKIPREMOVE
;
2832 menu
= MENU_GetMenu( mt
.hTopMenu
);
2834 if( IsWindow( mt
.hOwnerWnd
) )
2836 MENU_HideSubPopups( mt
.hOwnerWnd
, mt
.hTopMenu
, FALSE
);
2838 if (menu
&& menu
->wFlags
& MF_POPUP
)
2840 ShowWindow( menu
->hWnd
, SW_HIDE
);
2843 MENU_SelectItem( mt
.hOwnerWnd
, mt
.hTopMenu
, NO_SELECTED_ITEM
, FALSE
, 0 );
2844 SendMessageA( mt
.hOwnerWnd
, WM_MENUSELECT
, MAKELONG(0,0xffff), 0 );
2847 /* Reset the variable for hiding menu */
2848 menu
->bTimeToHide
= FALSE
;
2850 /* The return value is only used by TrackPopupMenu */
2851 return ((executedMenuId
!= -1) ? executedMenuId
: 0);
2854 /***********************************************************************
2857 static BOOL
MENU_InitTracking(HWND hWnd
, HMENU hMenu
, BOOL bPopup
, UINT wFlags
)
2859 TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd
, hMenu
);
2863 /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
2864 if (!(wFlags
& TPM_NONOTIFY
))
2865 SendMessageA( hWnd
, WM_ENTERMENULOOP
, bPopup
, 0 );
2867 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
, HTCAPTION
);
2869 if (!(wFlags
& TPM_NONOTIFY
))
2870 SendMessageA( hWnd
, WM_INITMENU
, hMenu
, 0 );
2874 /***********************************************************************
2877 static BOOL
MENU_ExitTracking(HWND hWnd
)
2879 TRACE("hwnd=0x%04x\n", hWnd
);
2881 SendMessageA( hWnd
, WM_EXITMENULOOP
, 0, 0 );
2886 /***********************************************************************
2887 * MENU_TrackMouseMenuBar
2889 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2891 void MENU_TrackMouseMenuBar( WND
* wndPtr
, INT ht
, POINT pt
)
2893 HWND hWnd
= wndPtr
->hwndSelf
;
2894 HMENU hMenu
= (ht
== HTSYSMENU
) ? wndPtr
->hSysMenu
: wndPtr
->wIDmenu
;
2895 UINT wFlags
= TPM_ENTERIDLEEX
| TPM_BUTTONDOWN
| TPM_LEFTALIGN
| TPM_LEFTBUTTON
;
2897 TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr
, ht
, pt
.x
, pt
.y
);
2901 MENU_InitTracking( hWnd
, hMenu
, FALSE
, wFlags
);
2902 MENU_TrackMenu( hMenu
, wFlags
, pt
.x
, pt
.y
, hWnd
, NULL
);
2903 MENU_ExitTracking(hWnd
);
2908 /***********************************************************************
2909 * MENU_TrackKbdMenuBar
2911 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2913 void MENU_TrackKbdMenuBar( WND
* wndPtr
, UINT wParam
, INT vkey
)
2915 UINT uItem
= NO_SELECTED_ITEM
;
2917 UINT wFlags
= TPM_ENTERIDLEEX
| TPM_LEFTALIGN
| TPM_LEFTBUTTON
;
2919 /* find window that has a menu */
2921 while( wndPtr
->dwStyle
& WS_CHILD
)
2922 if( !(wndPtr
= wndPtr
->parent
) ) return;
2924 /* check if we have to track a system menu */
2926 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_MINIMIZE
)) ||
2927 !wndPtr
->wIDmenu
|| vkey
== VK_SPACE
)
2929 if( !(wndPtr
->dwStyle
& WS_SYSMENU
) ) return;
2930 hTrackMenu
= wndPtr
->hSysMenu
;
2932 wParam
|= HTSYSMENU
; /* prevent item lookup */
2935 hTrackMenu
= wndPtr
->wIDmenu
;
2937 if (IsMenu( hTrackMenu
))
2939 MENU_InitTracking( wndPtr
->hwndSelf
, hTrackMenu
, FALSE
, wFlags
);
2941 if( vkey
&& vkey
!= VK_SPACE
)
2943 uItem
= MENU_FindItemByKey( wndPtr
->hwndSelf
, hTrackMenu
,
2944 vkey
, (wParam
& HTSYSMENU
) );
2945 if( uItem
>= (UINT
)(-2) )
2947 if( uItem
== (UINT
)(-1) ) MessageBeep(0);
2954 MENU_SelectItem( wndPtr
->hwndSelf
, hTrackMenu
, uItem
, TRUE
, 0 );
2956 if( uItem
== NO_SELECTED_ITEM
)
2957 MENU_MoveSelection( wndPtr
->hwndSelf
, hTrackMenu
, ITEM_NEXT
);
2959 PostMessageA( wndPtr
->hwndSelf
, WM_KEYDOWN
, VK_DOWN
, 0L );
2961 MENU_TrackMenu( hTrackMenu
, wFlags
, 0, 0, wndPtr
->hwndSelf
, NULL
);
2964 MENU_ExitTracking (wndPtr
->hwndSelf
);
2969 /**********************************************************************
2970 * TrackPopupMenu16 (USER.416)
2972 BOOL16 WINAPI
TrackPopupMenu16( HMENU16 hMenu
, UINT16 wFlags
, INT16 x
, INT16 y
,
2973 INT16 nReserved
, HWND16 hWnd
, const RECT16
*lpRect
)
2977 CONV_RECT16TO32( lpRect
, &r
);
2978 return TrackPopupMenu( hMenu
, wFlags
, x
, y
, nReserved
, hWnd
,
2979 lpRect
? &r
: NULL
);
2983 /**********************************************************************
2984 * TrackPopupMenu (USER32.549)
2986 * Like the win32 API, the function return the command ID only if the
2987 * flag TPM_RETURNCMD is on.
2990 BOOL WINAPI
TrackPopupMenu( HMENU hMenu
, UINT wFlags
, INT x
, INT y
,
2991 INT nReserved
, HWND hWnd
, const RECT
*lpRect
)
2995 MENU_InitTracking(hWnd
, hMenu
, TRUE
, wFlags
);
2997 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2998 if (!(wFlags
& TPM_NONOTIFY
))
2999 SendMessageA( hWnd
, WM_INITMENUPOPUP
, hMenu
, 0);
3001 if (MENU_ShowPopup( hWnd
, hMenu
, 0, x
, y
, 0, 0 ))
3002 ret
= MENU_TrackMenu( hMenu
, wFlags
| TPM_POPUPMENU
, 0, 0, hWnd
, lpRect
);
3003 MENU_ExitTracking(hWnd
);
3005 if( (!(wFlags
& TPM_RETURNCMD
)) && (ret
!= FALSE
) )
3011 /**********************************************************************
3012 * TrackPopupMenuEx (USER32.550)
3014 BOOL WINAPI
TrackPopupMenuEx( HMENU hMenu
, UINT wFlags
, INT x
, INT y
,
3015 HWND hWnd
, LPTPMPARAMS lpTpm
)
3017 FIXME("not fully implemented\n" );
3018 return TrackPopupMenu( hMenu
, wFlags
, x
, y
, 0, hWnd
,
3019 lpTpm
? &lpTpm
->rcExclude
: NULL
);
3022 /***********************************************************************
3025 * NOTE: Windows has totally different (and undocumented) popup wndproc.
3027 LRESULT WINAPI
PopupMenuWndProc( HWND hwnd
, UINT message
, WPARAM wParam
,
3030 WND
* wndPtr
= WIN_FindWndPtr(hwnd
);
3033 TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
3034 hwnd
, message
, wParam
, lParam
);
3040 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
3041 SetWindowLongA( hwnd
, 0, (LONG
)cs
->lpCreateParams
);
3046 case WM_MOUSEACTIVATE
: /* We don't want to be activated */
3047 retvalue
= MA_NOACTIVATE
;
3053 BeginPaint( hwnd
, &ps
);
3054 MENU_DrawPopupMenu( hwnd
, ps
.hdc
,
3055 (HMENU
)GetWindowLongA( hwnd
, 0 ) );
3056 EndPaint( hwnd
, &ps
);
3066 /* zero out global pointer in case resident popup window
3067 * was somehow destroyed. */
3069 if(MENU_GetTopPopupWnd() )
3071 if( hwnd
== pTopPopupWnd
->hwndSelf
)
3073 ERR("resident popup destroyed!\n");
3075 MENU_DestroyTopPopupWnd();
3080 MENU_ReleaseTopPopupWnd();
3088 if( !(*(HMENU
*)wndPtr
->wExtra
) )
3089 ERR("no menu to display\n");
3092 *(HMENU
*)wndPtr
->wExtra
= 0;
3095 case MM_SETMENUHANDLE
:
3097 *(HMENU
*)wndPtr
->wExtra
= (HMENU
)wParam
;
3100 case MM_GETMENUHANDLE
:
3102 retvalue
= *(HMENU
*)wndPtr
->wExtra
;
3106 retvalue
= DefWindowProcA( hwnd
, message
, wParam
, lParam
);
3111 WIN_ReleaseWndPtr(wndPtr
);
3116 /***********************************************************************
3117 * MENU_GetMenuBarHeight
3119 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3121 UINT
MENU_GetMenuBarHeight( HWND hwnd
, UINT menubarWidth
,
3122 INT orgX
, INT orgY
)
3130 TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
3131 hwnd
, menubarWidth
, orgX
, orgY
);
3133 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
3136 if (!(lppop
= MENU_GetMenu((HMENU16
)wndPtr
->wIDmenu
)))
3138 WIN_ReleaseWndPtr(wndPtr
);
3142 hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
3143 SelectObject( hdc
, hMenuFont
);
3144 SetRect(&rectBar
, orgX
, orgY
, orgX
+menubarWidth
, orgY
+GetSystemMetrics(SM_CYMENU
));
3145 MENU_MenuBarCalcSize( hdc
, &rectBar
, lppop
, hwnd
);
3146 ReleaseDC( hwnd
, hdc
);
3147 retvalue
= lppop
->Height
;
3148 WIN_ReleaseWndPtr(wndPtr
);
3153 /*******************************************************************
3154 * ChangeMenu16 (USER.153)
3156 BOOL16 WINAPI
ChangeMenu16( HMENU16 hMenu
, UINT16 pos
, SEGPTR data
,
3157 UINT16 id
, UINT16 flags
)
3159 TRACE("menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
3160 hMenu
, pos
, (DWORD
)data
, id
, flags
);
3161 if (flags
& MF_APPEND
) return AppendMenu16( hMenu
, flags
& ~MF_APPEND
,
3164 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
3165 /* for MF_DELETE. We should check the parameters for all others */
3166 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
3168 if (flags
& MF_DELETE
) return DeleteMenu16(hMenu
, pos
, flags
& ~MF_DELETE
);
3169 if (flags
& MF_CHANGE
) return ModifyMenu16(hMenu
, pos
, flags
& ~MF_CHANGE
,
3171 if (flags
& MF_REMOVE
) return RemoveMenu16(hMenu
,
3172 flags
& MF_BYPOSITION
? pos
: id
,
3173 flags
& ~MF_REMOVE
);
3174 /* Default: MF_INSERT */
3175 return InsertMenu16( hMenu
, pos
, flags
, id
, data
);
3179 /*******************************************************************
3180 * ChangeMenu32A (USER32.23)
3182 BOOL WINAPI
ChangeMenuA( HMENU hMenu
, UINT pos
, LPCSTR data
,
3183 UINT id
, UINT flags
)
3185 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3186 hMenu
, pos
, (DWORD
)data
, id
, flags
);
3187 if (flags
& MF_APPEND
) return AppendMenuA( hMenu
, flags
& ~MF_APPEND
,
3189 if (flags
& MF_DELETE
) return DeleteMenu(hMenu
, pos
, flags
& ~MF_DELETE
);
3190 if (flags
& MF_CHANGE
) return ModifyMenuA(hMenu
, pos
, flags
& ~MF_CHANGE
,
3192 if (flags
& MF_REMOVE
) return RemoveMenu( hMenu
,
3193 flags
& MF_BYPOSITION
? pos
: id
,
3194 flags
& ~MF_REMOVE
);
3195 /* Default: MF_INSERT */
3196 return InsertMenuA( hMenu
, pos
, flags
, id
, data
);
3200 /*******************************************************************
3201 * ChangeMenu32W (USER32.24)
3203 BOOL WINAPI
ChangeMenuW( HMENU hMenu
, UINT pos
, LPCWSTR data
,
3204 UINT id
, UINT flags
)
3206 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3207 hMenu
, pos
, (DWORD
)data
, id
, flags
);
3208 if (flags
& MF_APPEND
) return AppendMenuW( hMenu
, flags
& ~MF_APPEND
,
3210 if (flags
& MF_DELETE
) return DeleteMenu(hMenu
, pos
, flags
& ~MF_DELETE
);
3211 if (flags
& MF_CHANGE
) return ModifyMenuW(hMenu
, pos
, flags
& ~MF_CHANGE
,
3213 if (flags
& MF_REMOVE
) return RemoveMenu( hMenu
,
3214 flags
& MF_BYPOSITION
? pos
: id
,
3215 flags
& ~MF_REMOVE
);
3216 /* Default: MF_INSERT */
3217 return InsertMenuW( hMenu
, pos
, flags
, id
, data
);
3221 /*******************************************************************
3222 * CheckMenuItem16 (USER.154)
3224 BOOL16 WINAPI
CheckMenuItem16( HMENU16 hMenu
, UINT16 id
, UINT16 flags
)
3226 return (BOOL16
)CheckMenuItem( hMenu
, id
, flags
);
3230 /*******************************************************************
3231 * CheckMenuItem (USER32.46)
3233 DWORD WINAPI
CheckMenuItem( HMENU hMenu
, UINT id
, UINT flags
)
3238 TRACE("menu=%04x id=%04x flags=%04x\n", hMenu
, id
, flags
);
3239 if (!(item
= MENU_FindItem( &hMenu
, &id
, flags
))) return -1;
3240 ret
= item
->fState
& MF_CHECKED
;
3241 if (flags
& MF_CHECKED
) item
->fState
|= MF_CHECKED
;
3242 else item
->fState
&= ~MF_CHECKED
;
3247 /**********************************************************************
3248 * EnableMenuItem16 (USER.155)
3250 UINT16 WINAPI
EnableMenuItem16( HMENU16 hMenu
, UINT16 wItemID
, UINT16 wFlags
)
3252 return EnableMenuItem( hMenu
, wItemID
, wFlags
);
3256 /**********************************************************************
3257 * EnableMenuItem32 (USER32.170)
3259 UINT WINAPI
EnableMenuItem( HMENU hMenu
, UINT wItemID
, UINT wFlags
)
3265 TRACE("(%04x, %04X, %04X) !\n",
3266 hMenu
, wItemID
, wFlags
);
3268 /* Get the Popupmenu to access the owner menu */
3269 if (!(menu
= MENU_GetMenu(hMenu
)))
3272 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
)))
3275 oldflags
= item
->fState
& (MF_GRAYED
| MF_DISABLED
);
3276 item
->fState
^= (oldflags
^ wFlags
) & (MF_GRAYED
| MF_DISABLED
);
3278 /* In win95 if the close item in the system menu change update the close button */
3279 if (TWEAK_WineLook
== WIN95_LOOK
)
3280 if((item
->wID
== SC_CLOSE
) && (oldflags
!= wFlags
))
3282 if (menu
->hSysMenuOwner
!= 0)
3284 POPUPMENU
* parentMenu
;
3286 /* Get the parent menu to access*/
3287 if (!(parentMenu
= MENU_GetMenu(menu
->hSysMenuOwner
)))
3290 /* Refresh the frame to reflect the change*/
3291 SetWindowPos(parentMenu
->hWnd
, 0, 0, 0, 0, 0,
3292 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
);
3300 /*******************************************************************
3301 * GetMenuString16 (USER.161)
3303 INT16 WINAPI
GetMenuString16( HMENU16 hMenu
, UINT16 wItemID
,
3304 LPSTR str
, INT16 nMaxSiz
, UINT16 wFlags
)
3306 return GetMenuStringA( hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
3310 /*******************************************************************
3311 * GetMenuString32A (USER32.268)
3313 INT WINAPI
GetMenuStringA(
3314 HMENU hMenu
, /* [in] menuhandle */
3315 UINT wItemID
, /* [in] menu item (dep. on wFlags) */
3316 LPSTR str
, /* [out] outbuffer. If NULL, func returns entry length*/
3317 INT nMaxSiz
, /* [in] length of buffer. if 0, func returns entry len*/
3318 UINT wFlags
/* [in] MF_ flags */
3322 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3323 hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
3324 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return 0;
3325 if (!IS_STRING_ITEM(item
->fType
)) return 0;
3326 if (!str
|| !nMaxSiz
) return strlen(item
->text
);
3328 lstrcpynA( str
, item
->text
, nMaxSiz
);
3329 TRACE("returning '%s'\n", str
);
3334 /*******************************************************************
3335 * GetMenuString32W (USER32.269)
3337 INT WINAPI
GetMenuStringW( HMENU hMenu
, UINT wItemID
,
3338 LPWSTR str
, INT nMaxSiz
, UINT wFlags
)
3342 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3343 hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
3344 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return 0;
3345 if (!IS_STRING_ITEM(item
->fType
)) return 0;
3346 if (!str
|| !nMaxSiz
) return strlen(item
->text
);
3348 lstrcpynAtoW( str
, item
->text
, nMaxSiz
);
3349 return lstrlenW(str
);
3353 /**********************************************************************
3354 * HiliteMenuItem16 (USER.162)
3356 BOOL16 WINAPI
HiliteMenuItem16( HWND16 hWnd
, HMENU16 hMenu
, UINT16 wItemID
,
3359 return HiliteMenuItem( hWnd
, hMenu
, wItemID
, wHilite
);
3363 /**********************************************************************
3364 * HiliteMenuItem32 (USER32.318)
3366 BOOL WINAPI
HiliteMenuItem( HWND hWnd
, HMENU hMenu
, UINT wItemID
,
3370 TRACE("(%04x, %04x, %04x, %04x);\n",
3371 hWnd
, hMenu
, wItemID
, wHilite
);
3372 if (!MENU_FindItem( &hMenu
, &wItemID
, wHilite
)) return FALSE
;
3373 if (!(menu
= MENU_GetMenu(hMenu
))) return FALSE
;
3374 if (menu
->FocusedItem
== wItemID
) return TRUE
;
3375 MENU_HideSubPopups( hWnd
, hMenu
, FALSE
);
3376 MENU_SelectItem( hWnd
, hMenu
, wItemID
, TRUE
, 0 );
3381 /**********************************************************************
3382 * GetMenuState16 (USER.250)
3384 UINT16 WINAPI
GetMenuState16( HMENU16 hMenu
, UINT16 wItemID
, UINT16 wFlags
)
3386 return GetMenuState( hMenu
, wItemID
, wFlags
);
3390 /**********************************************************************
3391 * GetMenuState (USER32.267)
3393 UINT WINAPI
GetMenuState( HMENU hMenu
, UINT wItemID
, UINT wFlags
)
3396 TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
3397 hMenu
, wItemID
, wFlags
);
3398 if (!(item
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return -1;
3399 debug_print_menuitem (" item: ", item
, "");
3400 if (item
->fType
& MF_POPUP
)
3402 POPUPMENU
*menu
= MENU_GetMenu( item
->hSubMenu
);
3403 if (!menu
) return -1;
3404 else return (menu
->nItems
<< 8) | ((item
->fState
|item
->fType
) & 0xff);
3408 /* We used to (from way back then) mask the result to 0xff. */
3409 /* I don't know why and it seems wrong as the documented */
3410 /* return flag MF_SEPARATOR is outside that mask. */
3411 return (item
->fType
| item
->fState
);
3416 /**********************************************************************
3417 * GetMenuItemCount16 (USER.263)
3419 INT16 WINAPI
GetMenuItemCount16( HMENU16 hMenu
)
3421 LPPOPUPMENU menu
= MENU_GetMenu(hMenu
);
3422 if (!menu
) return -1;
3423 TRACE("(%04x) returning %d\n",
3424 hMenu
, menu
->nItems
);
3425 return menu
->nItems
;
3429 /**********************************************************************
3430 * GetMenuItemCount32 (USER32.262)
3432 INT WINAPI
GetMenuItemCount( HMENU hMenu
)
3434 LPPOPUPMENU menu
= MENU_GetMenu(hMenu
);
3435 if (!menu
) return -1;
3436 TRACE("(%04x) returning %d\n",
3437 hMenu
, menu
->nItems
);
3438 return menu
->nItems
;
3441 /**********************************************************************
3442 * GetMenuItemID16 (USER.264)
3444 UINT16 WINAPI
GetMenuItemID16( HMENU16 hMenu
, INT16 nPos
)
3446 return (UINT16
) GetMenuItemID (hMenu
, nPos
);
3449 /**********************************************************************
3450 * GetMenuItemID32 (USER32.263)
3452 UINT WINAPI
GetMenuItemID( HMENU hMenu
, INT nPos
)
3456 if (!(lpmi
= MENU_FindItem(&hMenu
,&nPos
,MF_BYPOSITION
))) return 0;
3457 if (lpmi
->fType
& MF_POPUP
) return -1;
3462 /*******************************************************************
3463 * InsertMenu16 (USER.410)
3465 BOOL16 WINAPI
InsertMenu16( HMENU16 hMenu
, UINT16 pos
, UINT16 flags
,
3466 UINT16 id
, SEGPTR data
)
3468 UINT pos32
= (UINT
)pos
;
3469 if ((pos
== (UINT16
)-1) && (flags
& MF_BYPOSITION
)) pos32
= (UINT
)-1;
3470 if (IS_STRING_ITEM(flags
) && data
)
3471 return InsertMenuA( hMenu
, pos32
, flags
, id
,
3472 (LPSTR
)PTR_SEG_TO_LIN(data
) );
3473 return InsertMenuA( hMenu
, pos32
, flags
, id
, (LPSTR
)data
);
3477 /*******************************************************************
3478 * InsertMenu32A (USER32.322)
3480 BOOL WINAPI
InsertMenuA( HMENU hMenu
, UINT pos
, UINT flags
,
3481 UINT id
, LPCSTR str
)
3485 if (IS_STRING_ITEM(flags
) && str
)
3486 TRACE("hMenu %04x, pos %d, flags %08x, "
3487 "id %04x, str '%s'\n",
3488 hMenu
, pos
, flags
, id
, str
);
3489 else TRACE("hMenu %04x, pos %d, flags %08x, "
3490 "id %04x, str %08lx (not a string)\n",
3491 hMenu
, pos
, flags
, id
, (DWORD
)str
);
3493 if (!(item
= MENU_InsertItem( hMenu
, pos
, flags
))) return FALSE
;
3495 if (!(MENU_SetItemData( item
, flags
, id
, str
)))
3497 RemoveMenu( hMenu
, pos
, flags
);
3501 if (flags
& MF_POPUP
) /* Set the MF_POPUP flag on the popup-menu */
3502 (MENU_GetMenu((HMENU16
)id
))->wFlags
|= MF_POPUP
;
3504 item
->hCheckBit
= item
->hUnCheckBit
= 0;
3509 /*******************************************************************
3510 * InsertMenu32W (USER32.325)
3512 BOOL WINAPI
InsertMenuW( HMENU hMenu
, UINT pos
, UINT flags
,
3513 UINT id
, LPCWSTR str
)
3517 if (IS_STRING_ITEM(flags
) && str
)
3519 LPSTR newstr
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
3520 ret
= InsertMenuA( hMenu
, pos
, flags
, id
, newstr
);
3521 HeapFree( GetProcessHeap(), 0, newstr
);
3524 else return InsertMenuA( hMenu
, pos
, flags
, id
, (LPCSTR
)str
);
3528 /*******************************************************************
3529 * AppendMenu16 (USER.411)
3531 BOOL16 WINAPI
AppendMenu16(HMENU16 hMenu
, UINT16 flags
, UINT16 id
, SEGPTR data
)
3533 return InsertMenu16( hMenu
, -1, flags
| MF_BYPOSITION
, id
, data
);
3537 /*******************************************************************
3538 * AppendMenu32A (USER32.5)
3540 BOOL WINAPI
AppendMenuA( HMENU hMenu
, UINT flags
,
3541 UINT id
, LPCSTR data
)
3543 return InsertMenuA( hMenu
, -1, flags
| MF_BYPOSITION
, id
, data
);
3547 /*******************************************************************
3548 * AppendMenu32W (USER32.6)
3550 BOOL WINAPI
AppendMenuW( HMENU hMenu
, UINT flags
,
3551 UINT id
, LPCWSTR data
)
3553 return InsertMenuW( hMenu
, -1, flags
| MF_BYPOSITION
, id
, data
);
3557 /**********************************************************************
3558 * RemoveMenu16 (USER.412)
3560 BOOL16 WINAPI
RemoveMenu16( HMENU16 hMenu
, UINT16 nPos
, UINT16 wFlags
)
3562 return RemoveMenu( hMenu
, nPos
, wFlags
);
3566 /**********************************************************************
3567 * RemoveMenu (USER32.441)
3569 BOOL WINAPI
RemoveMenu( HMENU hMenu
, UINT nPos
, UINT wFlags
)
3574 TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu
, nPos
, wFlags
);
3575 if (!(item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
3576 if (!(menu
= MENU_GetMenu(hMenu
))) return FALSE
;
3580 MENU_FreeItemData( item
);
3582 if (--menu
->nItems
== 0)
3584 HeapFree( SystemHeap
, 0, menu
->items
);
3589 while(nPos
< menu
->nItems
)
3595 menu
->items
= HeapReAlloc( SystemHeap
, 0, menu
->items
,
3596 menu
->nItems
* sizeof(MENUITEM
) );
3602 /**********************************************************************
3603 * DeleteMenu16 (USER.413)
3605 BOOL16 WINAPI
DeleteMenu16( HMENU16 hMenu
, UINT16 nPos
, UINT16 wFlags
)
3607 return DeleteMenu( hMenu
, nPos
, wFlags
);
3611 /**********************************************************************
3612 * DeleteMenu32 (USER32.129)
3614 BOOL WINAPI
DeleteMenu( HMENU hMenu
, UINT nPos
, UINT wFlags
)
3616 MENUITEM
*item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
);
3617 if (!item
) return FALSE
;
3618 if (item
->fType
& MF_POPUP
) DestroyMenu( item
->hSubMenu
);
3619 /* nPos is now the position of the item */
3620 RemoveMenu( hMenu
, nPos
, wFlags
| MF_BYPOSITION
);
3625 /*******************************************************************
3626 * ModifyMenu16 (USER.414)
3628 BOOL16 WINAPI
ModifyMenu16( HMENU16 hMenu
, UINT16 pos
, UINT16 flags
,
3629 UINT16 id
, SEGPTR data
)
3631 if (IS_STRING_ITEM(flags
))
3632 return ModifyMenuA( hMenu
, pos
, flags
, id
,
3633 (LPSTR
)PTR_SEG_TO_LIN(data
) );
3634 return ModifyMenuA( hMenu
, pos
, flags
, id
, (LPSTR
)data
);
3638 /*******************************************************************
3639 * ModifyMenu32A (USER32.397)
3641 BOOL WINAPI
ModifyMenuA( HMENU hMenu
, UINT pos
, UINT flags
,
3642 UINT id
, LPCSTR str
)
3646 if (IS_STRING_ITEM(flags
))
3648 TRACE("%04x %d %04x %04x '%s'\n",
3649 hMenu
, pos
, flags
, id
, str
? str
: "#NULL#" );
3650 if (!str
) return FALSE
;
3654 TRACE("%04x %d %04x %04x %08lx\n",
3655 hMenu
, pos
, flags
, id
, (DWORD
)str
);
3658 if (!(item
= MENU_FindItem( &hMenu
, &pos
, flags
))) return FALSE
;
3659 return MENU_SetItemData( item
, flags
, id
, str
);
3663 /*******************************************************************
3664 * ModifyMenu32W (USER32.398)
3666 BOOL WINAPI
ModifyMenuW( HMENU hMenu
, UINT pos
, UINT flags
,
3667 UINT id
, LPCWSTR str
)
3671 if (IS_STRING_ITEM(flags
) && str
)
3673 LPSTR newstr
= HEAP_strdupWtoA( GetProcessHeap(), 0, str
);
3674 ret
= ModifyMenuA( hMenu
, pos
, flags
, id
, newstr
);
3675 HeapFree( GetProcessHeap(), 0, newstr
);
3678 else return ModifyMenuA( hMenu
, pos
, flags
, id
, (LPCSTR
)str
);
3682 /**********************************************************************
3683 * CreatePopupMenu16 (USER.415)
3685 HMENU16 WINAPI
CreatePopupMenu16(void)
3687 return CreatePopupMenu();
3691 /**********************************************************************
3692 * CreatePopupMenu32 (USER32.82)
3694 HMENU WINAPI
CreatePopupMenu(void)
3699 if (!(hmenu
= CreateMenu())) return 0;
3700 menu
= (POPUPMENU
*) USER_HEAP_LIN_ADDR( hmenu
);
3701 menu
->wFlags
|= MF_POPUP
;
3702 menu
->bTimeToHide
= FALSE
;
3707 /**********************************************************************
3708 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
3710 DWORD WINAPI
GetMenuCheckMarkDimensions(void)
3712 return MAKELONG( check_bitmap_width
, check_bitmap_height
);
3716 /**********************************************************************
3717 * SetMenuItemBitmaps16 (USER.418)
3719 BOOL16 WINAPI
SetMenuItemBitmaps16( HMENU16 hMenu
, UINT16 nPos
, UINT16 wFlags
,
3720 HBITMAP16 hNewUnCheck
, HBITMAP16 hNewCheck
)
3722 return SetMenuItemBitmaps( hMenu
, nPos
, wFlags
, hNewUnCheck
, hNewCheck
);
3726 /**********************************************************************
3727 * SetMenuItemBitmaps32 (USER32.490)
3729 BOOL WINAPI
SetMenuItemBitmaps( HMENU hMenu
, UINT nPos
, UINT wFlags
,
3730 HBITMAP hNewUnCheck
, HBITMAP hNewCheck
)
3733 TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
3734 hMenu
, nPos
, wFlags
, hNewCheck
, hNewUnCheck
);
3735 if (!(item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
3737 if (!hNewCheck
&& !hNewUnCheck
)
3739 item
->fState
&= ~MF_USECHECKBITMAPS
;
3741 else /* Install new bitmaps */
3743 item
->hCheckBit
= hNewCheck
;
3744 item
->hUnCheckBit
= hNewUnCheck
;
3745 item
->fState
|= MF_USECHECKBITMAPS
;
3751 /**********************************************************************
3752 * CreateMenu16 (USER.151)
3754 HMENU16 WINAPI
CreateMenu16(void)
3756 return CreateMenu();
3760 /**********************************************************************
3761 * CreateMenu (USER32.81)
3763 HMENU WINAPI
CreateMenu(void)
3767 if (!(hMenu
= USER_HEAP_ALLOC( sizeof(POPUPMENU
) ))) return 0;
3768 menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
);
3770 ZeroMemory(menu
, sizeof(POPUPMENU
));
3771 menu
->wMagic
= MENU_MAGIC
;
3772 menu
->FocusedItem
= NO_SELECTED_ITEM
;
3773 menu
->bTimeToHide
= FALSE
;
3775 TRACE("return %04x\n", hMenu
);
3781 /**********************************************************************
3782 * DestroyMenu16 (USER.152)
3784 BOOL16 WINAPI
DestroyMenu16( HMENU16 hMenu
)
3786 return DestroyMenu( hMenu
);
3790 /**********************************************************************
3791 * DestroyMenu32 (USER32.134)
3793 BOOL WINAPI
DestroyMenu( HMENU hMenu
)
3795 TRACE("(%04x)\n", hMenu
);
3797 /* Silently ignore attempts to destroy default system popup */
3799 if (hMenu
&& hMenu
!= MENU_DefSysPopup
)
3801 LPPOPUPMENU lppop
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hMenu
);
3802 WND
*pTPWnd
= MENU_GetTopPopupWnd();
3804 if( pTPWnd
&& (hMenu
== *(HMENU
*)pTPWnd
->wExtra
) )
3805 *(UINT
*)pTPWnd
->wExtra
= 0;
3807 if (!IS_A_MENU(lppop
)) lppop
= NULL
;
3810 lppop
->wMagic
= 0; /* Mark it as destroyed */
3812 if ((lppop
->wFlags
& MF_POPUP
) && lppop
->hWnd
&&
3813 (!pTPWnd
|| (lppop
->hWnd
!= pTPWnd
->hwndSelf
)))
3814 DestroyWindow( lppop
->hWnd
);
3816 if (lppop
->items
) /* recursively destroy submenus */
3819 MENUITEM
*item
= lppop
->items
;
3820 for (i
= lppop
->nItems
; i
> 0; i
--, item
++)
3822 if (item
->fType
& MF_POPUP
) DestroyMenu(item
->hSubMenu
);
3823 MENU_FreeItemData( item
);
3825 HeapFree( SystemHeap
, 0, lppop
->items
);
3827 USER_HEAP_FREE( hMenu
);
3828 MENU_ReleaseTopPopupWnd();
3832 MENU_ReleaseTopPopupWnd();
3836 return (hMenu
!= MENU_DefSysPopup
);
3840 /**********************************************************************
3841 * GetSystemMenu16 (USER.156)
3843 HMENU16 WINAPI
GetSystemMenu16( HWND16 hWnd
, BOOL16 bRevert
)
3845 return GetSystemMenu( hWnd
, bRevert
);
3849 /**********************************************************************
3850 * GetSystemMenu32 (USER32.291)
3852 HMENU WINAPI
GetSystemMenu( HWND hWnd
, BOOL bRevert
)
3854 WND
*wndPtr
= WIN_FindWndPtr( hWnd
);
3859 if( wndPtr
->hSysMenu
)
3863 DestroyMenu(wndPtr
->hSysMenu
);
3864 wndPtr
->hSysMenu
= 0;
3868 POPUPMENU
*menu
= MENU_GetMenu( wndPtr
->hSysMenu
);
3871 if( menu
->nItems
> 0 && menu
->items
[0].hSubMenu
== MENU_DefSysPopup
)
3872 menu
->items
[0].hSubMenu
= MENU_CopySysPopup();
3876 WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
3877 wndPtr
->hSysMenu
, hWnd
);
3878 wndPtr
->hSysMenu
= 0;
3883 if(!wndPtr
->hSysMenu
&& (wndPtr
->dwStyle
& WS_SYSMENU
) )
3884 wndPtr
->hSysMenu
= MENU_GetSysMenu( hWnd
, (HMENU
)(-1) );
3886 if( wndPtr
->hSysMenu
)
3889 retvalue
= GetSubMenu16(wndPtr
->hSysMenu
, 0);
3891 /* Store the dummy sysmenu handle to facilitate the refresh */
3892 /* of the close button if the SC_CLOSE item change */
3893 menu
= MENU_GetMenu(retvalue
);
3895 menu
->hSysMenuOwner
= wndPtr
->hSysMenu
;
3897 WIN_ReleaseWndPtr(wndPtr
);
3903 /*******************************************************************
3904 * SetSystemMenu16 (USER.280)
3906 BOOL16 WINAPI
SetSystemMenu16( HWND16 hwnd
, HMENU16 hMenu
)
3908 return SetSystemMenu( hwnd
, hMenu
);
3912 /*******************************************************************
3913 * SetSystemMenu32 (USER32.508)
3915 BOOL WINAPI
SetSystemMenu( HWND hwnd
, HMENU hMenu
)
3917 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3921 if (wndPtr
->hSysMenu
) DestroyMenu( wndPtr
->hSysMenu
);
3922 wndPtr
->hSysMenu
= MENU_GetSysMenu( hwnd
, hMenu
);
3923 WIN_ReleaseWndPtr(wndPtr
);
3930 /**********************************************************************
3931 * GetMenu16 (USER.157)
3933 HMENU16 WINAPI
GetMenu16( HWND16 hWnd
)
3935 return (HMENU16
)GetMenu(hWnd
);
3939 /**********************************************************************
3940 * GetMenu32 (USER32.257)
3942 HMENU WINAPI
GetMenu( HWND hWnd
)
3945 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
3946 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
))
3948 retvalue
= (HMENU
)wndPtr
->wIDmenu
;
3953 WIN_ReleaseWndPtr(wndPtr
);
3958 /**********************************************************************
3959 * SetMenu16 (USER.158)
3961 BOOL16 WINAPI
SetMenu16( HWND16 hWnd
, HMENU16 hMenu
)
3963 return SetMenu( hWnd
, hMenu
);
3967 /**********************************************************************
3968 * SetMenu32 (USER32.487)
3970 BOOL WINAPI
SetMenu( HWND hWnd
, HMENU hMenu
)
3972 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
3974 TRACE("(%04x, %04x);\n", hWnd
, hMenu
);
3976 if (hMenu
&& !IsMenu(hMenu
))
3978 WARN("hMenu is not a menu handle\n");
3983 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
))
3985 if (GetCapture() == hWnd
) ReleaseCapture();
3987 wndPtr
->wIDmenu
= (UINT
)hMenu
;
3992 if (!(lpmenu
= MENU_GetMenu(hMenu
)))
3994 WIN_ReleaseWndPtr(wndPtr
);
3997 lpmenu
->hWnd
= hWnd
;
3998 lpmenu
->wFlags
&= ~MF_POPUP
; /* Can't be a popup */
3999 lpmenu
->Height
= 0; /* Make sure we recalculate the size */
4001 if (IsWindowVisible(hWnd
))
4002 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4003 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4004 WIN_ReleaseWndPtr(wndPtr
);
4007 WIN_ReleaseWndPtr(wndPtr
);
4013 /**********************************************************************
4014 * GetSubMenu16 (USER.159)
4016 HMENU16 WINAPI
GetSubMenu16( HMENU16 hMenu
, INT16 nPos
)
4018 return GetSubMenu( hMenu
, nPos
);
4022 /**********************************************************************
4023 * GetSubMenu32 (USER32.288)
4025 HMENU WINAPI
GetSubMenu( HMENU hMenu
, INT nPos
)
4029 if (!(lpmi
= MENU_FindItem(&hMenu
,&nPos
,MF_BYPOSITION
))) return 0;
4030 if (!(lpmi
->fType
& MF_POPUP
)) return 0;
4031 return lpmi
->hSubMenu
;
4035 /**********************************************************************
4036 * DrawMenuBar16 (USER.160)
4038 void WINAPI
DrawMenuBar16( HWND16 hWnd
)
4040 DrawMenuBar( hWnd
);
4044 /**********************************************************************
4045 * DrawMenuBar (USER32.161)
4047 BOOL WINAPI
DrawMenuBar( HWND hWnd
)
4050 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
4051 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
) && wndPtr
->wIDmenu
)
4053 lppop
= MENU_GetMenu((HMENU16
)wndPtr
->wIDmenu
);
4056 WIN_ReleaseWndPtr(wndPtr
);
4060 lppop
->Height
= 0; /* Make sure we call MENU_MenuBarCalcSize */
4061 lppop
->hwndOwner
= hWnd
;
4062 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4063 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4064 WIN_ReleaseWndPtr(wndPtr
);
4067 WIN_ReleaseWndPtr(wndPtr
);
4072 /***********************************************************************
4073 * EndMenu (USER.187) (USER32.175)
4075 void WINAPI
EndMenu(void)
4078 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
4085 /***********************************************************************
4086 * LookupMenuHandle (USER.217)
4088 HMENU16 WINAPI
LookupMenuHandle16( HMENU16 hmenu
, INT16 id
)
4090 HMENU hmenu32
= hmenu
;
4092 if (!MENU_FindItem( &hmenu32
, &id32
, MF_BYCOMMAND
)) return 0;
4093 else return hmenu32
;
4097 /**********************************************************************
4098 * LoadMenu16 (USER.150)
4100 HMENU16 WINAPI
LoadMenu16( HINSTANCE16 instance
, SEGPTR name
)
4108 char *str
= (char *)PTR_SEG_TO_LIN( name
);
4109 TRACE("(%04x,'%s')\n", instance
, str
);
4110 if (str
[0] == '#') name
= (SEGPTR
)atoi( str
+ 1 );
4113 TRACE("(%04x,%04x)\n",instance
,LOWORD(name
));
4115 if (!name
) return 0;
4117 /* check for Win32 module */
4118 if (HIWORD(instance
))
4119 return LoadMenuA(instance
,PTR_SEG_TO_LIN(name
));
4120 instance
= GetExePtr( instance
);
4122 if (!(hRsrc
= FindResource16( instance
, name
, RT_MENU16
))) return 0;
4123 if (!(handle
= LoadResource16( instance
, hRsrc
))) return 0;
4124 hMenu
= LoadMenuIndirect16(LockResource16(handle
));
4125 FreeResource16( handle
);
4130 /*****************************************************************
4131 * LoadMenu32A (USER32.370)
4133 HMENU WINAPI
LoadMenuA( HINSTANCE instance
, LPCSTR name
)
4135 HRSRC hrsrc
= FindResourceA( instance
, name
, RT_MENUA
);
4136 if (!hrsrc
) return 0;
4137 return LoadMenuIndirectA( (LPCVOID
)LoadResource( instance
, hrsrc
));
4141 /*****************************************************************
4142 * LoadMenu32W (USER32.373)
4144 HMENU WINAPI
LoadMenuW( HINSTANCE instance
, LPCWSTR name
)
4146 HRSRC hrsrc
= FindResourceW( instance
, name
, RT_MENUW
);
4147 if (!hrsrc
) return 0;
4148 return LoadMenuIndirectW( (LPCVOID
)LoadResource( instance
, hrsrc
));
4152 /**********************************************************************
4153 * LoadMenuIndirect16 (USER.220)
4155 HMENU16 WINAPI
LoadMenuIndirect16( LPCVOID
template )
4158 WORD version
, offset
;
4159 LPCSTR p
= (LPCSTR
)template;
4161 TRACE("(%p)\n", template );
4162 version
= GET_WORD(p
);
4166 WARN("version must be 0 for Win16\n" );
4169 offset
= GET_WORD(p
);
4170 p
+= sizeof(WORD
) + offset
;
4171 if (!(hMenu
= CreateMenu())) return 0;
4172 if (!MENU_ParseResource( p
, hMenu
, FALSE
))
4174 DestroyMenu( hMenu
);
4181 /**********************************************************************
4182 * LoadMenuIndirect32A (USER32.371)
4184 HMENU WINAPI
LoadMenuIndirectA( LPCVOID
template )
4187 WORD version
, offset
;
4188 LPCSTR p
= (LPCSTR
)template;
4190 TRACE("%p\n", template );
4191 version
= GET_WORD(p
);
4196 offset
= GET_WORD(p
);
4197 p
+= sizeof(WORD
) + offset
;
4198 if (!(hMenu
= CreateMenu())) return 0;
4199 if (!MENU_ParseResource( p
, hMenu
, TRUE
))
4201 DestroyMenu( hMenu
);
4206 offset
= GET_WORD(p
);
4207 p
+= sizeof(WORD
) + offset
;
4208 if (!(hMenu
= CreateMenu())) return 0;
4209 if (!MENUEX_ParseResource( p
, hMenu
))
4211 DestroyMenu( hMenu
);
4216 ERR("version %d not supported.\n", version
);
4222 /**********************************************************************
4223 * LoadMenuIndirect32W (USER32.372)
4225 HMENU WINAPI
LoadMenuIndirectW( LPCVOID
template )
4227 /* FIXME: is there anything different between A and W? */
4228 return LoadMenuIndirectA( template );
4232 /**********************************************************************
4233 * IsMenu16 (USER.358)
4235 BOOL16 WINAPI
IsMenu16( HMENU16 hmenu
)
4237 LPPOPUPMENU menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hmenu
);
4238 return IS_A_MENU(menu
);
4242 /**********************************************************************
4243 * IsMenu32 (USER32.346)
4245 BOOL WINAPI
IsMenu(HMENU hmenu
)
4247 LPPOPUPMENU menu
= (LPPOPUPMENU
) USER_HEAP_LIN_ADDR(hmenu
);
4248 return IS_A_MENU(menu
);
4251 /**********************************************************************
4252 * GetMenuItemInfo32_common
4255 static BOOL
GetMenuItemInfo_common ( HMENU hmenu
, UINT item
, BOOL bypos
,
4256 LPMENUITEMINFOA lpmii
, BOOL unicode
)
4258 MENUITEM
*menu
= MENU_FindItem (&hmenu
, &item
, bypos
? MF_BYPOSITION
: 0);
4260 debug_print_menuitem("GetMenuItemInfo32_common: ", menu
, "");
4265 if (lpmii
->fMask
& MIIM_TYPE
) {
4266 lpmii
->fType
= menu
->fType
;
4267 switch (MENU_ITEM_TYPE(menu
->fType
)) {
4269 if (menu
->text
&& lpmii
->dwTypeData
&& lpmii
->cch
) {
4271 lstrcpynAtoW((LPWSTR
) lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4272 lpmii
->cch
= lstrlenW((LPWSTR
)menu
->text
);
4274 lstrcpynA(lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4275 lpmii
->cch
= lstrlenA(menu
->text
);
4281 lpmii
->dwTypeData
= menu
->text
;
4288 if (lpmii
->fMask
& MIIM_STRING
) {
4290 lstrcpynAtoW((LPWSTR
) lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4291 lpmii
->cch
= lstrlenW((LPWSTR
)menu
->text
);
4293 lstrcpynA(lpmii
->dwTypeData
, menu
->text
, lpmii
->cch
);
4294 lpmii
->cch
= lstrlenA(menu
->text
);
4298 if (lpmii
->fMask
& MIIM_FTYPE
)
4299 lpmii
->fType
= menu
->fType
;
4301 if (lpmii
->fMask
& MIIM_BITMAP
)
4302 lpmii
->hbmpItem
= menu
->hbmpItem
;
4304 if (lpmii
->fMask
& MIIM_STATE
)
4305 lpmii
->fState
= menu
->fState
;
4307 if (lpmii
->fMask
& MIIM_ID
)
4308 lpmii
->wID
= menu
->wID
;
4310 if (lpmii
->fMask
& MIIM_SUBMENU
)
4311 lpmii
->hSubMenu
= menu
->hSubMenu
;
4313 if (lpmii
->fMask
& MIIM_CHECKMARKS
) {
4314 lpmii
->hbmpChecked
= menu
->hCheckBit
;
4315 lpmii
->hbmpUnchecked
= menu
->hUnCheckBit
;
4317 if (lpmii
->fMask
& MIIM_DATA
)
4318 lpmii
->dwItemData
= menu
->dwItemData
;
4323 /**********************************************************************
4324 * GetMenuItemInfoA (USER32.264)
4326 BOOL WINAPI
GetMenuItemInfoA( HMENU hmenu
, UINT item
, BOOL bypos
,
4327 LPMENUITEMINFOA lpmii
)
4329 return GetMenuItemInfo_common (hmenu
, item
, bypos
, lpmii
, FALSE
);
4332 /**********************************************************************
4333 * GetMenuItemInfoW (USER32.265)
4335 BOOL WINAPI
GetMenuItemInfoW( HMENU hmenu
, UINT item
, BOOL bypos
,
4336 LPMENUITEMINFOW lpmii
)
4338 return GetMenuItemInfo_common (hmenu
, item
, bypos
,
4339 (LPMENUITEMINFOA
)lpmii
, TRUE
);
4342 /**********************************************************************
4343 * SetMenuItemInfo32_common
4346 static BOOL
SetMenuItemInfo_common(MENUITEM
* menu
,
4347 const MENUITEMINFOA
*lpmii
,
4350 if (!menu
) return FALSE
;
4352 if (lpmii
->fMask
& MIIM_TYPE
) {
4353 /* Get rid of old string. */
4354 if ( IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4355 HeapFree(SystemHeap
, 0, menu
->text
);
4359 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4360 menu
->fType
&= ~MENU_ITEM_TYPE(menu
->fType
);
4361 menu
->fType
|= MENU_ITEM_TYPE(lpmii
->fType
);
4363 menu
->text
= lpmii
->dwTypeData
;
4365 if (IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4367 menu
->text
= HEAP_strdupWtoA(SystemHeap
, 0, (LPWSTR
) lpmii
->dwTypeData
);
4369 menu
->text
= HEAP_strdupA(SystemHeap
, 0, lpmii
->dwTypeData
);
4373 if (lpmii
->fMask
& MIIM_FTYPE
) {
4374 /* free the string when the type is changing */
4375 if ( (!IS_STRING_ITEM(lpmii
->fType
)) && IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4376 HeapFree(SystemHeap
, 0, menu
->text
);
4379 menu
->fType
&= ~MENU_ITEM_TYPE(menu
->fType
);
4380 menu
->fType
|= MENU_ITEM_TYPE(lpmii
->fType
);
4383 if (lpmii
->fMask
& MIIM_STRING
) {
4384 /* free the string when used */
4385 if ( IS_STRING_ITEM(menu
->fType
) && menu
->text
) {
4386 HeapFree(SystemHeap
, 0, menu
->text
);
4388 menu
->text
= HEAP_strdupWtoA(SystemHeap
, 0, (LPWSTR
) lpmii
->dwTypeData
);
4390 menu
->text
= HEAP_strdupA(SystemHeap
, 0, lpmii
->dwTypeData
);
4394 if (lpmii
->fMask
& MIIM_STATE
)
4396 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
4397 menu
->fState
= lpmii
->fState
;
4400 if (lpmii
->fMask
& MIIM_ID
)
4401 menu
->wID
= lpmii
->wID
;
4403 if (lpmii
->fMask
& MIIM_SUBMENU
) {
4404 menu
->hSubMenu
= lpmii
->hSubMenu
;
4405 if (menu
->hSubMenu
) {
4406 POPUPMENU
*subMenu
= MENU_GetMenu((UINT16
)menu
->hSubMenu
);
4408 subMenu
->wFlags
|= MF_POPUP
;
4409 menu
->fType
|= MF_POPUP
;
4412 /* FIXME: Return an error ? */
4413 menu
->fType
&= ~MF_POPUP
;
4416 menu
->fType
&= ~MF_POPUP
;
4419 if (lpmii
->fMask
& MIIM_CHECKMARKS
)
4421 menu
->hCheckBit
= lpmii
->hbmpChecked
;
4422 menu
->hUnCheckBit
= lpmii
->hbmpUnchecked
;
4424 if (lpmii
->fMask
& MIIM_DATA
)
4425 menu
->dwItemData
= lpmii
->dwItemData
;
4427 debug_print_menuitem("SetMenuItemInfo32_common: ", menu
, "");
4431 /**********************************************************************
4432 * SetMenuItemInfo32A (USER32.491)
4434 BOOL WINAPI
SetMenuItemInfoA(HMENU hmenu
, UINT item
, BOOL bypos
,
4435 const MENUITEMINFOA
*lpmii
)
4437 return SetMenuItemInfo_common(MENU_FindItem(&hmenu
, &item
, bypos
? MF_BYPOSITION
: 0),
4441 /**********************************************************************
4442 * SetMenuItemInfo32W (USER32.492)
4444 BOOL WINAPI
SetMenuItemInfoW(HMENU hmenu
, UINT item
, BOOL bypos
,
4445 const MENUITEMINFOW
*lpmii
)
4447 return SetMenuItemInfo_common(MENU_FindItem(&hmenu
, &item
, bypos
? MF_BYPOSITION
: 0),
4448 (const MENUITEMINFOA
*)lpmii
, TRUE
);
4451 /**********************************************************************
4452 * SetMenuDefaultItem (USER32.489)
4455 BOOL WINAPI
SetMenuDefaultItem(HMENU hmenu
, UINT uItem
, UINT bypos
)
4461 TRACE("(0x%x,%d,%d)\n", hmenu
, uItem
, bypos
);
4463 if (!(menu
= MENU_GetMenu(hmenu
))) return FALSE
;
4465 /* reset all default-item flags */
4467 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
4469 item
->fState
&= ~MFS_DEFAULT
;
4472 /* no default item */
4481 if ( uItem
>= menu
->nItems
) return FALSE
;
4482 item
[uItem
].fState
|= MFS_DEFAULT
;
4487 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
4489 if (item
->wID
== uItem
)
4491 item
->fState
|= MFS_DEFAULT
;
4500 /**********************************************************************
4501 * GetMenuDefaultItem (USER32.260)
4503 UINT WINAPI
GetMenuDefaultItem(HMENU hmenu
, UINT bypos
, UINT flags
)
4509 TRACE("(0x%x,%d,%d)\n", hmenu
, bypos
, flags
);
4511 if (!(menu
= MENU_GetMenu(hmenu
))) return -1;
4513 /* find default item */
4517 if (! item
) return -1;
4519 while ( !( item
->fState
& MFS_DEFAULT
) )
4522 if (i
>= menu
->nItems
) return -1;
4525 /* default: don't return disabled items */
4526 if ( (!(GMDI_USEDISABLED
& flags
)) && (item
->fState
& MFS_DISABLED
)) return -1;
4528 /* search rekursiv when needed */
4529 if ( (item
->fType
& MF_POPUP
) && (flags
& GMDI_GOINTOPOPUPS
) )
4532 ret
= GetMenuDefaultItem( item
->hSubMenu
, bypos
, flags
);
4533 if ( -1 != ret
) return ret
;
4535 /* when item not found in submenu, return the popup item */
4537 return ( bypos
) ? i
: item
->wID
;
4541 /*******************************************************************
4542 * InsertMenuItem16 (USER.441)
4546 BOOL16 WINAPI
InsertMenuItem16( HMENU16 hmenu
, UINT16 pos
, BOOL16 byposition
,
4547 const MENUITEMINFO16
*mii
)
4551 miia
.cbSize
= sizeof(miia
);
4552 miia
.fMask
= mii
->fMask
;
4553 miia
.dwTypeData
= mii
->dwTypeData
;
4554 miia
.fType
= mii
->fType
;
4555 miia
.fState
= mii
->fState
;
4556 miia
.wID
= mii
->wID
;
4557 miia
.hSubMenu
= mii
->hSubMenu
;
4558 miia
.hbmpChecked
= mii
->hbmpChecked
;
4559 miia
.hbmpUnchecked
= mii
->hbmpUnchecked
;
4560 miia
.dwItemData
= mii
->dwItemData
;
4561 miia
.cch
= mii
->cch
;
4562 if (IS_STRING_ITEM(miia
.fType
))
4563 miia
.dwTypeData
= PTR_SEG_TO_LIN(miia
.dwTypeData
);
4564 return InsertMenuItemA( hmenu
, pos
, byposition
, &miia
);
4568 /**********************************************************************
4569 * InsertMenuItem32A (USER32.323)
4571 BOOL WINAPI
InsertMenuItemA(HMENU hMenu
, UINT uItem
, BOOL bypos
,
4572 const MENUITEMINFOA
*lpmii
)
4574 MENUITEM
*item
= MENU_InsertItem(hMenu
, uItem
, bypos
? MF_BYPOSITION
: 0 );
4575 return SetMenuItemInfo_common(item
, lpmii
, FALSE
);
4579 /**********************************************************************
4580 * InsertMenuItem32W (USER32.324)
4582 BOOL WINAPI
InsertMenuItemW(HMENU hMenu
, UINT uItem
, BOOL bypos
,
4583 const MENUITEMINFOW
*lpmii
)
4585 MENUITEM
*item
= MENU_InsertItem(hMenu
, uItem
, bypos
? MF_BYPOSITION
: 0 );
4586 return SetMenuItemInfo_common(item
, (const MENUITEMINFOA
*)lpmii
, TRUE
);
4589 /**********************************************************************
4590 * CheckMenuRadioItem32 (USER32.47)
4593 BOOL WINAPI
CheckMenuRadioItem(HMENU hMenu
,
4594 UINT first
, UINT last
, UINT check
,
4597 MENUITEM
*mifirst
, *milast
, *micheck
;
4598 HMENU mfirst
= hMenu
, mlast
= hMenu
, mcheck
= hMenu
;
4600 TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
4601 hMenu
, first
, last
, check
, bypos
);
4603 mifirst
= MENU_FindItem (&mfirst
, &first
, bypos
);
4604 milast
= MENU_FindItem (&mlast
, &last
, bypos
);
4605 micheck
= MENU_FindItem (&mcheck
, &check
, bypos
);
4607 if (mifirst
== NULL
|| milast
== NULL
|| micheck
== NULL
||
4608 mifirst
> milast
|| mfirst
!= mlast
|| mfirst
!= mcheck
||
4609 micheck
> milast
|| micheck
< mifirst
)
4612 while (mifirst
<= milast
)
4614 if (mifirst
== micheck
)
4616 mifirst
->fType
|= MFT_RADIOCHECK
;
4617 mifirst
->fState
|= MFS_CHECKED
;
4619 mifirst
->fType
&= ~MFT_RADIOCHECK
;
4620 mifirst
->fState
&= ~MFS_CHECKED
;
4628 /**********************************************************************
4629 * CheckMenuRadioItem16 (not a Windows API)
4632 BOOL16 WINAPI
CheckMenuRadioItem16(HMENU16 hMenu
,
4633 UINT16 first
, UINT16 last
, UINT16 check
,
4636 return CheckMenuRadioItem (hMenu
, first
, last
, check
, bypos
);
4639 /**********************************************************************
4640 * GetMenuItemRect32 (USER32.266)
4642 * ATTENTION: Here, the returned values in rect are the screen
4643 * coordinates of the item just like if the menu was
4644 * always on the upper left side of the application.
4647 BOOL WINAPI
GetMenuItemRect (HWND hwnd
, HMENU hMenu
, UINT uItem
,
4650 POPUPMENU
*itemMenu
;
4654 TRACE("(0x%x,0x%x,%d,%p)\n", hwnd
, hMenu
, uItem
, rect
);
4656 item
= MENU_FindItem (&hMenu
, &uItem
, MF_BYPOSITION
);
4657 referenceHwnd
= hwnd
;
4661 itemMenu
= MENU_GetMenu(hMenu
);
4662 if (itemMenu
== NULL
)
4665 if(itemMenu
->hWnd
== 0)
4667 referenceHwnd
= itemMenu
->hWnd
;
4670 if ((rect
== NULL
) || (item
== NULL
))
4675 MapWindowPoints(referenceHwnd
, 0, (LPPOINT
)rect
, 2);
4680 /**********************************************************************
4681 * GetMenuItemRect16 (USER.665)
4684 BOOL16 WINAPI
GetMenuItemRect16 (HWND16 hwnd
, HMENU16 hMenu
, UINT16 uItem
,
4690 if (!rect
) return FALSE
;
4691 res
= GetMenuItemRect (hwnd
, hMenu
, uItem
, &r32
);
4692 CONV_RECT32TO16 (&r32
, rect
);
4696 /**********************************************************************
4700 * MIM_APPLYTOSUBMENUS
4701 * actually use the items to draw the menu
4703 BOOL WINAPI
SetMenuInfo (HMENU hMenu
, LPCMENUINFO lpmi
)
4707 TRACE("(0x%04x %p)\n", hMenu
, lpmi
);
4709 if (lpmi
&& (lpmi
->cbSize
==sizeof(MENUINFO
)) && (menu
= MENU_GetMenu(hMenu
)))
4712 if (lpmi
->fMask
& MIM_BACKGROUND
)
4713 menu
->hbrBack
= lpmi
->hbrBack
;
4715 if (lpmi
->fMask
& MIM_HELPID
)
4716 menu
->dwContextHelpID
= lpmi
->dwContextHelpID
;
4718 if (lpmi
->fMask
& MIM_MAXHEIGHT
)
4719 menu
->cyMax
= lpmi
->cyMax
;
4721 if (lpmi
->fMask
& MIM_MENUDATA
)
4722 menu
->dwMenuData
= lpmi
->dwMenuData
;
4724 if (lpmi
->fMask
& MIM_STYLE
)
4725 menu
->dwStyle
= lpmi
->dwStyle
;
4732 /**********************************************************************
4739 BOOL WINAPI
GetMenuInfo (HMENU hMenu
, LPMENUINFO lpmi
)
4742 TRACE("(0x%04x %p)\n", hMenu
, lpmi
);
4744 if (lpmi
&& (menu
= MENU_GetMenu(hMenu
)))
4747 if (lpmi
->fMask
& MIM_BACKGROUND
)
4748 lpmi
->hbrBack
= menu
->hbrBack
;
4750 if (lpmi
->fMask
& MIM_HELPID
)
4751 lpmi
->dwContextHelpID
= menu
->dwContextHelpID
;
4753 if (lpmi
->fMask
& MIM_MAXHEIGHT
)
4754 lpmi
->cyMax
= menu
->cyMax
;
4756 if (lpmi
->fMask
& MIM_MENUDATA
)
4757 lpmi
->dwMenuData
= menu
->dwMenuData
;
4759 if (lpmi
->fMask
& MIM_STYLE
)
4760 lpmi
->dwStyle
= menu
->dwStyle
;
4767 /**********************************************************************
4768 * SetMenuContextHelpId16 (USER.384)
4770 BOOL16 WINAPI
SetMenuContextHelpId16( HMENU16 hMenu
, DWORD dwContextHelpID
)
4772 return SetMenuContextHelpId( hMenu
, dwContextHelpID
);
4776 /**********************************************************************
4777 * SetMenuContextHelpId (USER32.488)
4779 BOOL WINAPI
SetMenuContextHelpId( HMENU hMenu
, DWORD dwContextHelpID
)
4783 TRACE("(0x%04x 0x%08lx)\n", hMenu
, dwContextHelpID
);
4785 if ((menu
= MENU_GetMenu(hMenu
)))
4787 menu
->dwContextHelpID
= dwContextHelpID
;
4793 /**********************************************************************
4794 * GetMenuContextHelpId16 (USER.385)
4796 DWORD WINAPI
GetMenuContextHelpId16( HMENU16 hMenu
)
4798 return GetMenuContextHelpId( hMenu
);
4801 /**********************************************************************
4802 * GetMenuContextHelpId (USER32.488)
4804 DWORD WINAPI
GetMenuContextHelpId( HMENU hMenu
)
4808 TRACE("(0x%04x)\n", hMenu
);
4810 if ((menu
= MENU_GetMenu(hMenu
)))
4812 return menu
->dwContextHelpID
;
4817 /**********************************************************************
4818 * MenuItemFromPoint (USER32.387)
4820 UINT WINAPI
MenuItemFromPoint(HWND hWnd
, HMENU hMenu
, POINT ptScreen
)
4822 FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
4823 hWnd
, hMenu
, ptScreen
.x
, ptScreen
.y
);