blob: 114964bd58a9112b4acaea176b66e4bf28135cbc [file] [log] [blame]
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001/*
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00002 * Menu functions
3 *
4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994 Alexandre Julliard
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00006 * Copyright 1997 Morten Welinder
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00007 */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00008
9/*
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.
13 */
Alexandre Julliard401710d1993-09-04 10:09:32 +000014
Alexandre Julliard7ff1c411997-05-25 13:58:18 +000015#include <assert.h>
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000016#include <ctype.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000017#include <stdlib.h>
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000018#include <string.h>
Francois Boisvert85dd9fc1999-02-17 12:50:11 +000019
Marcus Meissnerd5e7c791998-12-09 11:06:00 +000020#include "win.h"
Francois Boisvert85dd9fc1999-02-17 12:50:11 +000021#include "wine/winbase16.h"
Michael Veksler3fbb8dc1999-02-21 18:23:26 +000022#include "wine/winuser16.h"
Alexandre Julliard2ace16a1996-04-28 15:09:19 +000023#include "task.h"
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000024#include "heap.h"
Francois Boisvert197a8e11999-02-13 09:10:17 +000025#include "menu.h"
Alexandre Julliardc6c09441997-01-12 18:32:19 +000026#include "nonclient.h"
Alexandre Julliard1f579291994-05-25 16:25:21 +000027#include "user.h"
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000028#include "message.h"
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +000029#include "resource.h"
Alexandre Julliardd37eb361997-07-20 16:23:21 +000030#include "tweak.h"
Marcus Meissnerd5e7c791998-12-09 11:06:00 +000031
Alexandre Julliard9fe7a251999-05-14 08:17:14 +000032#include "debugtools.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000033
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000034DEFAULT_DEBUG_CHANNEL(menu)
35
Alexandre Julliardd37eb361997-07-20 16:23:21 +000036
Alexandre Julliard7ff1c411997-05-25 13:58:18 +000037/* internal popup menu window messages */
38
39#define MM_SETMENUHANDLE (WM_USER + 0)
40#define MM_GETMENUHANDLE (WM_USER + 1)
41
Alexandre Julliard2d93d001996-05-21 15:01:41 +000042/* Menu item structure */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000043typedef struct {
44 /* ----------- MENUITEMINFO Stuff ----------- */
Juergen Schmied78513941999-04-18 14:40:32 +000045 UINT fType; /* Item type. */
Alexandre Julliarda3960291999-02-26 11:11:13 +000046 UINT fState; /* Item state. */
47 UINT wID; /* Item id. */
48 HMENU hSubMenu; /* Pop-up menu. */
Juergen Schmied78513941999-04-18 14:40:32 +000049 HBITMAP hCheckBit; /* Bitmap when checked. */
Alexandre Julliarda3960291999-02-26 11:11:13 +000050 HBITMAP hUnCheckBit; /* Bitmap when unchecked. */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000051 LPSTR text; /* Item text or bitmap handle. */
52 DWORD dwItemData; /* Application defined. */
Juergen Schmied78513941999-04-18 14:40:32 +000053 DWORD dwTypeData; /* depends on fMask */
54 HBITMAP hbmpItem; /* bitmap in win98 style menus */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000055 /* ----------- Wine stuff ----------- */
Juergen Schmied78513941999-04-18 14:40:32 +000056 RECT rect; /* Item area (relative to menu window) */
57 UINT xTab; /* X position of text after Tab */
Alexandre Julliard2d93d001996-05-21 15:01:41 +000058} MENUITEM;
59
60/* Popup menu structure */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000061typedef struct {
Alexandre Julliard2d93d001996-05-21 15:01:41 +000062 WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
63 WORD wMagic; /* Magic number */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000064 HQUEUE16 hTaskQ; /* Task queue for this menu */
Alexandre Julliard2d93d001996-05-21 15:01:41 +000065 WORD Width; /* Width of the whole menu */
66 WORD Height; /* Height of the whole menu */
67 WORD nItems; /* Number of items in the menu */
Juergen Schmied78513941999-04-18 14:40:32 +000068 HWND hWnd; /* Window containing the menu */
69 MENUITEM *items; /* Array of menu items */
70 UINT FocusedItem; /* Currently focused item */
Juergen Schmied466a6521999-05-02 11:21:08 +000071 HWND hwndOwner; /* window receiving the messages for ownerdraw */
Pascal Lessard2eb0a301999-09-03 16:38:52 +000072 BOOL bTimeToHide; /* Request hiding when receiving a second click in the top-level menu item */
Juergen Schmied78513941999-04-18 14:40:32 +000073 /* ------------ 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 */
Pascal Lessardd814bb61999-07-31 13:02:02 +000079 HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */
Alexandre Julliard2d93d001996-05-21 15:01:41 +000080} POPUPMENU, *LPPOPUPMENU;
81
Alexandre Julliard7ff1c411997-05-25 13:58:18 +000082/* internal flags for menu tracking */
83
84#define TF_ENDMENU 0x0001
85#define TF_SUSPENDPOPUP 0x0002
86#define TF_SKIPREMOVE 0x0004
87
88typedef struct
89{
Alexandre Julliarda3960291999-02-26 11:11:13 +000090 UINT trackFlags;
91 HMENU hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
92 HMENU hTopMenu; /* initial menu */
93 HWND hOwnerWnd; /* where notifications are sent */
94 POINT pt;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +000095} MTRACKER;
96
Alexandre Julliard2d93d001996-05-21 15:01:41 +000097#define MENU_MAGIC 0x554d /* 'MU' */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000098#define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
Alexandre Julliard2d93d001996-05-21 15:01:41 +000099
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000100#define ITEM_PREV -1
101#define ITEM_NEXT 1
102
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000103 /* 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 */
Francois Boisvert85dd9fc1999-02-17 12:50:11 +0000107#define TPM_POPUPMENU 0x20000000 /* menu is a popup menu */
Alexandre Julliardf7207251994-07-23 07:57:48 +0000108
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000109 /* popup menu shade thickness */
110#define POPUP_XSHADE 4
111#define POPUP_YSHADE 4
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000112
Alexandre Julliardf7207251994-07-23 07:57:48 +0000113 /* Space between 2 menu bar items */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000114#define MENU_BAR_ITEMS_SPACE 12
Alexandre Julliardf7207251994-07-23 07:57:48 +0000115
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000116 /* Minimum width of a tab character */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000117#define MENU_TAB_SPACE 8
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000118
Alexandre Julliardf7207251994-07-23 07:57:48 +0000119 /* Height of a separator item */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000120#define SEPARATOR_HEIGHT 5
Alexandre Julliardf7207251994-07-23 07:57:48 +0000121
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000122 /* (other menu->FocusedItem values give the position of the focused item) */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000123#define NO_SELECTED_ITEM 0xffff
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000124
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000125#define MENU_ITEM_TYPE(flags) \
126 ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
127
128#define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
Juergen Schmied78513941999-04-18 14:40:32 +0000129#define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000130
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000131#define IS_SYSTEM_MENU(menu) \
132 (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
Juergen Schmied78513941999-04-18 14:40:32 +0000133
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000134#define IS_SYSTEM_POPUP(menu) \
135 ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
136
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000137#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)
142
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000143 /* Dimension of the menu bitmaps */
144static WORD check_bitmap_width = 0, check_bitmap_height = 0;
145static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000146
Alexandre Julliarda3960291999-02-26 11:11:13 +0000147static HBITMAP hStdRadioCheck = 0;
148static HBITMAP hStdCheck = 0;
149static HBITMAP hStdMnArrow = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000150
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000151/* Minimze/restore/close buttons to be inserted in menubar */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000152static HBITMAP hBmpMinimize = 0;
153static HBITMAP hBmpMinimizeD = 0;
154static HBITMAP hBmpMaximize = 0;
155static HBITMAP hBmpMaximizeD = 0;
156static HBITMAP hBmpClose = 0;
157static HBITMAP hBmpCloseD = 0;
Francois Boisvert308c6af1999-02-18 10:37:17 +0000158
Francois Boisvert8b391741999-02-09 14:09:55 +0000159
Juergen Schmied78513941999-04-18 14:40:32 +0000160static HBRUSH hShadeBrush = 0;
161static HFONT hMenuFont = 0;
Juergen Schmied466a6521999-05-02 11:21:08 +0000162static HFONT hMenuFontBold = 0;
Juergen Schmied78513941999-04-18 14:40:32 +0000163
Alexandre Julliarda3960291999-02-26 11:11:13 +0000164static HMENU MENU_DefSysPopup = 0; /* Default system menu popup */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000165
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000166/* Use global popup window because there's no way 2 menus can
167 * be tracked at the same time. */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000168
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000169static WND* pTopPopupWnd = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000170static UINT uSubPWndLevel = 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000171
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000172 /* Flag set by EndMenu() to force an exit from menu tracking */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000173static BOOL fEndMenu = FALSE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000174
175
176/***********************************************************************
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000177 * debug_print_menuitem
178 *
179 * Print a menuitem in readable form.
180 */
181
Alexandre Julliard03468f71998-02-15 19:40:49 +0000182#define debug_print_menuitem(pre, mp, post) \
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000183 if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000184
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000185#define MENUOUT(text) \
Alexandre Julliard15de6151999-08-04 12:22:42 +0000186 DPRINTF("%s%s", (count++ ? "," : ""), (text))
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000187
188#define MENUFLAG(bit,text) \
189 do { \
190 if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
191 } while (0)
192
Alexandre Julliard03468f71998-02-15 19:40:49 +0000193static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
194 const char *postfix)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000195{
Alexandre Julliard15de6151999-08-04 12:22:42 +0000196 TRACE("%s ", prefix);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000197 if (mp) {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000198 UINT flags = mp->fType;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000199 int typ = MENU_ITEM_TYPE(flags);
Alexandre Julliard15de6151999-08-04 12:22:42 +0000200 DPRINTF( "{ ID=0x%x", mp->wID);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000201 if (flags & MF_POPUP)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000202 DPRINTF( ", Sub=0x%x", mp->hSubMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000203 if (flags) {
204 int count = 0;
Alexandre Julliard15de6151999-08-04 12:22:42 +0000205 DPRINTF( ", Typ=");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000206 if (typ == MFT_STRING)
207 /* Nothing */ ;
208 else if (typ == MFT_SEPARATOR)
209 MENUOUT("sep");
210 else if (typ == MFT_OWNERDRAW)
211 MENUOUT("own");
212 else if (typ == MFT_BITMAP)
213 MENUOUT("bit");
214 else
215 MENUOUT("???");
216 flags -= typ;
217
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");
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000224 MENUFLAG(MFT_RIGHTJUSTIFY, "right"); /* same as MF_HELP */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000225
226 if (flags)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000227 DPRINTF( "+0x%x", flags);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000228 }
229 flags = mp->fState;
230 if (flags) {
231 int count = 0;
Alexandre Julliard15de6151999-08-04 12:22:42 +0000232 DPRINTF( ", State=");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000233 MENUFLAG(MFS_GRAYED, "grey");
Juergen Schmied466a6521999-05-02 11:21:08 +0000234 MENUFLAG(MFS_DEFAULT, "default");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000235 MENUFLAG(MFS_DISABLED, "dis");
236 MENUFLAG(MFS_CHECKED, "check");
237 MENUFLAG(MFS_HILITE, "hi");
238 MENUFLAG(MF_USECHECKBITMAPS, "usebit");
239 MENUFLAG(MF_MOUSESELECT, "mouse");
240 if (flags)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000241 DPRINTF( "+0x%x", flags);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000242 }
243 if (mp->hCheckBit)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000244 DPRINTF( ", Chk=0x%x", mp->hCheckBit);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000245 if (mp->hUnCheckBit)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000246 DPRINTF( ", Unc=0x%x", mp->hUnCheckBit);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000247
248 if (typ == MFT_STRING) {
249 if (mp->text)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000250 DPRINTF( ", Text=\"%s\"", mp->text);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000251 else
Alexandre Julliard15de6151999-08-04 12:22:42 +0000252 DPRINTF( ", Text=Null");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000253 } else if (mp->text == NULL)
254 /* Nothing */ ;
255 else
Alexandre Julliard15de6151999-08-04 12:22:42 +0000256 DPRINTF( ", Text=%p", mp->text);
Juergen Schmied7abca951999-04-11 17:02:30 +0000257 if (mp->dwItemData)
Alexandre Julliard15de6151999-08-04 12:22:42 +0000258 DPRINTF( ", ItemData=0x%08lx", mp->dwItemData);
259 DPRINTF( " }");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000260 } else {
Alexandre Julliard15de6151999-08-04 12:22:42 +0000261 DPRINTF( "NULL");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000262 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000263
Alexandre Julliard15de6151999-08-04 12:22:42 +0000264 DPRINTF(" %s\n", postfix);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000265}
266
267#undef MENUOUT
268#undef MENUFLAG
269
270/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000271 * MENU_CopySysPopup
272 *
273 * Return the default system menu.
274 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000275static HMENU MENU_CopySysPopup(void)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000276{
Bertho Stultiensd1895a71999-04-25 18:31:35 +0000277 HMENU hMenu = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000278
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000279 if( hMenu ) {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000280 POPUPMENU* menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
281 menu->wFlags |= MF_SYSMENU | MF_POPUP;
Juergen Schmied49251861999-05-13 18:42:03 +0000282 SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000283 }
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000284 else {
285 hMenu = 0;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000286 ERR("Unable to load default system menu\n" );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000287 }
288
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000289 TRACE("returning %x.\n", hMenu );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000290
291 return hMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000292}
293
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000294/***********************************************************************
295 * MENU_GetTopPopupWnd()
296 *
297 * Return the locked pointer pTopPopupWnd.
298 */
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000299static WND *MENU_GetTopPopupWnd()
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000300{
301 return WIN_LockWndPtr(pTopPopupWnd);
302}
303/***********************************************************************
304 * MENU_ReleaseTopPopupWnd()
305 *
306 * Realease the locked pointer pTopPopupWnd.
307 */
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000308static void MENU_ReleaseTopPopupWnd()
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000309{
310 WIN_ReleaseWndPtr(pTopPopupWnd);
311}
312/***********************************************************************
313 * MENU_DestroyTopPopupWnd()
314 *
315 * Destroy the locked pointer pTopPopupWnd.
316 */
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000317static void MENU_DestroyTopPopupWnd()
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000318{
319 WND *tmpWnd = pTopPopupWnd;
320 pTopPopupWnd = NULL;
321 WIN_ReleaseWndPtr(tmpWnd);
322}
323
324
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000325
326/**********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000327 * MENU_GetSysMenu
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000328 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000329 * Create a copy of the system menu. System menu in Windows is
330 * a special menu-bar with the single entry - system menu popup.
331 * This popup is presented to the outside world as a "system menu".
332 * However, the real system menu handle is sometimes seen in the
333 * WM_MENUSELECT paramemters (and Word 6 likes it this way).
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000334 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000335HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu )
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000336{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000337 HMENU hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000338
Alexandre Julliarda3960291999-02-26 11:11:13 +0000339 if ((hMenu = CreateMenu()))
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000340 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000341 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hMenu);
342 menu->wFlags = MF_SYSMENU;
343 menu->hWnd = hWnd;
344
Alexandre Julliarda3960291999-02-26 11:11:13 +0000345 if (hPopupMenu == (HMENU)(-1))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000346 hPopupMenu = MENU_CopySysPopup();
347 else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
348
349 if (hPopupMenu)
350 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000351 InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000352
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000353 menu->items[0].fType = MF_SYSMENU | MF_POPUP;
354 menu->items[0].fState = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000355 menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hPopupMenu);
356 menu->wFlags |= MF_SYSMENU;
357
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000358 TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000359 return hMenu;
360 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000361 DestroyMenu( hMenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000362 }
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000363 ERR("failed to load system menu!\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000364 return 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000365}
366
367
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000368/***********************************************************************
369 * MENU_Init
370 *
371 * Menus initialisation.
372 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000373BOOL MENU_Init()
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000374{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000375 HBITMAP hBitmap;
Juergen Schmied78513941999-04-18 14:40:32 +0000376 NONCLIENTMETRICSA ncm;
377
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000378 static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
379 0x55, 0, 0xAA, 0,
380 0x55, 0, 0xAA, 0,
381 0x55, 0, 0xAA, 0 };
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000382
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000383 /* Load menu bitmaps */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000384 hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
385 hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
386 hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
Francois Boisvert8b391741999-02-09 14:09:55 +0000387 /* Load system buttons bitmaps */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000388 hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
389 hBmpMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
390 hBmpMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
391 hBmpMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
392 hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
393 hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000394
395 if (hStdCheck)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000396 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000397 BITMAP bm;
398 GetObjectA( hStdCheck, sizeof(bm), &bm );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000399 check_bitmap_width = bm.bmWidth;
400 check_bitmap_height = bm.bmHeight;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000401 } else
402 return FALSE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000403
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000404 /* Assume that radio checks have the same size as regular check. */
405 if (!hStdRadioCheck)
406 return FALSE;
407
408 if (hStdMnArrow)
Juergen Schmied78513941999-04-18 14:40:32 +0000409 {
410 BITMAP bm;
411 GetObjectA( hStdMnArrow, sizeof(bm), &bm );
412 arrow_bitmap_width = bm.bmWidth;
413 arrow_bitmap_height = bm.bmHeight;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000414 } else
Juergen Schmied78513941999-04-18 14:40:32 +0000415 return FALSE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000416
Juergen Schmied78513941999-04-18 14:40:32 +0000417 if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
418 return FALSE;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000419
Juergen Schmied78513941999-04-18 14:40:32 +0000420 if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
421 return FALSE;
422
423 DeleteObject( hBitmap );
424 if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
425 return FALSE;
426
427 ncm.cbSize = sizeof (NONCLIENTMETRICSA);
428 if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
429 return FALSE;
430
431 if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
432 return FALSE;
433
Juergen Schmied466a6521999-05-02 11:21:08 +0000434 ncm.lfMenuFont.lfWeight += 300;
435 if ( ncm.lfMenuFont.lfWeight > 1000)
436 ncm.lfMenuFont.lfWeight = 1000;
437
438 if (!(hMenuFontBold = CreateFontIndirectA( &ncm.lfMenuFont )))
439 return FALSE;
440
Juergen Schmied78513941999-04-18 14:40:32 +0000441 return TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000442}
443
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000444/***********************************************************************
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000445 * MENU_InitSysMenuPopup
446 *
447 * Grey the appropriate items in System menu.
448 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000449static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000450{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000451 BOOL gray;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000452
453 gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000454 EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000455 gray = ((style & WS_MAXIMIZE) != 0);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000456 EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000457 gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000458 EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000459 gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000460 EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000461 gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000462 EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000463 gray = (clsStyle & CS_NOCLOSE) != 0;
Pascal Lessardd814bb61999-07-31 13:02:02 +0000464
465 /* The menu item must keep its state if it's disabled */
466 if(gray)
467 EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000468}
469
470
Alexandre Julliard641ee761997-08-04 16:34:36 +0000471/******************************************************************************
472 *
473 * UINT32 MENU_GetStartOfNextColumn(
474 * HMENU32 hMenu )
475 *
476 *****************************************************************************/
477
Alexandre Julliarda3960291999-02-26 11:11:13 +0000478static UINT MENU_GetStartOfNextColumn(
479 HMENU hMenu )
Alexandre Julliard641ee761997-08-04 16:34:36 +0000480{
481 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000482 UINT i = menu->FocusedItem + 1;
Alexandre Julliard641ee761997-08-04 16:34:36 +0000483
484 if(!menu)
485 return NO_SELECTED_ITEM;
486
487 if( i == NO_SELECTED_ITEM )
488 return i;
489
490 for( ; i < menu->nItems; ++i ) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000491 if (menu->items[i].fType & MF_MENUBARBREAK)
Alexandre Julliard641ee761997-08-04 16:34:36 +0000492 return i;
493 }
494
495 return NO_SELECTED_ITEM;
496}
497
498
499/******************************************************************************
500 *
501 * UINT32 MENU_GetStartOfPrevColumn(
502 * HMENU32 hMenu )
503 *
504 *****************************************************************************/
505
Alexandre Julliarda3960291999-02-26 11:11:13 +0000506static UINT MENU_GetStartOfPrevColumn(
507 HMENU hMenu )
Alexandre Julliard641ee761997-08-04 16:34:36 +0000508{
509 POPUPMENU const *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000510 UINT i;
Alexandre Julliard641ee761997-08-04 16:34:36 +0000511
512 if( !menu )
513 return NO_SELECTED_ITEM;
514
515 if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
516 return NO_SELECTED_ITEM;
517
518 /* Find the start of the column */
519
520 for(i = menu->FocusedItem; i != 0 &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000521 !(menu->items[i].fType & MF_MENUBARBREAK);
Alexandre Julliard641ee761997-08-04 16:34:36 +0000522 --i); /* empty */
523
524 if(i == 0)
525 return NO_SELECTED_ITEM;
526
527 for(--i; i != 0; --i) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000528 if (menu->items[i].fType & MF_MENUBARBREAK)
Alexandre Julliard641ee761997-08-04 16:34:36 +0000529 break;
530 }
531
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000532 TRACE("ret %d.\n", i );
Alexandre Julliard641ee761997-08-04 16:34:36 +0000533
534 return i;
535}
536
537
538
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000539/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000540 * MENU_FindItem
541 *
542 * Find a menu item. Return a pointer on the item, and modifies *hmenu
543 * in case the item was in a sub-menu.
544 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000545static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000546{
547 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000548 UINT i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000549
Juergen Schmied78513941999-04-18 14:40:32 +0000550 if (((*hmenu)==0xffff) || (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(*hmenu)))) return NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000551 if (wFlags & MF_BYPOSITION)
552 {
553 if (*nPos >= menu->nItems) return NULL;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000554 return &menu->items[*nPos];
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000555 }
556 else
557 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000558 MENUITEM *item = menu->items;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000559 for (i = 0; i < menu->nItems; i++, item++)
560 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000561 if (item->wID == *nPos)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000562 {
563 *nPos = i;
564 return item;
565 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000566 else if (item->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000567 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000568 HMENU hsubmenu = item->hSubMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000569 MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
570 if (subitem)
571 {
572 *hmenu = hsubmenu;
573 return subitem;
574 }
575 }
576 }
577 }
578 return NULL;
579}
580
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000581/***********************************************************************
582 * MENU_FreeItemData
583 */
584static void MENU_FreeItemData( MENUITEM* item )
585{
586 /* delete text */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000587 if (IS_STRING_ITEM(item->fType) && item->text)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000588 HeapFree( SystemHeap, 0, item->text );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000589}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000590
591/***********************************************************************
592 * MENU_FindItemByCoords
593 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000594 * Find the item at the specified coordinates (screen coords). Does
595 * not work for child windows and therefore should not be called for
596 * an arbitrary system menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000597 */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000598static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000599 POINT pt, UINT *pos )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000600{
601 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000602 UINT i;
Marcus Meissnerac593bb1999-03-17 15:18:28 +0000603 RECT wrect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000604
Marcus Meissnerac593bb1999-03-17 15:18:28 +0000605 if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
606 pt.x -= wrect.left;pt.y -= wrect.top;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000607 item = menu->items;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000608 for (i = 0; i < menu->nItems; i++, item++)
609 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000610 if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
611 (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000612 {
613 if (pos) *pos = i;
614 return item;
615 }
616 }
617 return NULL;
618}
619
620
621/***********************************************************************
622 * MENU_FindItemByKey
623 *
624 * Find the menu item selected by a key press.
625 * Return item id, -1 if none, -2 if we should close the menu.
626 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000627static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
628 UINT key, BOOL forceMenuChar )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000629{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000630 TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000631
Alexandre Julliarda3960291999-02-26 11:11:13 +0000632 if (!IsMenu( hmenu ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000633 {
634 WND* w = WIN_FindWndPtr(hwndOwner);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000635 hmenu = GetSubMenu(w->hSysMenu, 0);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000636 WIN_ReleaseWndPtr(w);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000637 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000638
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000639 if (hmenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000640 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000641 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
642 MENUITEM *item = menu->items;
643 LONG menuchar;
644
645 if( !forceMenuChar )
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000646 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000647 UINT i;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000648
649 key = toupper(key);
650 for (i = 0; i < menu->nItems; i++, item++)
651 {
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000652 if (item->text && (IS_STRING_ITEM(item->fType)))
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000653 {
Norman Stevensa83d0651998-10-12 07:25:35 +0000654 char *p = item->text - 2;
655 do
656 {
657 p = strchr (p + 2, '&');
658 }
659 while (p != NULL && p [1] == '&');
660 if (p && (toupper(p[1]) == key)) return i;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000661 }
662 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000663 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000664 menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000665 MAKEWPARAM( key, menu->wFlags ), hmenu );
666 if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000667 if (HIWORD(menuchar) == 1) return (UINT)(-2);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000668 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000669 return (UINT)(-1);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000670}
Francois Boisvert8b391741999-02-09 14:09:55 +0000671/***********************************************************************
672 * MENU_LoadMagicItem
673 *
674 * Load the bitmap associated with the magic menu item and its style
675 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000676
Juergen Schmied78513941999-04-18 14:40:32 +0000677static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
Francois Boisvert8b391741999-02-09 14:09:55 +0000678{
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000679 /*
680 * Magic menu item id's section
681 * These magic id's are used by windows to insert "standard" mdi
682 * buttons (minimize,restore,close) on menu. Under windows,
683 * these magic id's make sure the right things appear when those
684 * bitmap buttons are pressed/selected/released.
685 */
Francois Boisvert8b391741999-02-09 14:09:55 +0000686
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000687 switch(id & 0xffff)
Juergen Schmied78513941999-04-18 14:40:32 +0000688 { case HBMMENU_SYSTEM:
689 return (dwItemData) ?
690 (HBITMAP)dwItemData :
691 (hilite ? hBmpMinimizeD : hBmpMinimize);
692 case HBMMENU_MBAR_RESTORE:
693 return (hilite ? hBmpMaximizeD: hBmpMaximize);
694 case HBMMENU_MBAR_MINIMIZE:
695 return (hilite ? hBmpMinimizeD : hBmpMinimize);
696 case HBMMENU_MBAR_CLOSE:
697 return (hilite ? hBmpCloseD : hBmpClose);
698 case HBMMENU_CALLBACK:
699 case HBMMENU_MBAR_CLOSE_D:
700 case HBMMENU_MBAR_MINIMIZE_D:
701 case HBMMENU_POPUP_CLOSE:
702 case HBMMENU_POPUP_RESTORE:
703 case HBMMENU_POPUP_MAXIMIZE:
704 case HBMMENU_POPUP_MINIMIZE:
705 default:
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000706 FIXME("Magic 0x%08x not implemented\n", id);
Juergen Schmied78513941999-04-18 14:40:32 +0000707 return 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000708 }
709
710}
Alexandre Julliardf7207251994-07-23 07:57:48 +0000711
712/***********************************************************************
713 * MENU_CalcItemSize
714 *
715 * Calculate the size of the menu item and store it in lpitem->rect.
716 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000717static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
718 INT orgX, INT orgY, BOOL menuBar )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000719{
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000720 char *p;
721
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000722 TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000723 debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
724 (menuBar ? " (MenuBar)" : ""));
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000725
Alexandre Julliarda3960291999-02-26 11:11:13 +0000726 SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000727
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000728 if (lpitem->fType & MF_OWNERDRAW)
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000729 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000730 MEASUREITEMSTRUCT mis;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000731 mis.CtlType = ODT_MENU;
Juergen Schmied7abca951999-04-11 17:02:30 +0000732 mis.CtlID = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000733 mis.itemID = lpitem->wID;
Juergen Schmied7abca951999-04-11 17:02:30 +0000734 mis.itemData = (DWORD)lpitem->dwItemData;
735 mis.itemHeight = 0;
736 mis.itemWidth = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000737 SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000738 lpitem->rect.bottom += mis.itemHeight;
739 lpitem->rect.right += mis.itemWidth;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000740 TRACE("id=%04x size=%dx%d\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000741 lpitem->wID, mis.itemWidth, mis.itemHeight);
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000742 return;
Alexandre Julliardfa68b751995-04-03 16:55:37 +0000743 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000744
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000745 if (lpitem->fType & MF_SEPARATOR)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000746 {
747 lpitem->rect.bottom += SEPARATOR_HEIGHT;
748 return;
749 }
750
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000751 if (!menuBar)
752 {
753 lpitem->rect.right += 2 * check_bitmap_width;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000754 if (lpitem->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000755 lpitem->rect.right += arrow_bitmap_width;
756 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000757
Juergen Schmied78513941999-04-18 14:40:32 +0000758 if (IS_BITMAP_ITEM(lpitem->fType))
Alexandre Julliardf7207251994-07-23 07:57:48 +0000759 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000760 BITMAP bm;
Juergen Schmied78513941999-04-18 14:40:32 +0000761 HBITMAP resBmp = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000762
Patrik Stridvall1bb94031999-05-08 15:47:44 +0000763 /* Check if there is a magic menu item associated with this item */
Juergen Schmied78513941999-04-18 14:40:32 +0000764 if((LOWORD((int)lpitem->text))<12)
765 {
766 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
767 lpitem->dwItemData);
Francois Boisvert8b391741999-02-09 14:09:55 +0000768 }
769 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000770 resBmp = (HBITMAP)lpitem->text;
Francois Boisvert8b391741999-02-09 14:09:55 +0000771
Alexandre Julliarda3960291999-02-26 11:11:13 +0000772 if (GetObjectA(resBmp, sizeof(bm), &bm ))
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000773 {
774 lpitem->rect.right += bm.bmWidth;
775 lpitem->rect.bottom += bm.bmHeight;
Francois Boisvert8b391741999-02-09 14:09:55 +0000776
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000777 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000778 }
779
Juergen Schmied78513941999-04-18 14:40:32 +0000780
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000781 /* If we get here, then it must be a text item */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000782 if (IS_STRING_ITEM( lpitem->fType ))
Juergen Schmied78513941999-04-18 14:40:32 +0000783 { SIZE size;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000784
Juergen Schmied78513941999-04-18 14:40:32 +0000785 GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
786
787 lpitem->rect.right += size.cx;
788 if (TWEAK_WineLook == WIN31_LOOK)
Marcus Meissnerddca3151999-05-22 11:33:23 +0000789 lpitem->rect.bottom += MAX( size.cy, GetSystemMetrics(SM_CYMENU) );
Juergen Schmied78513941999-04-18 14:40:32 +0000790 else
Marcus Meissnerddca3151999-05-22 11:33:23 +0000791 lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
Juergen Schmied78513941999-04-18 14:40:32 +0000792 lpitem->xTab = 0;
793
794 if (menuBar)
795 {
796 lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
797 }
798 else if ((p = strchr( lpitem->text, '\t' )) != NULL)
799 {
800 /* Item contains a tab (only meaningful in popup menus) */
801 GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
802 lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
803 lpitem->rect.right += MENU_TAB_SPACE;
804 }
805 else
806 {
807 if (strchr( lpitem->text, '\b' ))
808 lpitem->rect.right += MENU_TAB_SPACE;
809 lpitem->xTab = lpitem->rect.right - check_bitmap_width
810 - arrow_bitmap_width;
811 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000812 }
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000813 TRACE("(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
Alexandre Julliardf7207251994-07-23 07:57:48 +0000814}
815
816
817/***********************************************************************
818 * MENU_PopupMenuCalcSize
819 *
820 * Calculate the size of a popup menu.
821 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000822static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000823{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000824 MENUITEM *lpitem;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000825 HDC hdc;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000826 int start, i;
827 int orgX, orgY, maxX, maxTab, maxTabWidth;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000828
Alexandre Julliardf7207251994-07-23 07:57:48 +0000829 lppop->Width = lppop->Height = 0;
830 if (lppop->nItems == 0) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000831 hdc = GetDC( 0 );
Juergen Schmied78513941999-04-18 14:40:32 +0000832
833 SelectObject( hdc, hMenuFont);
834
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000835 start = 0;
Marcus Meissnerddca3151999-05-22 11:33:23 +0000836 maxX = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CXBORDER) : 2 ;
Juergen Schmied466a6521999-05-02 11:21:08 +0000837
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000838 while (start < lppop->nItems)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000839 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000840 lpitem = &lppop->items[start];
Alexandre Julliardf7207251994-07-23 07:57:48 +0000841 orgX = maxX;
Marcus Meissnerddca3151999-05-22 11:33:23 +0000842 orgY = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CYBORDER) : 2;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000843
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000844 maxTab = maxTabWidth = 0;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000845
846 /* Parse items until column break or end of menu */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000847 for (i = start; i < lppop->nItems; i++, lpitem++)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000848 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000849 if ((i != start) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000850 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000851
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000852 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
Pascal Lessard47274231999-02-13 12:21:46 +0000853
Juergen Schmied466a6521999-05-02 11:21:08 +0000854 if (lpitem->fType & MF_MENUBARBREAK) orgX++;
Alexandre Julliard902da691995-11-05 14:39:02 +0000855 maxX = MAX( maxX, lpitem->rect.right );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000856 orgY = lpitem->rect.bottom;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000857 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000858 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000859 maxTab = MAX( maxTab, lpitem->xTab );
860 maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000861 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000862 }
863
864 /* Finish the column (set all items to the largest width found) */
Alexandre Julliard902da691995-11-05 14:39:02 +0000865 maxX = MAX( maxX, maxTab + maxTabWidth );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000866 for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000867 {
868 lpitem->rect.right = maxX;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000869 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
Juergen Schmied466a6521999-05-02 11:21:08 +0000870 lpitem->xTab = maxTab;
871
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000872 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000873 lppop->Height = MAX( lppop->Height, orgY );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000874 }
875
876 lppop->Width = maxX;
Juergen Schmied466a6521999-05-02 11:21:08 +0000877
878 /* space for 3d border */
879 if(TWEAK_WineLook > WIN31_LOOK)
880 {
881 lppop->Height += 2;
882 lppop->Width += 2;
883 }
884
Alexandre Julliarda3960291999-02-26 11:11:13 +0000885 ReleaseDC( 0, hdc );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000886}
887
888
889/***********************************************************************
890 * MENU_MenuBarCalcSize
891 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000892 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000893 * height is off by 1 pixel which causes lengthy window relocations when
894 * active document window is maximized/restored.
895 *
Alexandre Julliardf7207251994-07-23 07:57:48 +0000896 * Calculate the size of the menu bar.
897 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000898static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
899 LPPOPUPMENU lppop, HWND hwndOwner )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000900{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000901 MENUITEM *lpitem;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000902 int start, i, orgX, orgY, maxY, helpPos;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000903
904 if ((lprect == NULL) || (lppop == NULL)) return;
905 if (lppop->nItems == 0) return;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000906 TRACE("left=%d top=%d right=%d bottom=%d\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000907 lprect->left, lprect->top, lprect->right, lprect->bottom);
Alexandre Julliardf7207251994-07-23 07:57:48 +0000908 lppop->Width = lprect->right - lprect->left;
909 lppop->Height = 0;
910 maxY = lprect->top;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000911 start = 0;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000912 helpPos = -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000913 while (start < lppop->nItems)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000914 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000915 lpitem = &lppop->items[start];
Alexandre Julliardf7207251994-07-23 07:57:48 +0000916 orgX = lprect->left;
917 orgY = maxY;
918
919 /* Parse items until line break or end of menu */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000920 for (i = start; i < lppop->nItems; i++, lpitem++)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000921 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000922 if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000923 if ((i != start) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000924 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000925
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000926 TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000927 orgX, orgY );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000928 debug_print_menuitem (" item: ", lpitem, "");
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000929 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
Pascal Lessard47274231999-02-13 12:21:46 +0000930
Alexandre Julliardf7207251994-07-23 07:57:48 +0000931 if (lpitem->rect.right > lprect->right)
932 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000933 if (i != start) break;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000934 else lpitem->rect.right = lprect->right;
935 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000936 maxY = MAX( maxY, lpitem->rect.bottom );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000937 orgX = lpitem->rect.right;
938 }
939
940 /* Finish the line (set all items to the largest height found) */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000941 while (start < i) lppop->items[start++].rect.bottom = maxY;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000942 }
943
944 lprect->bottom = maxY;
945 lppop->Height = lprect->bottom - lprect->top;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000946
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000947 /* Flush right all magic items and items between the MF_HELP and */
948 /* the last item (if several lines, only move the last line) */
949 lpitem = &lppop->items[lppop->nItems-1];
950 orgY = lpitem->rect.top;
951 orgX = lprect->right;
952 for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000953 {
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000954 if ( !IS_BITMAP_ITEM(lpitem->fType) && ((helpPos ==-1) ? TRUE : (helpPos>i) ))
955 break; /* done */
956 if (lpitem->rect.top != orgY) break; /* Other line */
957 if (lpitem->rect.right >= orgX) break; /* Too far right already */
958 lpitem->rect.left += orgX - lpitem->rect.right;
959 lpitem->rect.right = orgX;
960 orgX = lpitem->rect.left;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000961 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000962}
963
Alexandre Julliardf7207251994-07-23 07:57:48 +0000964/***********************************************************************
965 * MENU_DrawMenuItem
966 *
967 * Draw a single menu item.
968 */
Juergen Schmied78513941999-04-18 14:40:32 +0000969static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000970 UINT height, BOOL menuBar, UINT odaction )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000971{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000972 RECT rect;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000973
Alexandre Julliard03468f71998-02-15 19:40:49 +0000974 debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000975
976 if (lpitem->fType & MF_SYSMENU)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000977 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000978 if( !IsIconic(hwnd) ) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000979 if (TWEAK_WineLook > WIN31_LOOK)
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000980 NC_DrawSysButton95( hwnd, hdc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000981 lpitem->fState &
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000982 (MF_HILITE | MF_MOUSESELECT) );
983 else
984 NC_DrawSysButton( hwnd, hdc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000985 lpitem->fState &
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000986 (MF_HILITE | MF_MOUSESELECT) );
987 }
988
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000989 return;
990 }
991
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000992 if (lpitem->fType & MF_OWNERDRAW)
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000993 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000994 DRAWITEMSTRUCT dis;
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000995
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000996 dis.CtlType = ODT_MENU;
Juergen Schmied7abca951999-04-11 17:02:30 +0000997 dis.CtlID = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000998 dis.itemID = lpitem->wID;
Juergen Schmied7abca951999-04-11 17:02:30 +0000999 dis.itemData = (DWORD)lpitem->dwItemData;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001000 dis.itemState = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001001 if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
1002 if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
1003 if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001004 dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
Juergen Schmied78513941999-04-18 14:40:32 +00001005 dis.hwndItem = hmenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001006 dis.hDC = hdc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001007 dis.rcItem = lpitem->rect;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001008 TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
Juergen Schmied78513941999-04-18 14:40:32 +00001009 "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
1010 dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
1011 dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
1012 dis.rcItem.bottom);
1013 SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001014 return;
Alexandre Julliardfa68b751995-04-03 16:55:37 +00001015 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001016
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001017 TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
Juergen Schmied78513941999-04-18 14:40:32 +00001018 lpitem->rect.right,lpitem->rect.bottom);
1019
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001020 if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
Juergen Schmied78513941999-04-18 14:40:32 +00001021
Alexandre Julliardf7207251994-07-23 07:57:48 +00001022 rect = lpitem->rect;
1023
Juergen Schmied466a6521999-05-02 11:21:08 +00001024 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
Juergen Schmied78513941999-04-18 14:40:32 +00001025 if ((menuBar) && (TWEAK_WineLook==WIN98_LOOK))
1026 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
1027 else
1028 FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001029 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001030 FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001031
Alexandre Julliarda3960291999-02-26 11:11:13 +00001032 SetBkMode( hdc, TRANSPARENT );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001033
Juergen Schmied78513941999-04-18 14:40:32 +00001034 /* vertical separator */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001035 if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
Alexandre Julliardf7207251994-07-23 07:57:48 +00001036 {
Juergen Schmied78513941999-04-18 14:40:32 +00001037 if (TWEAK_WineLook > WIN31_LOOK)
1038 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001039 RECT rc = rect;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001040 rc.top = 3;
1041 rc.bottom = height - 3;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001042 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001043 }
Juergen Schmied78513941999-04-18 14:40:32 +00001044 else
1045 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001046 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1047 MoveTo16( hdc, rect.left, 0 );
1048 LineTo( hdc, rect.left, height );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001049 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001050 }
Juergen Schmied78513941999-04-18 14:40:32 +00001051
1052 /* horizontal separator */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001053 if (lpitem->fType & MF_SEPARATOR)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001054 {
Juergen Schmied78513941999-04-18 14:40:32 +00001055 if (TWEAK_WineLook > WIN31_LOOK)
1056 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001057 RECT rc = rect;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001058 rc.left++;
1059 rc.right--;
1060 rc.top += SEPARATOR_HEIGHT / 2;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001061 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001062 }
Juergen Schmied78513941999-04-18 14:40:32 +00001063 else
1064 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001065 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1066 MoveTo16( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2 );
1067 LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001068 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001069 return;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001070 }
1071
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001072 /* Setup colors */
1073
Juergen Schmied78513941999-04-18 14:40:32 +00001074 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001075 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001076 if (lpitem->fState & MF_GRAYED)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001077 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001078 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001079 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
1080 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001081 }
1082 else
1083 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001084 if (lpitem->fState & MF_GRAYED)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001085 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001086 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001087 SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
1088 SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001089 }
1090
Juergen Schmied78513941999-04-18 14:40:32 +00001091 /* helper lines for debugging */
1092/* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1093 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1094 MoveTo16( hdc, rect.left, (rect.top + rect.bottom)/2 );
1095 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1096*/
1097
Alexandre Julliardf7207251994-07-23 07:57:48 +00001098 if (!menuBar)
1099 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001100 INT y = rect.top + rect.bottom;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001101
1102 /* Draw the check mark
1103 *
Huw D M Davies2d617be1998-12-08 09:14:09 +00001104 * FIXME:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001105 * Custom checkmark bitmaps are monochrome but not always 1bpp.
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001106 */
Alexandre Julliardf7207251994-07-23 07:57:48 +00001107
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001108 if (lpitem->fState & MF_CHECKED)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001109 {
Juergen Schmied78513941999-04-18 14:40:32 +00001110 HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
1111 ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001112 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001113
Alexandre Julliarda3960291999-02-26 11:11:13 +00001114 SelectObject( hdcMem, bm );
Juergen Schmied78513941999-04-18 14:40:32 +00001115 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001116 check_bitmap_width, check_bitmap_height,
1117 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001118 DeleteDC( hdcMem );
Juergen Schmied78513941999-04-18 14:40:32 +00001119 }
1120 else if (lpitem->hUnCheckBit)
1121 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001122 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001123
Alexandre Julliarda3960291999-02-26 11:11:13 +00001124 SelectObject( hdcMem, lpitem->hUnCheckBit );
Juergen Schmied78513941999-04-18 14:40:32 +00001125 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001126 check_bitmap_width, check_bitmap_height,
1127 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001128 DeleteDC( hdcMem );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001129 }
Juergen Schmied78513941999-04-18 14:40:32 +00001130
Alexandre Julliardf7207251994-07-23 07:57:48 +00001131 /* Draw the popup-menu arrow */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001132 if (lpitem->fType & MF_POPUP)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001133 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001134 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001135
Alexandre Julliarda3960291999-02-26 11:11:13 +00001136 SelectObject( hdcMem, hStdMnArrow );
Juergen Schmied78513941999-04-18 14:40:32 +00001137 BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001138 (y - arrow_bitmap_height) / 2,
1139 arrow_bitmap_width, arrow_bitmap_height,
1140 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001141 DeleteDC( hdcMem );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001142 }
1143
1144 rect.left += check_bitmap_width;
1145 rect.right -= arrow_bitmap_width;
1146 }
1147
Juergen Schmied78513941999-04-18 14:40:32 +00001148 /* Draw the item text or bitmap */
1149 if (IS_BITMAP_ITEM(lpitem->fType))
1150 { int top;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001151
Alexandre Julliarda3960291999-02-26 11:11:13 +00001152 HBITMAP resBmp = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +00001153
Alexandre Julliarda3960291999-02-26 11:11:13 +00001154 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001155
Patrik Stridvall1bb94031999-05-08 15:47:44 +00001156 /*
1157 * Check if there is a magic menu item associated with this item
1158 * and load the appropriate bitmap
1159 */
Juergen Schmied78513941999-04-18 14:40:32 +00001160 if((LOWORD((int)lpitem->text)) < 12)
1161 {
1162 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
1163 lpitem->dwItemData);
Francois Boisvert8b391741999-02-09 14:09:55 +00001164 }
1165 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001166 resBmp = (HBITMAP)lpitem->text;
Juergen Schmied78513941999-04-18 14:40:32 +00001167
1168 if (resBmp)
1169 {
1170 BITMAP bm;
1171 GetObjectA( resBmp, sizeof(bm), &bm );
1172
1173 SelectObject(hdcMem,resBmp );
1174
1175 /* handle fontsize > bitmap_height */
1176 top = ((rect.bottom-rect.top)>bm.bmHeight) ?
1177 rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
1178
1179 BitBlt( hdc, rect.left, top, rect.right - rect.left,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001180 rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
Juergen Schmied78513941999-04-18 14:40:32 +00001181 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001182 DeleteDC( hdcMem );
Juergen Schmied78513941999-04-18 14:40:32 +00001183
Alexandre Julliardf7207251994-07-23 07:57:48 +00001184 return;
Francois Boisvert8b391741999-02-09 14:09:55 +00001185
Alexandre Julliardf7207251994-07-23 07:57:48 +00001186 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001187 /* No bitmap - process text if present */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001188 else if (IS_STRING_ITEM(lpitem->fType))
Alexandre Julliardf7207251994-07-23 07:57:48 +00001189 {
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001190 register int i;
Juergen Schmied466a6521999-05-02 11:21:08 +00001191 HFONT hfontOld = 0;
1192
Juergen Schmied78513941999-04-18 14:40:32 +00001193 UINT uFormat = (menuBar) ?
1194 DT_CENTER | DT_VCENTER | DT_SINGLELINE :
1195 DT_LEFT | DT_VCENTER | DT_SINGLELINE;
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001196
Juergen Schmied466a6521999-05-02 11:21:08 +00001197 if ( lpitem->fState & MFS_DEFAULT )
1198 {
1199 hfontOld = SelectObject( hdc, hMenuFontBold);
1200 }
1201
Alexandre Julliardf7207251994-07-23 07:57:48 +00001202 if (menuBar)
1203 {
1204 rect.left += MENU_BAR_ITEMS_SPACE / 2;
1205 rect.right -= MENU_BAR_ITEMS_SPACE / 2;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001206 i = strlen( lpitem->text );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001207 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001208 else
Alexandre Julliardf7207251994-07-23 07:57:48 +00001209 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001210 for (i = 0; lpitem->text[i]; i++)
Juergen Schmied466a6521999-05-02 11:21:08 +00001211 if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
1212 break;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001213 }
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001214
Juergen Schmied466a6521999-05-02 11:21:08 +00001215 if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
Juergen Schmied78513941999-04-18 14:40:32 +00001216 {
Juergen Schmied466a6521999-05-02 11:21:08 +00001217 if (!(lpitem->fState & MF_HILITE) )
Juergen Schmied78513941999-04-18 14:40:32 +00001218 {
Juergen Schmied466a6521999-05-02 11:21:08 +00001219 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001220 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
Juergen Schmied78513941999-04-18 14:40:32 +00001221 DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
Juergen Schmied466a6521999-05-02 11:21:08 +00001222 --rect.left; --rect.top; --rect.right; --rect.bottom;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001223 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001224 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001225 }
Juergen Schmied466a6521999-05-02 11:21:08 +00001226
1227 DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001228
Juergen Schmied466a6521999-05-02 11:21:08 +00001229 /* paint the shortcut text */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001230 if (lpitem->text[i]) /* There's a tab or flush-right char */
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001231 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001232 if (lpitem->text[i] == '\t')
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001233 {
1234 rect.left = lpitem->xTab;
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +00001235 uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001236 }
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +00001237 else
1238 {
1239 uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
1240 }
1241
Juergen Schmied466a6521999-05-02 11:21:08 +00001242 if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
1243 {
1244 if (!(lpitem->fState & MF_HILITE) )
1245 {
1246 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
1247 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
1248 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
1249 --rect.left; --rect.top; --rect.right; --rect.bottom;
1250 }
1251 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
1252 }
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +00001253 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001254 }
Juergen Schmied466a6521999-05-02 11:21:08 +00001255
1256 if (hfontOld)
1257 SelectObject (hdc, hfontOld);
Alexandre Julliardf7207251994-07-23 07:57:48 +00001258 }
1259}
1260
1261
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001262/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001263 * MENU_DrawPopupMenu
1264 *
1265 * Paint a popup menu.
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001266 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001267static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001268{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001269 HBRUSH hPrevBrush = 0;
1270 RECT rect;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001271
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001272 TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
Juergen Schmied78513941999-04-18 14:40:32 +00001273
Alexandre Julliarda3960291999-02-26 11:11:13 +00001274 GetClientRect( hwnd, &rect );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001275
Alex Korobka44a1b591999-04-01 12:03:52 +00001276 if(TWEAK_WineLook == WIN31_LOOK)
1277 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001278 rect.bottom -= POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
1279 rect.right -= POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER);
Alex Korobka44a1b591999-04-01 12:03:52 +00001280 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001281
Juergen Schmied78513941999-04-18 14:40:32 +00001282 if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
1283 && (SelectObject( hdc, hMenuFont)))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001284 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001285 HPEN hPrevPen;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001286
Alexandre Julliarda3960291999-02-26 11:11:13 +00001287 Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001288
Alexandre Julliarda3960291999-02-26 11:11:13 +00001289 hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001290 if( hPrevPen )
1291 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001292 INT ropPrev, i;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001293 POPUPMENU *menu;
1294
1295 /* draw 3-d shade */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001296 if(TWEAK_WineLook == WIN31_LOOK) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001297 SelectObject( hdc, hShadeBrush );
1298 SetBkMode( hdc, TRANSPARENT );
1299 ropPrev = SetROP2( hdc, R2_MASKPEN );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001300
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001301 i = rect.right; /* why SetBrushOrg() doesn't? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001302 PatBlt( hdc, i & 0xfffffffe,
Marcus Meissnerddca3151999-05-22 11:33:23 +00001303 rect.top + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER),
1304 i%2 + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001305 rect.bottom - rect.top, 0x00a000c9 );
1306 i = rect.bottom;
Marcus Meissnerddca3151999-05-22 11:33:23 +00001307 PatBlt( hdc, rect.left + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001308 i & 0xfffffffe,rect.right - rect.left,
Marcus Meissnerddca3151999-05-22 11:33:23 +00001309 i%2 + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER), 0x00a000c9 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001310 SelectObject( hdc, hPrevPen );
1311 SelectObject( hdc, hPrevBrush );
1312 SetROP2( hdc, ropPrev );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001313 }
1314 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001315 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001316
1317 /* draw menu items */
1318
1319 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1320 if (menu && menu->nItems)
1321 {
1322 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001323 UINT u;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001324
1325 for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
Juergen Schmied78513941999-04-18 14:40:32 +00001326 MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
1327 menu->Height, FALSE, ODA_DRAWENTIRE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001328
1329 }
Juergen Schmied78513941999-04-18 14:40:32 +00001330 } else
1331 {
1332 SelectObject( hdc, hPrevBrush );
1333 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001334 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001335}
1336
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001337/***********************************************************************
1338 * MENU_DrawMenuBar
1339 *
1340 * Paint a menu bar. Returns the height of the menu bar.
Juergen Schmied78513941999-04-18 14:40:32 +00001341 * called from [windows/nonclient.c]
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001342 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001343UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
1344 BOOL suppress_draw)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001345{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001346 LPPOPUPMENU lppop;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001347 UINT i,retvalue;
Juergen Schmied78513941999-04-18 14:40:32 +00001348 HFONT hfontOld = 0;
1349
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001350 WND *wndPtr = WIN_FindWndPtr( hwnd );
1351
Juergen Schmied78513941999-04-18 14:40:32 +00001352 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( (HMENU)wndPtr->wIDmenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001353 if (lppop == NULL || lprect == NULL)
1354 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001355 retvalue = GetSystemMetrics(SM_CYMENU);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001356 goto END;
1357 }
Juergen Schmied78513941999-04-18 14:40:32 +00001358
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001359 TRACE("(%04x, %p, %p)\n", hDC, lprect, lppop);
Juergen Schmied78513941999-04-18 14:40:32 +00001360
1361 hfontOld = SelectObject( hDC, hMenuFont);
1362
1363 if (lppop->Height == 0)
1364 MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
1365
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001366 lprect->bottom = lprect->top + lppop->Height;
Juergen Schmied78513941999-04-18 14:40:32 +00001367
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001368 if (suppress_draw)
1369 {
1370 retvalue = lppop->Height;
1371 goto END;
1372 }
Juergen Schmied78513941999-04-18 14:40:32 +00001373
Alexandre Julliarda3960291999-02-26 11:11:13 +00001374 FillRect(hDC, lprect, GetSysColorBrush(COLOR_MENU) );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001375
Juergen Schmied78513941999-04-18 14:40:32 +00001376 if (TWEAK_WineLook == WIN31_LOOK)
1377 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001378 SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
1379 MoveTo16( hDC, lprect->left, lprect->bottom );
1380 LineTo( hDC, lprect->right, lprect->bottom );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001381 }
Juergen Schmied78513941999-04-18 14:40:32 +00001382 else
1383 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001384 SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
1385 MoveTo16( hDC, lprect->left, lprect->bottom );
1386 LineTo( hDC, lprect->right, lprect->bottom );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001387 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001388
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001389 if (lppop->nItems == 0)
1390 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001391 retvalue = GetSystemMetrics(SM_CYMENU);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001392 goto END;
1393 }
Juergen Schmied78513941999-04-18 14:40:32 +00001394
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001395 for (i = 0; i < lppop->nItems; i++)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001396 {
Juergen Schmied78513941999-04-18 14:40:32 +00001397 MENU_DrawMenuItem( hwnd, (HMENU)wndPtr->wIDmenu, GetWindow(hwnd,GW_OWNER),
1398 hDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001399 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001400 retvalue = lppop->Height;
Juergen Schmied78513941999-04-18 14:40:32 +00001401
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001402END:
Juergen Schmied78513941999-04-18 14:40:32 +00001403 if (hfontOld)
1404 SelectObject (hDC, hfontOld);
1405
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001406 WIN_ReleaseWndPtr(wndPtr);
1407 return retvalue;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001408}
1409
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001410/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001411 * MENU_PatchResidentPopup
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001412 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001413BOOL MENU_PatchResidentPopup( HQUEUE16 checkQueue, WND* checkWnd )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001414{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001415 WND *pTPWnd = MENU_GetTopPopupWnd();
1416
1417 if( pTPWnd )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001418 {
1419 HTASK16 hTask = 0;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001420
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001421 TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001422 checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
1423 pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001424
Alexandre Julliard77b99181997-09-14 17:17:23 +00001425 switch( checkQueue )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001426 {
Alexandre Julliard77b99181997-09-14 17:17:23 +00001427 case 0: /* checkWnd is the new popup owner */
1428 if( checkWnd )
1429 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001430 pTPWnd->owner = checkWnd;
1431 if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
Alexandre Julliard77b99181997-09-14 17:17:23 +00001432 hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
1433 }
1434 break;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001435
Alexandre Julliard77b99181997-09-14 17:17:23 +00001436 case 0xFFFF: /* checkWnd is destroyed */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001437 if( pTPWnd->owner == checkWnd )
1438 pTPWnd->owner = NULL;
1439 MENU_ReleaseTopPopupWnd();
Alexandre Julliard77b99181997-09-14 17:17:23 +00001440 return TRUE;
1441
1442 default: /* checkQueue is exiting */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001443 if( pTPWnd->hmemTaskQ == checkQueue )
Alexandre Julliard77b99181997-09-14 17:17:23 +00001444 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001445 hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
Alexandre Julliard77b99181997-09-14 17:17:23 +00001446 hTask = TASK_GetNextTask( hTask );
1447 }
1448 break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001449 }
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001450
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001451 if( hTask )
1452 {
1453 TDB* task = (TDB*)GlobalLock16( hTask );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001454 if( task )
1455 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001456 pTPWnd->hInstance = task->hInstance;
1457 pTPWnd->hmemTaskQ = task->hQueue;
1458 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001459 return TRUE;
1460 }
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001461 else WARN("failed to patch resident popup.\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001462 }
1463 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001464 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001465 return FALSE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001466}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001467
1468/***********************************************************************
1469 * MENU_ShowPopup
1470 *
1471 * Display a popup menu.
1472 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001473static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
1474 INT x, INT y, INT xanchor, INT yanchor )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001475{
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001476 POPUPMENU *menu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001477 WND *wndOwner = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001478
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001479 TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
Juergen Schmied78513941999-04-18 14:40:32 +00001480 hwndOwner, hmenu, id, x, y, xanchor, yanchor);
1481
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001482 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001483 if (menu->FocusedItem != NO_SELECTED_ITEM)
1484 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001485 menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001486 menu->FocusedItem = NO_SELECTED_ITEM;
1487 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001488
Juergen Schmied78513941999-04-18 14:40:32 +00001489 /* store the owner for DrawItem*/
1490 menu->hwndOwner = hwndOwner;
1491
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001492 if( (wndOwner = WIN_FindWndPtr( hwndOwner )) )
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001493 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001494 UINT width, height;
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001495
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001496 MENU_PopupMenuCalcSize( menu, hwndOwner );
1497
1498 /* adjust popup menu pos so that it fits within the desktop */
1499
Marcus Meissnerddca3151999-05-22 11:33:23 +00001500 width = menu->Width + GetSystemMetrics(SM_CXBORDER);
1501 height = menu->Height + GetSystemMetrics(SM_CYBORDER);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001502
Marcus Meissnerddca3151999-05-22 11:33:23 +00001503 if( x + width > GetSystemMetrics(SM_CXSCREEN ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001504 {
1505 if( xanchor )
1506 x -= width - xanchor;
Marcus Meissnerddca3151999-05-22 11:33:23 +00001507 if( x + width > GetSystemMetrics(SM_CXSCREEN))
1508 x = GetSystemMetrics(SM_CXSCREEN) - width;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001509 }
1510 if( x < 0 ) x = 0;
1511
Marcus Meissnerddca3151999-05-22 11:33:23 +00001512 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001513 {
1514 if( yanchor )
1515 y -= height + yanchor;
Marcus Meissnerddca3151999-05-22 11:33:23 +00001516 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
1517 y = GetSystemMetrics(SM_CYSCREEN) - height;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001518 }
1519 if( y < 0 ) y = 0;
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001520
Alex Korobka44a1b591999-04-01 12:03:52 +00001521 if( TWEAK_WineLook == WIN31_LOOK )
1522 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001523 width += POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER); /* add space for shading */
1524 height += POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
Alex Korobka44a1b591999-04-01 12:03:52 +00001525 }
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001526
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001527 /* NOTE: In Windows, top menu popup is not owned. */
1528 if (!pTopPopupWnd) /* create top level popup menu window */
1529 {
1530 assert( uSubPWndLevel == 0 );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001531
Alexandre Julliarda3960291999-02-26 11:11:13 +00001532 pTopPopupWnd = WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001533 WS_POPUP, x, y, width, height,
1534 hwndOwner, 0, wndOwner->hInstance,
1535 (LPVOID)hmenu ));
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001536 if (!pTopPopupWnd)
1537 {
1538 WIN_ReleaseWndPtr(wndOwner);
1539 return FALSE;
1540 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001541 menu->hWnd = pTopPopupWnd->hwndSelf;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001542 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001543 }
1544 else
1545 if( uSubPWndLevel )
1546 {
1547 /* create a new window for the submenu */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001548
Alexandre Julliarda3960291999-02-26 11:11:13 +00001549 menu->hWnd = CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001550 WS_POPUP, x, y, width, height,
Juergen Schmied78513941999-04-18 14:40:32 +00001551 hwndOwner, 0, wndOwner->hInstance,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001552 (LPVOID)hmenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001553 if( !menu->hWnd )
1554 {
1555 WIN_ReleaseWndPtr(wndOwner);
1556 return FALSE;
1557 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001558 }
1559 else /* top level popup menu window already exists */
1560 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001561 WND *pTPWnd = MENU_GetTopPopupWnd();
1562 menu->hWnd = pTPWnd->hwndSelf;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001563
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001564 MENU_PatchResidentPopup( 0, wndOwner );
Juergen Schmied78513941999-04-18 14:40:32 +00001565 SendMessageA( pTPWnd->hwndSelf, MM_SETMENUHANDLE, (WPARAM16)hmenu, 0L);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001566
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001567 /* adjust its size */
1568
Alexandre Julliarda3960291999-02-26 11:11:13 +00001569 SetWindowPos( menu->hWnd, 0, x, y, width, height,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001570 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001571 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001572 }
1573
1574 uSubPWndLevel++; /* menu level counter */
1575
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001576 /* Display the window */
1577
Alexandre Julliarda3960291999-02-26 11:11:13 +00001578 SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001579 SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001580 UpdateWindow( menu->hWnd );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001581 WIN_ReleaseWndPtr(wndOwner);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001582 return TRUE;
1583 }
1584 return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001585}
1586
1587
1588/***********************************************************************
1589 * MENU_SelectItem
1590 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001591static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
1592 BOOL sendMenuSelect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001593{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001594 LPPOPUPMENU lppop;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001595 HDC hdc;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001596
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001597 TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
Juergen Schmied78513941999-04-18 14:40:32 +00001598
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001599 lppop = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001600 if (!lppop->nItems) return;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001601
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001602 if ((wIndex != NO_SELECTED_ITEM) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001603 (lppop->items[wIndex].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001604 wIndex = NO_SELECTED_ITEM;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001605
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001606 if (lppop->FocusedItem == wIndex) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001607 if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
1608 else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
Alexandre Julliardf7207251994-07-23 07:57:48 +00001609
Juergen Schmied78513941999-04-18 14:40:32 +00001610 SelectObject( hdc, hMenuFont);
1611
Alexandre Julliardf7207251994-07-23 07:57:48 +00001612 /* Clear previous highlighted item */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001613 if (lppop->FocusedItem != NO_SELECTED_ITEM)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001614 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001615 lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
Juergen Schmied78513941999-04-18 14:40:32 +00001616 MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001617 lppop->Height, !(lppop->wFlags & MF_POPUP),
1618 ODA_SELECT );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001619 }
1620
1621 /* Highlight new item (if any) */
1622 lppop->FocusedItem = wIndex;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001623 if (lppop->FocusedItem != NO_SELECTED_ITEM)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001624 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001625 lppop->items[lppop->FocusedItem].fState |= MF_HILITE;
Juergen Schmied78513941999-04-18 14:40:32 +00001626 MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc, &lppop->items[lppop->FocusedItem],
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001627 lppop->Height, !(lppop->wFlags & MF_POPUP),
1628 ODA_SELECT );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001629 if (sendMenuSelect)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001630 {
1631 MENUITEM *ip = &lppop->items[lppop->FocusedItem];
Juergen Schmied78513941999-04-18 14:40:32 +00001632 SendMessageA( hwndOwner, WM_MENUSELECT,
1633 MAKELONG(ip->wID,ip->fType | (ip->fState | MF_MOUSESELECT)), hmenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001634 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001635 }
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001636 else if (sendMenuSelect) {
Juergen Schmied78513941999-04-18 14:40:32 +00001637 SendMessageA( hwndOwner, WM_MENUSELECT,
1638 MAKELONG( hmenu, lppop->wFlags | MF_MOUSESELECT), hmenu );
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001639 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001640 ReleaseDC( lppop->hWnd, hdc );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001641}
1642
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001643
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001644/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001645 * MENU_MoveSelection
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001646 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001647 * Moves currently selected item according to the offset parameter.
1648 * If there is no selection then it should select the last item if
1649 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001650 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001651static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001652{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001653 INT i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001654 POPUPMENU *menu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001655
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001656 TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner, hmenu, offset);
Juergen Schmied466a6521999-05-02 11:21:08 +00001657
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001658 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001659 if (!menu->items) return;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001660
1661 if ( menu->FocusedItem != NO_SELECTED_ITEM )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001662 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001663 if( menu->nItems == 1 ) return; else
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001664 for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
1665 ; i += offset)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001666 if (!(menu->items[i].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001667 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001668 MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001669 return;
1670 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001671 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001672
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001673 for ( i = (offset > 0) ? 0 : menu->nItems - 1;
1674 i >= 0 && i < menu->nItems ; i += offset)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001675 if (!(menu->items[i].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001676 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001677 MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001678 return;
1679 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001680}
1681
1682
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001683/**********************************************************************
1684 * MENU_SetItemData
1685 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001686 * Set an item flags, id and text ptr. Called by InsertMenu() and
1687 * ModifyMenu().
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001688 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001689static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001690 LPCSTR str )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001691{
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001692 LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001693
Alexandre Julliard03468f71998-02-15 19:40:49 +00001694 debug_print_menuitem("MENU_SetItemData from: ", item, "");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001695
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001696 if (IS_STRING_ITEM(flags))
1697 {
Alexandre Julliard491502b1997-11-01 19:08:16 +00001698 if (!str || !*str)
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001699 {
1700 flags |= MF_SEPARATOR;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001701 item->text = NULL;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001702 }
1703 else
1704 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001705 LPSTR text;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001706 /* Item beginning with a backspace is a help item */
1707 if (*str == '\b')
1708 {
1709 flags |= MF_HELP;
1710 str++;
1711 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001712 if (!(text = HEAP_strdupA( SystemHeap, 0, str ))) return FALSE;
1713 item->text = text;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001714 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001715 }
Juergen Schmied78513941999-04-18 14:40:32 +00001716 else if (IS_BITMAP_ITEM(flags))
1717 item->text = (LPSTR)(HBITMAP)LOWORD(str);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001718 else item->text = NULL;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001719
Alexandre Julliarda845b881998-06-01 10:44:35 +00001720 if (flags & MF_OWNERDRAW)
1721 item->dwItemData = (DWORD)str;
1722 else
1723 item->dwItemData = 0;
1724
Alexandre Julliard02e90081998-01-04 17:49:09 +00001725 if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00001726 DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001727
1728 if (flags & MF_POPUP)
1729 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001730 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)id);
1731 if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001732 else
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001733 {
1734 item->wID = 0;
1735 item->hSubMenu = 0;
1736 item->fType = 0;
1737 item->fState = 0;
1738 return FALSE;
1739 }
Alexandre Julliard02e90081998-01-04 17:49:09 +00001740 }
1741
1742 item->wID = id;
1743 if (flags & MF_POPUP)
1744 item->hSubMenu = id;
1745
1746 if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
1747 flags |= MF_POPUP; /* keep popup */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001748
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001749 item->fType = flags & TYPE_MASK;
1750 item->fState = (flags & STATE_MASK) &
1751 ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001752
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001753
1754 /* Don't call SetRectEmpty here! */
1755
1756
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001757 if (prevText) HeapFree( SystemHeap, 0, prevText );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001758
Alexandre Julliard03468f71998-02-15 19:40:49 +00001759 debug_print_menuitem("MENU_SetItemData to : ", item, "");
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001760 return TRUE;
1761}
1762
1763
1764/**********************************************************************
1765 * MENU_InsertItem
1766 *
1767 * Insert a new item into a menu.
1768 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001769static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001770{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001771 MENUITEM *newItems;
1772 POPUPMENU *menu;
1773
1774 if (!(menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu)))
1775 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001776 WARN("%04x not a menu handle\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001777 hMenu );
1778 return NULL;
1779 }
1780
1781 /* Find where to insert new item */
1782
1783 if ((flags & MF_BYPOSITION) &&
Alexandre Julliarda3960291999-02-26 11:11:13 +00001784 ((pos == (UINT)-1) || (pos == menu->nItems)))
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001785 {
1786 /* Special case: append to menu */
1787 /* Some programs specify the menu length to do that */
1788 pos = menu->nItems;
1789 }
1790 else
1791 {
1792 if (!MENU_FindItem( &hMenu, &pos, flags ))
1793 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001794 WARN("item %x not found\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001795 pos );
1796 return NULL;
1797 }
1798 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
1799 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001800 WARN("%04x not a menu handle\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001801 hMenu);
1802 return NULL;
1803 }
1804 }
1805
1806 /* Create new items array */
1807
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001808 newItems = HeapAlloc( SystemHeap, 0, sizeof(MENUITEM) * (menu->nItems+1) );
1809 if (!newItems)
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001810 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001811 WARN("allocation failed\n" );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001812 return NULL;
1813 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001814 if (menu->nItems > 0)
1815 {
1816 /* Copy the old array into the new */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001817 if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
1818 if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001819 (menu->nItems-pos)*sizeof(MENUITEM) );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001820 HeapFree( SystemHeap, 0, menu->items );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001821 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001822 menu->items = newItems;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001823 menu->nItems++;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001824 memset( &newItems[pos], 0, sizeof(*newItems) );
Gerard Patel6df06941999-09-28 13:05:54 +00001825 menu->Height = 0; /* force size recalculate */
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001826 return &newItems[pos];
1827}
1828
1829
1830/**********************************************************************
1831 * MENU_ParseResource
1832 *
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001833 * Parse a standard menu resource and add items to the menu.
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001834 * Return a pointer to the end of the resource.
1835 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001836static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001837{
1838 WORD flags, id = 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001839 LPCSTR str;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001840
1841 do
1842 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001843 flags = GET_WORD(res);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001844 res += sizeof(WORD);
1845 if (!(flags & MF_POPUP))
1846 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001847 id = GET_WORD(res);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001848 res += sizeof(WORD);
1849 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001850 if (!IS_STRING_ITEM(flags))
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001851 ERR("not a string item %04x\n", flags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001852 str = res;
1853 if (!unicode) res += strlen(str) + 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001854 else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001855 if (flags & MF_POPUP)
1856 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001857 HMENU hSubMenu = CreatePopupMenu();
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001858 if (!hSubMenu) return NULL;
1859 if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
1860 return NULL;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001861 if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
1862 else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001863 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001864 else /* Not a popup */
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001865 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001866 if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1867 else AppendMenuW( hMenu, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001868 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001869 }
1870 } while (!(flags & MF_END));
1871 return res;
1872}
1873
1874
Alexandre Julliard641ee761997-08-04 16:34:36 +00001875/**********************************************************************
1876 * MENUEX_ParseResource
1877 *
1878 * Parse an extended menu resource and add items to the menu.
1879 * Return a pointer to the end of the resource.
1880 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001881static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
Alexandre Julliard641ee761997-08-04 16:34:36 +00001882{
Alexandre Julliard641ee761997-08-04 16:34:36 +00001883 WORD resinfo;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001884 do {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001885 MENUITEMINFOW mii;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001886
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001887 mii.cbSize = sizeof(mii);
1888 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
1889 mii.fType = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001890 res += sizeof(DWORD);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001891 mii.fState = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001892 res += sizeof(DWORD);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001893 mii.wID = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001894 res += sizeof(DWORD);
1895 resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte. */
1896 res += sizeof(WORD);
1897 /* Align the text on a word boundary. */
1898 res += (~((int)res - 1)) & 1;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001899 mii.dwTypeData = (LPWSTR) res;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001900 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001901 /* Align the following fields on a dword boundary. */
1902 res += (~((int)res - 1)) & 3;
1903
1904 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1905 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001906 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
1907 0, mii.dwTypeData);
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001908 TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001909 mii.fType, mii.fState, mii.wID, resinfo, newstr);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001910 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001911 }
1912
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001913 if (resinfo & 1) { /* Pop-up? */
Marcus Meissnerde43ef41999-02-28 19:56:59 +00001914 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
Alexandre Julliard641ee761997-08-04 16:34:36 +00001915 res += sizeof(DWORD);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001916 mii.hSubMenu = CreatePopupMenu();
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001917 if (!mii.hSubMenu)
1918 return NULL;
1919 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001920 DestroyMenu(mii.hSubMenu);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001921 return NULL;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001922 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001923 mii.fMask |= MIIM_SUBMENU;
1924 mii.fType |= MF_POPUP;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001925 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001926 InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001927 } while (!(resinfo & MF_END));
1928 return res;
1929}
1930
1931
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001932/***********************************************************************
1933 * MENU_GetSubPopup
1934 *
1935 * Return the handle of the selected sub-popup menu (if any).
1936 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001937static HMENU MENU_GetSubPopup( HMENU hmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001938{
1939 POPUPMENU *menu;
1940 MENUITEM *item;
1941
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001942 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001943
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001944 if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001945
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001946 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001947 if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
1948 return item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001949 return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001950}
1951
1952
1953/***********************************************************************
1954 * MENU_HideSubPopups
1955 *
1956 * Hide the sub-popup menus of this menu.
1957 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001958static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
1959 BOOL sendMenuSelect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001960{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001961 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR( hmenu );;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001962
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001963 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
Juergen Schmied466a6521999-05-02 11:21:08 +00001964
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001965 if (menu && uSubPWndLevel)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001966 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001967 HMENU hsubmenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001968 POPUPMENU *submenu;
1969 MENUITEM *item;
1970
1971 if (menu->FocusedItem != NO_SELECTED_ITEM)
1972 {
1973 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001974 if (!(item->fType & MF_POPUP) ||
1975 !(item->fState & MF_MOUSESELECT)) return;
1976 item->fState &= ~MF_MOUSESELECT;
1977 hsubmenu = item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001978 } else return;
1979
1980 submenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hsubmenu );
1981 MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
1982 MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect );
1983
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001984 if (submenu->hWnd == MENU_GetTopPopupWnd()->hwndSelf )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001985 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001986 ShowWindow( submenu->hWnd, SW_HIDE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001987 uSubPWndLevel = 0;
1988 }
1989 else
1990 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001991 DestroyWindow( submenu->hWnd );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001992 submenu->hWnd = 0;
1993 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001994 MENU_ReleaseTopPopupWnd();
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001995 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001996}
1997
1998
1999/***********************************************************************
2000 * MENU_ShowSubPopup
2001 *
2002 * Display the sub-menu of the selected item of this menu.
2003 * Return the handle of the submenu, or hmenu if no submenu to display.
2004 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002005static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002006 BOOL selectFirst, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002007{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002008 RECT rect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002009 POPUPMENU *menu;
2010 MENUITEM *item;
2011 WND *wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002012 HDC hdc;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002013
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002014 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
Juergen Schmied466a6521999-05-02 11:21:08 +00002015
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002016 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return hmenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002017
2018 if (!(wndPtr = WIN_FindWndPtr( menu->hWnd )) ||
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002019 (menu->FocusedItem == NO_SELECTED_ITEM))
2020 {
2021 WIN_ReleaseWndPtr(wndPtr);
2022 return hmenu;
2023 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002024
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002025 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002026 if (!(item->fType & MF_POPUP) ||
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002027 (item->fState & (MF_GRAYED | MF_DISABLED)))
2028 {
2029 WIN_ReleaseWndPtr(wndPtr);
2030 return hmenu;
2031 }
Alexandre Julliard02e90081998-01-04 17:49:09 +00002032
2033 /* message must be send before using item,
2034 because nearly everything may by changed by the application ! */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002035
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002036 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2037 if (!(wFlags & TPM_NONOTIFY))
2038 SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
Alexandre Julliard02e90081998-01-04 17:49:09 +00002039 MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
2040
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002041 item = &menu->items[menu->FocusedItem];
2042 rect = item->rect;
2043
Alexandre Julliard02e90081998-01-04 17:49:09 +00002044 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2045 if (!(item->fState & MF_HILITE))
2046 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002047 if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
2048 else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
Juergen Schmied78513941999-04-18 14:40:32 +00002049
2050 SelectObject( hdc, hMenuFont);
2051
Alexandre Julliard02e90081998-01-04 17:49:09 +00002052 item->fState |= MF_HILITE;
Juergen Schmied78513941999-04-18 14:40:32 +00002053 MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002054 ReleaseDC( menu->hWnd, hdc );
Alexandre Julliard02e90081998-01-04 17:49:09 +00002055 }
2056 if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
2057 item->rect = rect;
2058
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002059 item->fState |= MF_MOUSESELECT;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002060
2061 if (IS_SYSTEM_MENU(menu))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002062 {
Patrik Stridvall4bf33541999-06-12 14:52:15 +00002063 MENU_InitSysMenuPopup(item->hSubMenu, wndPtr->dwStyle, GetClassLongA(wndPtr->hwndSelf, GCL_STYLE));
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002064
2065 NC_GetSysPopupPos( wndPtr, &rect );
2066 rect.top = rect.bottom;
Marcus Meissnerddca3151999-05-22 11:33:23 +00002067 rect.right = GetSystemMetrics(SM_CXSIZE);
2068 rect.bottom = GetSystemMetrics(SM_CYSIZE);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002069 }
2070 else
2071 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002072 if (menu->wFlags & MF_POPUP)
2073 {
2074 rect.left = wndPtr->rectWindow.left + item->rect.right-arrow_bitmap_width;
2075 rect.top = wndPtr->rectWindow.top + item->rect.top;
2076 rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
2077 rect.bottom = item->rect.top - item->rect.bottom;
2078 }
2079 else
2080 {
2081 rect.left = wndPtr->rectWindow.left + item->rect.left;
2082 rect.top = wndPtr->rectWindow.top + item->rect.bottom;
2083 rect.right = item->rect.right - item->rect.left;
2084 rect.bottom = item->rect.bottom - item->rect.top;
2085 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002086 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002087
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002088 MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002089 rect.left, rect.top, rect.right, rect.bottom );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002090 if (selectFirst)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002091 MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002092 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002093 return item->hSubMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002094}
2095
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002096/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002097 * MENU_PtMenu
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002098 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002099 * Walks menu chain trying to find a menu pt maps to.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002100 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002101static HMENU MENU_PtMenu( HMENU hMenu, POINT16 pt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002102{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002103 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002104 register UINT ht = menu->FocusedItem;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002105
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002106 /* try subpopup first (if any) */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002107 ht = (ht != NO_SELECTED_ITEM &&
2108 (menu->items[ht].fType & MF_POPUP) &&
2109 (menu->items[ht].fState & MF_MOUSESELECT))
Alexandre Julliarda3960291999-02-26 11:11:13 +00002110 ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002111
2112 if( !ht ) /* check the current window (avoiding WM_HITTEST) */
2113 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002114 ht = (UINT)NC_HandleNCHitTest( menu->hWnd, pt );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002115 if( menu->wFlags & MF_POPUP )
Alexandre Julliarda3960291999-02-26 11:11:13 +00002116 ht = (ht != (UINT)HTNOWHERE &&
2117 ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002118 else
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002119 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002120 WND* wndPtr = WIN_FindWndPtr(menu->hWnd);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002121
Alexandre Julliarda3960291999-02-26 11:11:13 +00002122 ht = ( ht == HTSYSMENU ) ? (UINT)(wndPtr->hSysMenu)
2123 : ( ht == HTMENU ) ? (UINT)(wndPtr->wIDmenu) : 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002124 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002125 }
2126 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002127 return (HMENU)ht;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002128}
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002129
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002130/***********************************************************************
2131 * MENU_ExecFocusedItem
2132 *
2133 * Execute a menu item (for instance when user pressed Enter).
Karl Lessard13409b31999-09-28 16:24:58 +00002134 * Return the wID of the executed item. Otherwise, -1 indicating
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002135 * that no menu item wase executed;
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002136 * Have to receive the flags for the TrackPopupMenu options to avoid
2137 * sending unwanted message.
2138 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002139 */
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002140static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002141{
2142 MENUITEM *item;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002143 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
Juergen Schmied466a6521999-05-02 11:21:08 +00002144
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002145 TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
Juergen Schmied466a6521999-05-02 11:21:08 +00002146
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002147 if (!menu || !menu->nItems ||
Karl Lessard13409b31999-09-28 16:24:58 +00002148 (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002149
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002150 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002151
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002152 TRACE("%08x %08x %08x\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002153 hMenu, item->wID, item->hSubMenu);
2154
2155 if (!(item->fType & MF_POPUP))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002156 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002157 if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002158 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002159 /* If TPM_RETURNCMD is set you return the id, but
2160 do not send a message to the owner */
2161 if(!(wFlags & TPM_RETURNCMD))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002162 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002163 if( menu->wFlags & MF_SYSMENU )
2164 PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
2165 MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
2166 else
2167 PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002168 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002169 return item->wID;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002170 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002171 }
2172 else
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002173 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags);
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002174
Karl Lessard13409b31999-09-28 16:24:58 +00002175 return -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002176}
2177
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002178/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002179 * MENU_SwitchTracking
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002180 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002181 * Helper function for menu navigation routines.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002182 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002183static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002184{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002185 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2186 POPUPMENU *topmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002187
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002188 TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
Juergen Schmied466a6521999-05-02 11:21:08 +00002189
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002190 if( pmt->hTopMenu != hPtMenu &&
2191 !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002192 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002193 /* both are top level menus (system and menu-bar) */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002194 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2195 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE );
2196 pmt->hTopMenu = hPtMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002197 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002198 else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
2199 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002200}
2201
2202
2203/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002204 * MENU_ButtonDown
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002205 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002206 * Return TRUE if we can go on with menu tracking.
2207 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002208static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002209{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002210 TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
Juergen Schmied466a6521999-05-02 11:21:08 +00002211
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002212 if (hPtMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002213 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002214 UINT id = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002215 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2216 MENUITEM *item;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002217
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002218 if( IS_SYSTEM_MENU(ptmenu) )
2219 item = ptmenu->items;
2220 else
2221 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002222
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002223 if( item )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002224 {
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002225 if( ptmenu->FocusedItem != id )
2226 MENU_SwitchTracking( pmt, hPtMenu, id );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002227
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002228 /* If the popup menu is not already "popped" */
2229 if(!(item->fState & MF_MOUSESELECT ))
Pascal Lessard07c447f1999-09-19 12:03:25 +00002230 {
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002231 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE, wFlags );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002232
Pascal Lessard07c447f1999-09-19 12:03:25 +00002233 /* In win31, a newly popped menu always remain opened for the next buttonup */
2234 if(TWEAK_WineLook == WIN31_LOOK)
2235 ptmenu->bTimeToHide = FALSE;
2236 }
2237
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002238 return TRUE;
2239 }
Pascal Lessard445c9101999-09-20 18:27:14 +00002240 /* Else the click was on the menu bar, finish the tracking */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002241 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002242 return FALSE;
2243}
2244
2245/***********************************************************************
2246 * MENU_ButtonUp
2247 *
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002248 * Return the value of MENU_ExecFocusedItem if
2249 * the selected item was not a popup. Else open the popup.
Karl Lessard13409b31999-09-28 16:24:58 +00002250 * A -1 return value indicates that we go on with menu tracking.
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002251 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002252 */
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002253static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002254{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002255 TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
Juergen Schmied466a6521999-05-02 11:21:08 +00002256
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002257 if (hPtMenu)
2258 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002259 UINT id = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002260 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2261 MENUITEM *item;
2262
2263 if( IS_SYSTEM_MENU(ptmenu) )
2264 item = ptmenu->items;
2265 else
2266 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2267
Alexandre Julliard491502b1997-11-01 19:08:16 +00002268 if( item && (ptmenu->FocusedItem == id ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002269 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002270 if( !(item->fType & MF_POPUP) )
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002271 return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002272
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002273 /* If we are dealing with the top-level menu and that this */
2274 /* is a click on an already "poppped" item */
2275 /* Stop the menu tracking and close the opened submenus */
2276 if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
Karl Lessard13409b31999-09-28 16:24:58 +00002277 return 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002278 }
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002279 ptmenu->bTimeToHide = TRUE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002280 }
Karl Lessard13409b31999-09-28 16:24:58 +00002281 return -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002282}
2283
2284
2285/***********************************************************************
2286 * MENU_MouseMove
2287 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002288 * Return TRUE if we can go on with menu tracking.
2289 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002290static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002291{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002292 UINT id = NO_SELECTED_ITEM;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002293 POPUPMENU *ptmenu = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002294
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002295 if( hPtMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002296 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002297 ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2298 if( IS_SYSTEM_MENU(ptmenu) )
2299 id = 0;
2300 else
2301 MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2302 }
2303
2304 if( id == NO_SELECTED_ITEM )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002305 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002306 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2307 NO_SELECTED_ITEM, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002308 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002309 else if( ptmenu->FocusedItem != id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002310 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002311 MENU_SwitchTracking( pmt, hPtMenu, id );
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002312 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002313 }
2314 return TRUE;
2315}
2316
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002317
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002318/***********************************************************************
2319 * MENU_DoNextMenu
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002320 *
2321 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002322 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002323static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002324{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002325 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002326
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002327 if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
2328 (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
2329 {
2330 WND* wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002331 HMENU hNewMenu;
2332 HWND hNewWnd;
2333 UINT id = 0;
Juergen Schmied78513941999-04-18 14:40:32 +00002334 LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002335 (IS_SYSTEM_MENU(menu)) ? GetSubMenu16(pmt->hTopMenu,0) : pmt->hTopMenu );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002336
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002337 TRACE("%04x [%04x] -> %04x [%04x]\n",
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002338 (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002339
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002340 if( l == 0 )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002341 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002342 wndPtr = WIN_FindWndPtr(pmt->hOwnerWnd);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002343
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002344 hNewWnd = pmt->hOwnerWnd;
2345 if( IS_SYSTEM_MENU(menu) )
2346 {
2347 /* switch to the menu bar */
2348
2349 if( wndPtr->dwStyle & WS_CHILD || !wndPtr->wIDmenu )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002350 {
2351 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002352 return FALSE;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002353 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002354
2355 hNewMenu = wndPtr->wIDmenu;
2356 if( vk == VK_LEFT )
2357 {
2358 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hNewMenu );
2359 id = menu->nItems - 1;
2360 }
2361 }
2362 else if( wndPtr->dwStyle & WS_SYSMENU )
2363 {
2364 /* switch to the system menu */
2365 hNewMenu = wndPtr->hSysMenu;
2366 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002367 else
2368 {
2369 WIN_ReleaseWndPtr(wndPtr);
2370 return FALSE;
2371 }
2372 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002373 }
2374 else /* application returned a new menu to switch to */
2375 {
2376 hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
2377
Alexandre Julliarda3960291999-02-26 11:11:13 +00002378 if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002379 {
2380 wndPtr = WIN_FindWndPtr(hNewWnd);
2381
2382 if( wndPtr->dwStyle & WS_SYSMENU &&
2383 GetSubMenu16(wndPtr->hSysMenu, 0) == hNewMenu )
2384 {
2385 /* get the real system menu */
2386 hNewMenu = wndPtr->hSysMenu;
2387 }
2388 else if( wndPtr->dwStyle & WS_CHILD || wndPtr->wIDmenu != hNewMenu )
2389 {
2390 /* FIXME: Not sure what to do here, perhaps,
2391 * try to track hNewMenu as a popup? */
2392
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002393 TRACE(" -- got confused.\n");
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002394 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002395 return FALSE;
2396 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002397 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002398 }
2399 else return FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002400 }
2401
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002402 if( hNewMenu != pmt->hTopMenu )
2403 {
2404 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE );
2405 if( pmt->hCurrentMenu != pmt->hTopMenu )
2406 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2407 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002408
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002409 if( hNewWnd != pmt->hOwnerWnd )
2410 {
2411 ReleaseCapture();
2412 pmt->hOwnerWnd = hNewWnd;
2413 EVENT_Capture( pmt->hOwnerWnd, HTMENU );
2414 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002415
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002416 pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
2417 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002418
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002419 return TRUE;
2420 }
2421 return FALSE;
2422}
2423
2424/***********************************************************************
2425 * MENU_SuspendPopup
2426 *
2427 * The idea is not to show the popup if the next input message is
2428 * going to hide it anyway.
2429 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002430static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT16 uMsg )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002431{
Juergen Schmied78513941999-04-18 14:40:32 +00002432 MSG msg;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002433
2434 msg.hwnd = pmt->hOwnerWnd;
2435
Juergen Schmied78513941999-04-18 14:40:32 +00002436 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002437 pmt->trackFlags |= TF_SKIPREMOVE;
2438
2439 switch( uMsg )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002440 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002441 case WM_KEYDOWN:
Juergen Schmied78513941999-04-18 14:40:32 +00002442 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002443 if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
2444 {
Juergen Schmied78513941999-04-18 14:40:32 +00002445 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2446 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002447 if( msg.message == WM_KEYDOWN &&
2448 (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
2449 {
2450 pmt->trackFlags |= TF_SUSPENDPOPUP;
2451 return TRUE;
2452 }
2453 }
2454 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002455 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002456
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002457 /* failures go through this */
2458 pmt->trackFlags &= ~TF_SUSPENDPOPUP;
2459 return FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002460}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002461
2462/***********************************************************************
2463 * MENU_KeyLeft
2464 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002465 * Handle a VK_LEFT key event in a menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002466 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002467static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002468{
2469 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002470 HMENU hmenutmp, hmenuprev;
2471 UINT prevcol;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002472
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002473 hmenuprev = hmenutmp = pmt->hTopMenu;
2474 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenutmp );
2475
Alexandre Julliard641ee761997-08-04 16:34:36 +00002476 /* Try to move 1 column left (if possible) */
2477 if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
2478 NO_SELECTED_ITEM ) {
2479
2480 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2481 prevcol, TRUE );
2482 return;
2483 }
2484
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002485 /* close topmost popup */
2486 while (hmenutmp != pmt->hCurrentMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002487 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002488 hmenuprev = hmenutmp;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002489 hmenutmp = MENU_GetSubPopup( hmenuprev );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002490 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002491
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002492 MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
2493 pmt->hCurrentMenu = hmenuprev;
2494
2495 if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002496 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002497 /* move menu bar selection if no more popups are left */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002498
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002499 if( !MENU_DoNextMenu( pmt, VK_LEFT) )
2500 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002501
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002502 if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002503 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002504 /* A sublevel menu was displayed - display the next one
2505 * unless there is another displacement coming up */
2506
2507 if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002508 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2509 pmt->hTopMenu, TRUE, wFlags);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002510 }
2511 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002512}
2513
2514
2515/***********************************************************************
2516 * MENU_KeyRight
2517 *
2518 * Handle a VK_RIGHT key event in a menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002519 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002520static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002521{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002522 HMENU hmenutmp;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002523 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002524 UINT nextcol;
Alexandre Julliard641ee761997-08-04 16:34:36 +00002525
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002526 TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
Alexandre Julliard641ee761997-08-04 16:34:36 +00002527 pmt->hCurrentMenu,
2528 ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
2529 items[0].text,
2530 pmt->hTopMenu, menu->items[0].text );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002531
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002532 if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002533 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002534 /* If already displaying a popup, try to display sub-popup */
2535
2536 hmenutmp = pmt->hCurrentMenu;
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002537 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002538
2539 /* if subpopup was displayed then we are done */
2540 if (hmenutmp != pmt->hCurrentMenu) return;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002541 }
2542
Alexandre Julliard641ee761997-08-04 16:34:36 +00002543 /* Check to see if there's another column */
2544 if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
2545 NO_SELECTED_ITEM ) {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002546 TRACE("Going to %d.\n", nextcol );
Alexandre Julliard641ee761997-08-04 16:34:36 +00002547 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2548 nextcol, TRUE );
2549 return;
2550 }
2551
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002552 if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002553 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002554 if( pmt->hCurrentMenu != pmt->hTopMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002555 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002556 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2557 hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
2558 } else hmenutmp = 0;
2559
2560 /* try to move to the next item */
2561 if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
2562 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
2563
2564 if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2565 if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002566 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2567 pmt->hTopMenu, TRUE, wFlags);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002568 }
2569}
2570
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002571/***********************************************************************
2572 * MENU_TrackMenu
2573 *
2574 * Menu tracking code.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002575 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002576static INT MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
2577 HWND hwnd, const RECT *lprect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002578{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002579 MSG msg;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002580 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002581 BOOL fRemove;
Karl Lessard13409b31999-09-28 16:24:58 +00002582 INT executedMenuId = -1;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +00002583 MTRACKER mt;
Francis Beaudet7ed1af31999-08-15 16:58:03 +00002584 BOOL enterIdleSent = FALSE;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +00002585
2586 mt.trackFlags = 0;
2587 mt.hCurrentMenu = hmenu;
2588 mt.hTopMenu = hmenu;
2589 mt.hOwnerWnd = hwnd;
2590 mt.pt.x = x;
2591 mt.pt.y = y;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002592
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002593 TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00002594 hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
2595 (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
Juergen Schmied78513941999-04-18 14:40:32 +00002596
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002597 fEndMenu = FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002598 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002599
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002600 if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu, wFlags );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002601
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002602 EVENT_Capture( mt.hOwnerWnd, HTMENU );
2603
2604 while (!fEndMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002605 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002606 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2607 msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
2608
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002609 /* we have to keep the message in the queue until it's
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002610 * clear that menu loop is not over yet. */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002611
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002612 if (!MSG_InternalGetMessage( &msg, msg.hwnd, mt.hOwnerWnd,
Francis Beaudet7ed1af31999-08-15 16:58:03 +00002613 MSGF_MENU, PM_NOREMOVE, !enterIdleSent, &enterIdleSent )) break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002614
Alexandre Julliarda3960291999-02-26 11:11:13 +00002615 TranslateMessage( &msg );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002616 mt.pt = msg.pt;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +00002617
Francis Beaudet7ed1af31999-08-15 16:58:03 +00002618 if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
2619 enterIdleSent=FALSE;
2620
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002621 fRemove = FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002622 if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002623 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002624 /* Find a menu for this mouse event */
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002625 POINT16 pt16;
2626 CONV_POINT32TO16( &msg.pt, &pt16 );
2627 hmenu = MENU_PtMenu( mt.hTopMenu, pt16 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002628
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002629 switch(msg.message)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002630 {
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002631 /* no WM_NC... messages in captured state */
2632
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002633 case WM_RBUTTONDBLCLK:
2634 case WM_RBUTTONDOWN:
2635 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2636 /* fall through */
2637 case WM_LBUTTONDBLCLK:
2638 case WM_LBUTTONDOWN:
Karl Lessard4a0a7df1999-11-07 05:17:10 +00002639 /* If the message belongs to the menu, removes it from the queue */
2640 /* Else, end menu tracking */
2641 fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
2642 fEndMenu = !fRemove;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002643 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002644
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002645 case WM_RBUTTONUP:
2646 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2647 /* fall through */
2648 case WM_LBUTTONUP:
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002649 /* Check if a menu was selected by the mouse */
2650 if (hmenu)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002651 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002652 executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002653
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002654 /* End the loop if executedMenuId is an item ID */
Karl Lessard13409b31999-09-28 16:24:58 +00002655 /* or if the job was done (executedMenuId = 0). */
2656 fEndMenu = fRemove = (executedMenuId != -1);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002657 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002658 /* No menu was selected by the mouse */
2659 /* if the function was called by TrackPopupMenu, continue
2660 with the menu tracking. If not, stop it */
2661 else
2662 fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
2663
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002664 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002665
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002666 case WM_MOUSEMOVE:
Alexandre Julliard8da12c41999-01-17 16:55:11 +00002667 /* In win95 winelook, the selected menu item must be changed every time the
2668 mouse moves. In Win31 winelook, the mouse button has to be held down */
2669
2670 if ( (TWEAK_WineLook > WIN31_LOOK) ||
2671 ( (msg.wParam & MK_LBUTTON) ||
2672 ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
2673
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002674 fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
Alexandre Julliard8da12c41999-01-17 16:55:11 +00002675
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002676 } /* switch(msg.message) - mouse */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002677 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002678 else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002679 {
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002680 fRemove = TRUE; /* Keyboard messages are always removed */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002681 switch(msg.message)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002682 {
2683 case WM_KEYDOWN:
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002684 switch(msg.wParam)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002685 {
2686 case VK_HOME:
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002687 case VK_END:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002688 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
2689 NO_SELECTED_ITEM, FALSE );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002690 /* fall through */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002691 case VK_UP:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002692 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002693 (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002694 break;
2695
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002696 case VK_DOWN: /* If on menu bar, pull-down the menu */
2697
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002698 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2699 if (!(menu->wFlags & MF_POPUP))
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002700 mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002701 else /* otherwise try to move selection */
2702 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002703 break;
2704
2705 case VK_LEFT:
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002706 MENU_KeyLeft( &mt, wFlags );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002707 break;
2708
2709 case VK_RIGHT:
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002710 MENU_KeyRight( &mt, wFlags );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002711 break;
2712
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002713 case VK_ESCAPE:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002714 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002715 break;
2716
2717 default:
2718 break;
2719 }
2720 break; /* WM_KEYDOWN */
2721
2722 case WM_SYSKEYDOWN:
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002723 switch(msg.wParam)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002724 {
2725 case VK_MENU:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002726 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002727 break;
2728
2729 }
2730 break; /* WM_SYSKEYDOWN */
2731
2732 case WM_CHAR:
2733 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002734 UINT pos;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002735
Norman Stevensa83d0651998-10-12 07:25:35 +00002736 if (msg.wParam == '\r' || msg.wParam == ' ')
2737 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002738 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
Karl Lessard13409b31999-09-28 16:24:58 +00002739 fEndMenu = (executedMenuId != -1);
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002740
Norman Stevensa83d0651998-10-12 07:25:35 +00002741 break;
2742 }
2743
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002744 /* Hack to avoid control chars. */
2745 /* We will find a better way real soon... */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002746 if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002747
2748 pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002749 LOWORD(msg.wParam), FALSE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002750 if (pos == (UINT)-2) fEndMenu = TRUE;
2751 else if (pos == (UINT)-1) MessageBeep(0);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002752 else
2753 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002754 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos, TRUE );
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002755 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
Karl Lessard13409b31999-09-28 16:24:58 +00002756 fEndMenu = (executedMenuId != -1);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002757 }
2758 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002759 break;
2760 } /* switch(msg.message) - kbd */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002761 }
2762 else
2763 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002764 DispatchMessageA( &msg );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002765 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002766
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002767 if (!fEndMenu) fRemove = TRUE;
2768
2769 /* finally remove message from the queue */
2770
2771 if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00002772 PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002773 else mt.trackFlags &= ~TF_SKIPREMOVE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002774 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002775
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002776 ReleaseCapture();
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00002777
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002778 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hTopMenu );
2779
Alexandre Julliarda3960291999-02-26 11:11:13 +00002780 if( IsWindow( mt.hOwnerWnd ) )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002781 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002782 MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
2783
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002784 if (menu && menu->wFlags & MF_POPUP)
2785 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002786 ShowWindow( menu->hWnd, SW_HIDE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002787 uSubPWndLevel = 0;
2788 }
2789 MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE );
Dennis Björklund4352c7a1999-09-19 18:28:35 +00002790 SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002791 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002792
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002793 /* Reset the variable for hiding menu */
2794 menu->bTimeToHide = FALSE;
2795
Juergen Schmied371c4201999-10-13 12:27:44 +00002796 /* The return value is only used by TrackPopupMenu */
2797 return ((executedMenuId != -1) ? executedMenuId : 0);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002798}
2799
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002800/***********************************************************************
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002801 * MENU_InitTracking
2802 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002803static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002804{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002805 TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00002806
Alexandre Julliarda3960291999-02-26 11:11:13 +00002807 HideCaret(0);
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002808
2809 /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
2810 if (!(wFlags & TPM_NONOTIFY))
2811 SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
2812
Juergen Schmied78513941999-04-18 14:40:32 +00002813 SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002814
2815 if (!(wFlags & TPM_NONOTIFY))
2816 SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
2817
Juergen Schmied78513941999-04-18 14:40:32 +00002818 return TRUE;
2819}
2820/***********************************************************************
2821 * MENU_ExitTracking
2822 */
2823static BOOL MENU_ExitTracking(HWND hWnd)
2824{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002825 TRACE("hwnd=0x%04x\n", hWnd);
Juergen Schmied78513941999-04-18 14:40:32 +00002826
2827 SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
2828 ShowCaret(0);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002829 return TRUE;
2830}
2831
2832/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002833 * MENU_TrackMouseMenuBar
2834 *
2835 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2836 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002837void MENU_TrackMouseMenuBar( WND* wndPtr, INT ht, POINT pt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002838{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002839 HWND hWnd = wndPtr->hwndSelf;
2840 HMENU hMenu = (ht == HTSYSMENU) ? wndPtr->hSysMenu : wndPtr->wIDmenu;
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002841 UINT wFlags = TPM_ENTERIDLEEX | TPM_BUTTONDOWN | TPM_LEFTALIGN | TPM_LEFTBUTTON;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002842
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002843 TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
Juergen Schmied78513941999-04-18 14:40:32 +00002844
Alexandre Julliarda3960291999-02-26 11:11:13 +00002845 if (IsMenu(hMenu))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002846 {
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002847 MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
2848 MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd, NULL );
Juergen Schmied78513941999-04-18 14:40:32 +00002849 MENU_ExitTracking(hWnd);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002850 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002851}
2852
2853
2854/***********************************************************************
2855 * MENU_TrackKbdMenuBar
2856 *
2857 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2858 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002859void MENU_TrackKbdMenuBar( WND* wndPtr, UINT wParam, INT vkey)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002860{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002861 UINT uItem = NO_SELECTED_ITEM;
2862 HMENU hTrackMenu;
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002863 UINT wFlags = TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002864
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002865 /* find window that has a menu */
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002866
Pierre Mageau891d4d21999-10-23 20:05:04 +00002867 while( wndPtr->dwStyle & WS_CHILD)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002868 if( !(wndPtr = wndPtr->parent) ) return;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002869
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002870 /* check if we have to track a system menu */
2871
2872 if( (wndPtr->dwStyle & (WS_CHILD | WS_MINIMIZE)) ||
2873 !wndPtr->wIDmenu || vkey == VK_SPACE )
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002874 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002875 if( !(wndPtr->dwStyle & WS_SYSMENU) ) return;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002876 hTrackMenu = wndPtr->hSysMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002877 uItem = 0;
2878 wParam |= HTSYSMENU; /* prevent item lookup */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002879 }
2880 else
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002881 hTrackMenu = wndPtr->wIDmenu;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002882
Alexandre Julliarda3960291999-02-26 11:11:13 +00002883 if (IsMenu( hTrackMenu ))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002884 {
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002885 MENU_InitTracking( wndPtr->hwndSelf, hTrackMenu, FALSE, wFlags );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002886
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002887 if( vkey && vkey != VK_SPACE )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002888 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002889 uItem = MENU_FindItemByKey( wndPtr->hwndSelf, hTrackMenu,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002890 vkey, (wParam & HTSYSMENU) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002891 if( uItem >= (UINT)(-2) )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002892 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002893 if( uItem == (UINT)(-1) ) MessageBeep(0);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002894 hTrackMenu = 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002895 }
2896 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002897
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002898 if( hTrackMenu )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002899 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002900 MENU_SelectItem( wndPtr->hwndSelf, hTrackMenu, uItem, TRUE );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002901
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002902 if( uItem == NO_SELECTED_ITEM )
2903 MENU_MoveSelection( wndPtr->hwndSelf, hTrackMenu, ITEM_NEXT );
2904 else if( vkey )
Juergen Schmied78513941999-04-18 14:40:32 +00002905 PostMessageA( wndPtr->hwndSelf, WM_KEYDOWN, VK_DOWN, 0L );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002906
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002907 MENU_TrackMenu( hTrackMenu, wFlags, 0, 0, wndPtr->hwndSelf, NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002908 }
Juergen Schmied78513941999-04-18 14:40:32 +00002909
2910 MENU_ExitTracking (wndPtr->hwndSelf);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002911 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002912}
2913
2914
2915/**********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002916 * TrackPopupMenu16 (USER.416)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002917 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002918BOOL16 WINAPI TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
2919 INT16 nReserved, HWND16 hWnd, const RECT16 *lpRect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002920{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002921 RECT r;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002922 if (lpRect)
2923 CONV_RECT16TO32( lpRect, &r );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002924 return TrackPopupMenu( hMenu, wFlags, x, y, nReserved, hWnd,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002925 lpRect ? &r : NULL );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002926}
2927
2928
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002929/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00002930 * TrackPopupMenu (USER32.549)
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002931 *
2932 * Like the win32 API, the function return the command ID only if the
2933 * flag TPM_RETURNCMD is on.
2934 *
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002935 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002936BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
2937 INT nReserved, HWND hWnd, const RECT *lpRect )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002938{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002939 BOOL ret = FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002940
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002941 MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
2942
2943 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2944 if (!(wFlags & TPM_NONOTIFY))
2945 SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
2946
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002947 if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002948 ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
Juergen Schmied78513941999-04-18 14:40:32 +00002949 MENU_ExitTracking(hWnd);
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002950
2951 if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
2952 ret = 1;
2953
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002954 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002955}
2956
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002957/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00002958 * TrackPopupMenuEx (USER32.550)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002959 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002960BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
2961 HWND hWnd, LPTPMPARAMS lpTpm )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002962{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002963 FIXME("not fully implemented\n" );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002964 return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002965 lpTpm ? &lpTpm->rcExclude : NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002966}
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002967
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002968/***********************************************************************
2969 * PopupMenuWndProc
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002970 *
2971 * NOTE: Windows has totally different (and undocumented) popup wndproc.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002972 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002973LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002974 LPARAM lParam )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002975{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002976 WND* wndPtr = WIN_FindWndPtr(hwnd);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002977 LRESULT retvalue;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002978
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002979 TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
Juergen Schmied78513941999-04-18 14:40:32 +00002980 hwnd, message, wParam, lParam);
2981
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002982 switch(message)
2983 {
2984 case WM_CREATE:
2985 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002986 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
2987 SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002988 retvalue = 0;
2989 goto END;
Alexandre Julliardf7207251994-07-23 07:57:48 +00002990 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +00002991
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002992 case WM_MOUSEACTIVATE: /* We don't want to be activated */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002993 retvalue = MA_NOACTIVATE;
2994 goto END;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00002995
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002996 case WM_PAINT:
2997 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002998 PAINTSTRUCT ps;
2999 BeginPaint( hwnd, &ps );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003000 MENU_DrawPopupMenu( hwnd, ps.hdc,
Alexandre Julliarda3960291999-02-26 11:11:13 +00003001 (HMENU)GetWindowLongA( hwnd, 0 ) );
3002 EndPaint( hwnd, &ps );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003003 retvalue = 0;
3004 goto END;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003005 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003006 case WM_ERASEBKGND:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003007 retvalue = 1;
3008 goto END;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003009
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003010 case WM_DESTROY:
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003011
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003012 /* zero out global pointer in case resident popup window
3013 * was somehow destroyed. */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003014
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003015 if(MENU_GetTopPopupWnd() )
Alexandre Julliard54c27111998-03-29 19:44:57 +00003016 {
3017 if( hwnd == pTopPopupWnd->hwndSelf )
3018 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003019 ERR("resident popup destroyed!\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003020
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003021 MENU_DestroyTopPopupWnd();
Alexandre Julliard54c27111998-03-29 19:44:57 +00003022 uSubPWndLevel = 0;
3023 }
3024 else
3025 uSubPWndLevel--;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003026 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003027 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003028 break;
3029
3030 case WM_SHOWWINDOW:
3031
3032 if( wParam )
3033 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003034 if( !(*(HMENU*)wndPtr->wExtra) )
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003035 ERR("no menu to display\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003036 }
3037 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00003038 *(HMENU*)wndPtr->wExtra = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003039 break;
3040
3041 case MM_SETMENUHANDLE:
3042
Alexandre Julliarda3960291999-02-26 11:11:13 +00003043 *(HMENU*)wndPtr->wExtra = (HMENU)wParam;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003044 break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003045
3046 case MM_GETMENUHANDLE:
3047
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003048 retvalue = *(HMENU*)wndPtr->wExtra;
3049 goto END;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003050
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003051 default:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003052 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
3053 goto END;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003054 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003055 retvalue = 0;
3056END:
3057 WIN_ReleaseWndPtr(wndPtr);
3058 return retvalue;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003059}
3060
3061
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00003062/***********************************************************************
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003063 * MENU_GetMenuBarHeight
3064 *
3065 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3066 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003067UINT MENU_GetMenuBarHeight( HWND hwnd, UINT menubarWidth,
3068 INT orgX, INT orgY )
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003069{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003070 HDC hdc;
3071 RECT rectBar;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003072 WND *wndPtr;
3073 LPPOPUPMENU lppop;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003074 UINT retvalue;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003075
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003076 TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
Juergen Schmied78513941999-04-18 14:40:32 +00003077 hwnd, menubarWidth, orgX, orgY );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003078
Juergen Schmied78513941999-04-18 14:40:32 +00003079 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
3080 return 0;
3081
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003082 if (!(lppop = (LPPOPUPMENU)USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu)))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003083 {
Juergen Schmied78513941999-04-18 14:40:32 +00003084 WIN_ReleaseWndPtr(wndPtr);
3085 return 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003086 }
Juergen Schmied78513941999-04-18 14:40:32 +00003087
Alexandre Julliarda3960291999-02-26 11:11:13 +00003088 hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
Juergen Schmied78513941999-04-18 14:40:32 +00003089 SelectObject( hdc, hMenuFont);
Marcus Meissnerddca3151999-05-22 11:33:23 +00003090 SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
Juergen Schmied78513941999-04-18 14:40:32 +00003091 MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003092 ReleaseDC( hwnd, hdc );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003093 retvalue = lppop->Height;
3094 WIN_ReleaseWndPtr(wndPtr);
3095 return retvalue;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003096}
3097
3098
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003099/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003100 * ChangeMenu16 (USER.153)
Alexandre Julliard401710d1993-09-04 10:09:32 +00003101 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003102BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
3103 UINT16 id, UINT16 flags )
Alexandre Julliard401710d1993-09-04 10:09:32 +00003104{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003105 TRACE("menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +00003106 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003107 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND,
3108 id, data );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003109
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003110 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
3111 /* for MF_DELETE. We should check the parameters for all others */
3112 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003113
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003114 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
3115 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE,
3116 id, data );
3117 if (flags & MF_REMOVE) return RemoveMenu16(hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003118 flags & MF_BYPOSITION ? pos : id,
3119 flags & ~MF_REMOVE );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003120 /* Default: MF_INSERT */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003121 return InsertMenu16( hMenu, pos, flags, id, data );
3122}
3123
3124
3125/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003126 * ChangeMenu32A (USER32.23)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003127 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003128BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
3129 UINT id, UINT flags )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003130{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003131 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003132 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003133 if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003134 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003135 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3136 if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003137 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003138 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003139 flags & MF_BYPOSITION ? pos : id,
3140 flags & ~MF_REMOVE );
3141 /* Default: MF_INSERT */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003142 return InsertMenuA( hMenu, pos, flags, id, data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003143}
3144
3145
3146/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003147 * ChangeMenu32W (USER32.24)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003148 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003149BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
3150 UINT id, UINT flags )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003151{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003152 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003153 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003154 if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003155 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003156 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3157 if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003158 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003159 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003160 flags & MF_BYPOSITION ? pos : id,
3161 flags & ~MF_REMOVE );
3162 /* Default: MF_INSERT */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003163 return InsertMenuW( hMenu, pos, flags, id, data );
Alexandre Julliard401710d1993-09-04 10:09:32 +00003164}
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003165
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003166
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003167/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003168 * CheckMenuItem16 (USER.154)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003169 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003170BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003171{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003172 return (BOOL16)CheckMenuItem( hMenu, id, flags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003173}
3174
3175
3176/*******************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003177 * CheckMenuItem (USER32.46)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003178 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003179DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003180{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003181 MENUITEM *item;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003182 DWORD ret;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003183
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003184 TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003185 if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003186 ret = item->fState & MF_CHECKED;
3187 if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
3188 else item->fState &= ~MF_CHECKED;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003189 return ret;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003190}
3191
3192
3193/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003194 * EnableMenuItem16 (USER.155)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003195 */
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003196UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003197{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003198 return EnableMenuItem( hMenu, wItemID, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003199}
3200
3201
3202/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003203 * EnableMenuItem32 (USER32.170)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003204 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003205UINT WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003206{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003207 UINT oldflags;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003208 MENUITEM *item;
Pascal Lessardd814bb61999-07-31 13:02:02 +00003209 POPUPMENU *menu;
Alexandre Julliardf7207251994-07-23 07:57:48 +00003210
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003211 TRACE("(%04x, %04X, %04X) !\n",
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003212 hMenu, wItemID, wFlags);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003213
Pascal Lessardd814bb61999-07-31 13:02:02 +00003214 /* Get the Popupmenu to access the owner menu */
3215 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
3216 return (UINT)-1;
3217
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003218 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003219 return (UINT)-1;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003220
3221 oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
3222 item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
Pascal Lessardd814bb61999-07-31 13:02:02 +00003223
3224 /* In win95 if the close item in the system menu change update the close button */
3225 if (TWEAK_WineLook == WIN95_LOOK)
3226 if((item->wID == SC_CLOSE) && (oldflags != wFlags))
3227 {
3228 if (menu->hSysMenuOwner != 0)
3229 {
3230 POPUPMENU* parentMenu;
3231
3232 /* Get the parent menu to access*/
3233 if (!(parentMenu = (POPUPMENU *) USER_HEAP_LIN_ADDR(menu->hSysMenuOwner)))
3234 return (UINT)-1;
3235
3236 /* Refresh the frame to reflect the change*/
3237 SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
Stephane Lussiera833f631999-08-21 14:46:06 +00003238 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
Pascal Lessardd814bb61999-07-31 13:02:02 +00003239 }
3240 }
3241
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003242 return oldflags;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003243}
3244
3245
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003246/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003247 * GetMenuString16 (USER.161)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003248 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003249INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
3250 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003251{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003252 return GetMenuStringA( hMenu, wItemID, str, nMaxSiz, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003253}
3254
3255
3256/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003257 * GetMenuString32A (USER32.268)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003258 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003259INT WINAPI GetMenuStringA( HMENU hMenu, UINT wItemID,
3260 LPSTR str, INT nMaxSiz, UINT wFlags )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003261{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003262 MENUITEM *item;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003263
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003264 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003265 hMenu, wItemID, str, nMaxSiz, wFlags );
3266 if (!str || !nMaxSiz) return 0;
3267 str[0] = '\0';
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003268 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003269 if (!IS_STRING_ITEM(item->fType)) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003270 lstrcpynA( str, item->text, nMaxSiz );
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003271 TRACE("returning '%s'\n", str );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003272 return strlen(str);
Alexandre Julliard1f579291994-05-25 16:25:21 +00003273}
3274
3275
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003276/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003277 * GetMenuString32W (USER32.269)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003278 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003279INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
3280 LPWSTR str, INT nMaxSiz, UINT wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003281{
3282 MENUITEM *item;
3283
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003284 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003285 hMenu, wItemID, str, nMaxSiz, wFlags );
3286 if (!str || !nMaxSiz) return 0;
3287 str[0] = '\0';
3288 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003289 if (!IS_STRING_ITEM(item->fType)) return 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003290 lstrcpynAtoW( str, item->text, nMaxSiz );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003291 return lstrlenW(str);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003292}
3293
3294
3295/**********************************************************************
3296 * HiliteMenuItem16 (USER.162)
3297 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003298BOOL16 WINAPI HiliteMenuItem16( HWND16 hWnd, HMENU16 hMenu, UINT16 wItemID,
3299 UINT16 wHilite )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003300{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003301 return HiliteMenuItem( hWnd, hMenu, wItemID, wHilite );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003302}
3303
3304
3305/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003306 * HiliteMenuItem32 (USER32.318)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003307 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003308BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
3309 UINT wHilite )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003310{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003311 LPPOPUPMENU menu;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003312 TRACE("(%04x, %04x, %04x, %04x);\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +00003313 hWnd, hMenu, wItemID, wHilite);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003314 if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003315 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003316 if (menu->FocusedItem == wItemID) return TRUE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00003317 MENU_HideSubPopups( hWnd, hMenu, FALSE );
3318 MENU_SelectItem( hWnd, hMenu, wItemID, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003319 return TRUE;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003320}
3321
3322
3323/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003324 * GetMenuState16 (USER.250)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003325 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003326UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003327{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003328 return GetMenuState( hMenu, wItemID, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003329}
3330
3331
3332/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003333 * GetMenuState (USER32.267)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003334 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003335UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003336{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003337 MENUITEM *item;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003338 TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
Alexandre Julliardaca05781994-10-17 18:12:41 +00003339 hMenu, wItemID, wFlags);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003340 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
Alexandre Julliard03468f71998-02-15 19:40:49 +00003341 debug_print_menuitem (" item: ", item, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003342 if (item->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003343 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003344 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( item->hSubMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003345 if (!menu) return -1;
Alexandre Julliard829fe321998-07-26 14:27:39 +00003346 else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003347 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003348 else
Alexandre Julliard491502b1997-11-01 19:08:16 +00003349 {
Alexandre Julliard829fe321998-07-26 14:27:39 +00003350 /* We used to (from way back then) mask the result to 0xff. */
3351 /* I don't know why and it seems wrong as the documented */
3352 /* return flag MF_SEPARATOR is outside that mask. */
3353 return (item->fType | item->fState);
Alexandre Julliard491502b1997-11-01 19:08:16 +00003354 }
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003355}
3356
3357
3358/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003359 * GetMenuItemCount16 (USER.263)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003360 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003361INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003362{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003363 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003364 if (!IS_A_MENU(menu)) return -1;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003365 TRACE("(%04x) returning %d\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003366 hMenu, menu->nItems );
3367 return menu->nItems;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003368}
3369
3370
3371/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003372 * GetMenuItemCount32 (USER32.262)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003373 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003374INT WINAPI GetMenuItemCount( HMENU hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003375{
3376 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003377 if (!IS_A_MENU(menu)) return -1;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003378 TRACE("(%04x) returning %d\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003379 hMenu, menu->nItems );
3380 return menu->nItems;
3381}
3382
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003383/**********************************************************************
3384 * GetMenuItemID16 (USER.264)
3385 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003386UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003387{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003388 return (UINT16) GetMenuItemID (hMenu, nPos);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003389}
3390
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003391/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003392 * GetMenuItemID32 (USER32.263)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003393 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003394UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003395{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003396 MENUITEM * lpmi;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003397
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003398 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3399 if (lpmi->fType & MF_POPUP) return -1;
3400 return lpmi->wID;
3401
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003402}
3403
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003404/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003405 * InsertMenu16 (USER.410)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003406 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003407BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3408 UINT16 id, SEGPTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003409{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003410 UINT pos32 = (UINT)pos;
3411 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003412 if (IS_STRING_ITEM(flags) && data)
Alexandre Julliarda3960291999-02-26 11:11:13 +00003413 return InsertMenuA( hMenu, pos32, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003414 (LPSTR)PTR_SEG_TO_LIN(data) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003415 return InsertMenuA( hMenu, pos32, flags, id, (LPSTR)data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003416}
3417
3418
3419/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003420 * InsertMenu32A (USER32.322)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003421 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003422BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
3423 UINT id, LPCSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003424{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003425 MENUITEM *item;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003426
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003427 if (IS_STRING_ITEM(flags) && str)
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003428 TRACE("hMenu %04x, pos %d, flags %08x, "
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003429 "id %04x, str '%s'\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003430 hMenu, pos, flags, id, str );
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003431 else TRACE("hMenu %04x, pos %d, flags %08x, "
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003432 "id %04x, str %08lx (not a string)\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003433 hMenu, pos, flags, id, (DWORD)str );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003434
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003435 if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003436
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003437 if (!(MENU_SetItemData( item, flags, id, str )))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003438 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003439 RemoveMenu( hMenu, pos, flags );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003440 return FALSE;
3441 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003442
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003443 if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003444 ((POPUPMENU *)USER_HEAP_LIN_ADDR((HMENU16)id))->wFlags |= MF_POPUP;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003445
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003446 item->hCheckBit = item->hUnCheckBit = 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003447 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003448}
3449
3450
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003451/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003452 * InsertMenu32W (USER32.325)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003453 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003454BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
3455 UINT id, LPCWSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003456{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003457 BOOL ret;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003458
3459 if (IS_STRING_ITEM(flags) && str)
3460 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003461 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003462 ret = InsertMenuA( hMenu, pos, flags, id, newstr );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003463 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003464 return ret;
3465 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003466 else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003467}
3468
3469
3470/*******************************************************************
3471 * AppendMenu16 (USER.411)
3472 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003473BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003474{
3475 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
3476}
3477
3478
3479/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003480 * AppendMenu32A (USER32.5)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003481 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003482BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
3483 UINT id, LPCSTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003484{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003485 return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003486}
3487
3488
3489/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003490 * AppendMenu32W (USER32.6)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003491 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003492BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
3493 UINT id, LPCWSTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003494{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003495 return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003496}
3497
3498
3499/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003500 * RemoveMenu16 (USER.412)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003501 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003502BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003503{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003504 return RemoveMenu( hMenu, nPos, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003505}
3506
3507
3508/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003509 * RemoveMenu (USER32.441)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003510 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003511BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003512{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003513 LPPOPUPMENU menu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003514 MENUITEM *item;
3515
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003516 TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003517 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003518 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003519
3520 /* Remove item */
3521
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003522 MENU_FreeItemData( item );
3523
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003524 if (--menu->nItems == 0)
3525 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003526 HeapFree( SystemHeap, 0, menu->items );
3527 menu->items = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003528 }
3529 else
3530 {
3531 while(nPos < menu->nItems)
3532 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003533 *item = *(item+1);
3534 item++;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003535 nPos++;
3536 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003537 menu->items = HeapReAlloc( SystemHeap, 0, menu->items,
3538 menu->nItems * sizeof(MENUITEM) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003539 }
3540 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003541}
3542
3543
3544/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003545 * DeleteMenu16 (USER.413)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003546 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003547BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003548{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003549 return DeleteMenu( hMenu, nPos, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003550}
3551
3552
3553/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003554 * DeleteMenu32 (USER32.129)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003555 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003556BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003557{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003558 MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
3559 if (!item) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003560 if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003561 /* nPos is now the position of the item */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003562 RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003563 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003564}
3565
3566
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003567/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003568 * ModifyMenu16 (USER.414)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003569 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003570BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3571 UINT16 id, SEGPTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003572{
3573 if (IS_STRING_ITEM(flags))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003574 return ModifyMenuA( hMenu, pos, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003575 (LPSTR)PTR_SEG_TO_LIN(data) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003576 return ModifyMenuA( hMenu, pos, flags, id, (LPSTR)data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003577}
3578
3579
3580/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003581 * ModifyMenu32A (USER32.397)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003582 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003583BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
3584 UINT id, LPCSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003585{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003586 MENUITEM *item;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003587
3588 if (IS_STRING_ITEM(flags))
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003589 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003590 TRACE("%04x %d %04x %04x '%s'\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003591 hMenu, pos, flags, id, str ? str : "#NULL#" );
3592 if (!str) return FALSE;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003593 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003594 else
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003595 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003596 TRACE("%04x %d %04x %04x %08lx\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003597 hMenu, pos, flags, id, (DWORD)str );
3598 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003599
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003600 if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003601 return MENU_SetItemData( item, flags, id, str );
3602}
3603
3604
3605/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003606 * ModifyMenu32W (USER32.398)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003607 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003608BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
3609 UINT id, LPCWSTR str )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003610{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003611 BOOL ret;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003612
3613 if (IS_STRING_ITEM(flags) && str)
3614 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003615 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003616 ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003617 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003618 return ret;
3619 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003620 else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003621}
3622
3623
3624/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003625 * CreatePopupMenu16 (USER.415)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003626 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003627HMENU16 WINAPI CreatePopupMenu16(void)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003628{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003629 return CreatePopupMenu();
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003630}
3631
3632
3633/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003634 * CreatePopupMenu32 (USER32.82)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003635 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003636HMENU WINAPI CreatePopupMenu(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003637{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003638 HMENU hmenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003639 POPUPMENU *menu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003640
Alexandre Julliarda3960291999-02-26 11:11:13 +00003641 if (!(hmenu = CreateMenu())) return 0;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003642 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003643 menu->wFlags |= MF_POPUP;
Pascal Lessard2eb0a301999-09-03 16:38:52 +00003644 menu->bTimeToHide = FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003645 return hmenu;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003646}
3647
3648
3649/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003650 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003651 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003652DWORD WINAPI GetMenuCheckMarkDimensions(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003653{
Alexandre Julliardf7207251994-07-23 07:57:48 +00003654 return MAKELONG( check_bitmap_width, check_bitmap_height );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003655}
3656
3657
3658/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003659 * SetMenuItemBitmaps16 (USER.418)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003660 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003661BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
3662 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003663{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003664 return SetMenuItemBitmaps( hMenu, nPos, wFlags, hNewUnCheck, hNewCheck );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003665}
3666
3667
3668/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003669 * SetMenuItemBitmaps32 (USER32.490)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003670 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003671BOOL WINAPI SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags,
3672 HBITMAP hNewUnCheck, HBITMAP hNewCheck)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003673{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003674 MENUITEM *item;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003675 TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003676 hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
3677 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003678
3679 if (!hNewCheck && !hNewUnCheck)
3680 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003681 item->fState &= ~MF_USECHECKBITMAPS;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003682 }
3683 else /* Install new bitmaps */
3684 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003685 item->hCheckBit = hNewCheck;
3686 item->hUnCheckBit = hNewUnCheck;
3687 item->fState |= MF_USECHECKBITMAPS;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003688 }
3689 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003690}
3691
3692
3693/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003694 * CreateMenu16 (USER.151)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003695 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003696HMENU16 WINAPI CreateMenu16(void)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003697{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003698 return CreateMenu();
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003699}
3700
3701
3702/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003703 * CreateMenu (USER32.81)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003704 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003705HMENU WINAPI CreateMenu(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003706{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003707 HMENU hMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003708 LPPOPUPMENU menu;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003709 if (!(hMenu = USER_HEAP_ALLOC( sizeof(POPUPMENU) ))) return 0;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003710 menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00003711
3712 ZeroMemory(menu, sizeof(POPUPMENU));
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003713 menu->wMagic = MENU_MAGIC;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003714 menu->FocusedItem = NO_SELECTED_ITEM;
Pascal Lessard2eb0a301999-09-03 16:38:52 +00003715 menu->bTimeToHide = FALSE;
Juergen Schmied78513941999-04-18 14:40:32 +00003716
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003717 TRACE("return %04x\n", hMenu );
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00003718
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003719 return hMenu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003720}
3721
3722
3723/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003724 * DestroyMenu16 (USER.152)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003725 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003726BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003727{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003728 return DestroyMenu( hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003729}
3730
3731
3732/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003733 * DestroyMenu32 (USER32.134)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003734 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003735BOOL WINAPI DestroyMenu( HMENU hMenu )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003736{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003737 TRACE("(%04x)\n", hMenu);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003738
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003739 /* Silently ignore attempts to destroy default system popup */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003740
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003741 if (hMenu && hMenu != MENU_DefSysPopup)
Alexandre Julliardff8331e1995-09-18 11:19:54 +00003742 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003743 LPPOPUPMENU lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003744 WND *pTPWnd = MENU_GetTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003745
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003746 if( pTPWnd && (hMenu == *(HMENU*)pTPWnd->wExtra) )
3747 *(UINT*)pTPWnd->wExtra = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003748
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003749 if (IS_A_MENU( lppop ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003750 {
3751 lppop->wMagic = 0; /* Mark it as destroyed */
3752
3753 if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003754 (!pTPWnd || (lppop->hWnd != pTPWnd->hwndSelf)))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003755 DestroyWindow( lppop->hWnd );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003756
3757 if (lppop->items) /* recursively destroy submenus */
3758 {
3759 int i;
3760 MENUITEM *item = lppop->items;
3761 for (i = lppop->nItems; i > 0; i--, item++)
3762 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003763 if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003764 MENU_FreeItemData( item );
3765 }
3766 HeapFree( SystemHeap, 0, lppop->items );
3767 }
3768 USER_HEAP_FREE( hMenu );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00003769 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003770 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00003771 else
3772 {
3773 MENU_ReleaseTopPopupWnd();
3774 return FALSE;
3775 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +00003776 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003777 return (hMenu != MENU_DefSysPopup);
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003778}
3779
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003780
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003781/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003782 * GetSystemMenu16 (USER.156)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003783 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003784HMENU16 WINAPI GetSystemMenu16( HWND16 hWnd, BOOL16 bRevert )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003785{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003786 return GetSystemMenu( hWnd, bRevert );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003787}
3788
3789
3790/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003791 * GetSystemMenu32 (USER32.291)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003792 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003793HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003794{
Alexandre Julliardb7258be1995-09-01 15:57:28 +00003795 WND *wndPtr = WIN_FindWndPtr( hWnd );
Eric Pouech562309a1999-08-21 12:59:44 +00003796 HMENU retvalue = 0;
Alexandre Julliardb7258be1995-09-01 15:57:28 +00003797
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003798 if (wndPtr)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003799 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003800 if( wndPtr->hSysMenu )
3801 {
3802 if( bRevert )
3803 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003804 DestroyMenu(wndPtr->hSysMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003805 wndPtr->hSysMenu = 0;
3806 }
3807 else
3808 {
3809 POPUPMENU *menu = (POPUPMENU*)
3810 USER_HEAP_LIN_ADDR(wndPtr->hSysMenu);
Eric Pouech562309a1999-08-21 12:59:44 +00003811 if( IS_A_MENU(menu) )
3812 {
3813 if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
3814 menu->items[0].hSubMenu = MENU_CopySysPopup();
3815 }
3816 else
3817 {
3818 WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
3819 wndPtr->hSysMenu, hWnd);
3820 wndPtr->hSysMenu = 0;
3821 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003822 }
3823 }
3824
3825 if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00003826 wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003827
3828 if( wndPtr->hSysMenu )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003829 {
Eric Pouech562309a1999-08-21 12:59:44 +00003830 POPUPMENU *menu;
3831 retvalue = GetSubMenu16(wndPtr->hSysMenu, 0);
Pascal Lessardd814bb61999-07-31 13:02:02 +00003832
3833 /* Store the dummy sysmenu handle to facilitate the refresh */
3834 /* of the close button if the SC_CLOSE item change */
Eric Pouech562309a1999-08-21 12:59:44 +00003835 menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(retvalue);
3836 if ( IS_A_MENU(menu) )
3837 menu->hSysMenuOwner = wndPtr->hSysMenu;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003838 }
3839 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003840 }
Eric Pouech562309a1999-08-21 12:59:44 +00003841 return retvalue;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003842}
3843
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003844
3845/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003846 * SetSystemMenu16 (USER.280)
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003847 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003848BOOL16 WINAPI SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003849{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003850 return SetSystemMenu( hwnd, hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003851}
3852
3853
3854/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003855 * SetSystemMenu32 (USER32.508)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003856 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003857BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003858{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003859 WND *wndPtr = WIN_FindWndPtr(hwnd);
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003860
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003861 if (wndPtr)
3862 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003863 if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003864 wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003865 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003866 return TRUE;
3867 }
3868 return FALSE;
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003869}
3870
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003871
3872/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003873 * GetMenu16 (USER.157)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003874 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003875HMENU16 WINAPI GetMenu16( HWND16 hWnd )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003876{
Richard Cohen56753621999-09-19 14:08:13 +00003877 return (HMENU16)GetMenu(hWnd);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003878}
3879
3880
3881/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003882 * GetMenu32 (USER32.257)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003883 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003884HMENU WINAPI GetMenu( HWND hWnd )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003885{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003886 HMENU retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003887 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003888 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003889 {
3890 retvalue = (HMENU)wndPtr->wIDmenu;
3891 goto END;
3892 }
3893 retvalue = 0;
3894END:
3895 WIN_ReleaseWndPtr(wndPtr);
3896 return retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003897}
3898
3899
3900/**********************************************************************
3901 * SetMenu16 (USER.158)
3902 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003903BOOL16 WINAPI SetMenu16( HWND16 hWnd, HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003904{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003905 return SetMenu( hWnd, hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003906}
3907
3908
3909/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003910 * SetMenu32 (USER32.487)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003911 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003912BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003913{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003914 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003915
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003916 TRACE("(%04x, %04x);\n", hWnd, hMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003917
Richard Cohen56753621999-09-19 14:08:13 +00003918 if (hMenu && !IsMenu(hMenu))
3919 {
3920 WARN("hMenu is not a menu handle\n");
3921 return FALSE;
3922 }
3923
3924
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003925 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003926 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003927 if (GetCapture() == hWnd) ReleaseCapture();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003928
Alexandre Julliarda3960291999-02-26 11:11:13 +00003929 wndPtr->wIDmenu = (UINT)hMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003930 if (hMenu != 0)
3931 {
3932 LPPOPUPMENU lpmenu;
3933
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003934 if (!(lpmenu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
3935 {
3936 WIN_ReleaseWndPtr(wndPtr);
3937 return FALSE;
3938 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003939 lpmenu->hWnd = hWnd;
3940 lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
3941 lpmenu->Height = 0; /* Make sure we recalculate the size */
3942 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003943 if (IsWindowVisible(hWnd))
3944 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliard01d63461997-01-20 19:43:45 +00003945 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003946 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003947 return TRUE;
3948 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003949 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003950 return FALSE;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003951}
3952
3953
Alexandre Julliardd18872d1994-05-11 12:18:19 +00003954
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003955/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003956 * GetSubMenu16 (USER.159)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003957 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003958HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003959{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003960 return GetSubMenu( hMenu, nPos );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003961}
3962
3963
3964/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003965 * GetSubMenu32 (USER32.288)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003966 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003967HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003968{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003969 MENUITEM * lpmi;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003970
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003971 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3972 if (!(lpmi->fType & MF_POPUP)) return 0;
3973 return lpmi->hSubMenu;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003974}
3975
3976
3977/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003978 * DrawMenuBar16 (USER.160)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003979 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003980void WINAPI DrawMenuBar16( HWND16 hWnd )
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003981{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003982 DrawMenuBar( hWnd );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003983}
Alexandre Julliardf7207251994-07-23 07:57:48 +00003984
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003985
3986/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003987 * DrawMenuBar (USER32.161)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003988 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003989BOOL WINAPI DrawMenuBar( HWND hWnd )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003990{
3991 LPPOPUPMENU lppop;
3992 WND *wndPtr = WIN_FindWndPtr(hWnd);
3993 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && wndPtr->wIDmenu)
3994 {
3995 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003996 if (lppop == NULL)
3997 {
3998 WIN_ReleaseWndPtr(wndPtr);
3999 return FALSE;
4000 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004001
4002 lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
Juergen Schmied78513941999-04-18 14:40:32 +00004003 lppop->hwndOwner = hWnd;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004004 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliard01d63461997-01-20 19:43:45 +00004005 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00004006 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004007 return TRUE;
4008 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00004009 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004010 return FALSE;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004011}
4012
4013
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004014/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004015 * EndMenu (USER.187) (USER32.175)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004016 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004017void WINAPI EndMenu(void)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004018{
Alex Korobka4f1ac051999-03-28 09:37:57 +00004019 /*
4020 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
4021 */
4022
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00004023 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004024}
4025
4026
4027/***********************************************************************
4028 * LookupMenuHandle (USER.217)
4029 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004030HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004031{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004032 HMENU hmenu32 = hmenu;
4033 UINT id32 = id;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004034 if (!MENU_FindItem( &hmenu32, &id32, MF_BYCOMMAND )) return 0;
4035 else return hmenu32;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004036}
4037
4038
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004039/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004040 * LoadMenu16 (USER.150)
Alexandre Julliard594997c1995-04-30 10:05:20 +00004041 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004042HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, SEGPTR name )
Alexandre Julliard594997c1995-04-30 10:05:20 +00004043{
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004044 HRSRC16 hRsrc;
4045 HGLOBAL16 handle;
4046 HMENU16 hMenu;
Alexandre Julliard594997c1995-04-30 10:05:20 +00004047
4048 if (HIWORD(name))
4049 {
4050 char *str = (char *)PTR_SEG_TO_LIN( name );
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004051 TRACE("(%04x,'%s')\n", instance, str );
Alexandre Julliard594997c1995-04-30 10:05:20 +00004052 if (str[0] == '#') name = (SEGPTR)atoi( str + 1 );
4053 }
4054 else
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004055 TRACE("(%04x,%04x)\n",instance,LOWORD(name));
Alexandre Julliard594997c1995-04-30 10:05:20 +00004056
4057 if (!name) return 0;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00004058
4059 /* check for Win32 module */
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00004060 if (HIWORD(instance))
Alexandre Julliarda3960291999-02-26 11:11:13 +00004061 return LoadMenuA(instance,PTR_SEG_TO_LIN(name));
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00004062 instance = GetExePtr( instance );
Alexandre Julliard594997c1995-04-30 10:05:20 +00004063
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004064 if (!(hRsrc = FindResource16( instance, name, RT_MENU16 ))) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004065 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
4066 hMenu = LoadMenuIndirect16(LockResource16(handle));
4067 FreeResource16( handle );
Alexandre Julliard594997c1995-04-30 10:05:20 +00004068 return hMenu;
4069}
4070
4071
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004072/*****************************************************************
4073 * LoadMenu32A (USER32.370)
4074 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004075HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004076{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004077 HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004078 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004079 return LoadMenuIndirectA( (LPCVOID)LoadResource( instance, hrsrc ));
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004080}
4081
4082
4083/*****************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004084 * LoadMenu32W (USER32.373)
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004085 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004086HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004087{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004088 HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004089 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004090 return LoadMenuIndirectW( (LPCVOID)LoadResource( instance, hrsrc ));
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004091}
4092
4093
Alexandre Julliard594997c1995-04-30 10:05:20 +00004094/**********************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004095 * LoadMenuIndirect16 (USER.220)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00004096 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004097HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00004098{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00004099 HMENU16 hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004100 WORD version, offset;
4101 LPCSTR p = (LPCSTR)template;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00004102
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004103 TRACE("(%p)\n", template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004104 version = GET_WORD(p);
4105 p += sizeof(WORD);
4106 if (version)
4107 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004108 WARN("version must be 0 for Win16\n" );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004109 return 0;
4110 }
4111 offset = GET_WORD(p);
4112 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004113 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004114 if (!MENU_ParseResource( p, hMenu, FALSE ))
Alexandre Julliard7e56f681996-01-31 19:02:28 +00004115 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004116 DestroyMenu( hMenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004117 return 0;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00004118 }
4119 return hMenu;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004120}
4121
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004122
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004123/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004124 * LoadMenuIndirect32A (USER32.371)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004125 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004126HMENU WINAPI LoadMenuIndirectA( LPCVOID template )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004127{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00004128 HMENU16 hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004129 WORD version, offset;
4130 LPCSTR p = (LPCSTR)template;
4131
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004132 TRACE("%p\n", template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004133 version = GET_WORD(p);
4134 p += sizeof(WORD);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004135 switch (version)
4136 {
4137 case 0:
4138 offset = GET_WORD(p);
4139 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004140 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004141 if (!MENU_ParseResource( p, hMenu, TRUE ))
4142 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004143 DestroyMenu( hMenu );
Alexandre Julliard641ee761997-08-04 16:34:36 +00004144 return 0;
4145 }
4146 return hMenu;
4147 case 1:
4148 offset = GET_WORD(p);
4149 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004150 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004151 if (!MENUEX_ParseResource( p, hMenu))
4152 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004153 DestroyMenu( hMenu );
Alexandre Julliard641ee761997-08-04 16:34:36 +00004154 return 0;
4155 }
4156 return hMenu;
4157 default:
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004158 ERR("version %d not supported.\n", version);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004159 return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004160 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004161}
4162
4163
4164/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004165 * LoadMenuIndirect32W (USER32.372)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004166 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004167HMENU WINAPI LoadMenuIndirectW( LPCVOID template )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004168{
4169 /* FIXME: is there anything different between A and W? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004170 return LoadMenuIndirectA( template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004171}
4172
4173
4174/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004175 * IsMenu16 (USER.358)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004176 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004177BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004178{
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004179 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4180 return IS_A_MENU(menu);
4181}
4182
4183
4184/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004185 * IsMenu32 (USER32.346)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004186 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004187BOOL WINAPI IsMenu(HMENU hmenu)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004188{
4189 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4190 return IS_A_MENU(menu);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004191}
4192
Alexandre Julliard641ee761997-08-04 16:34:36 +00004193/**********************************************************************
4194 * GetMenuItemInfo32_common
4195 */
4196
Juergen Schmied78513941999-04-18 14:40:32 +00004197static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
4198 LPMENUITEMINFOA lpmii, BOOL unicode)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004199{
Juergen Schmied78513941999-04-18 14:40:32 +00004200 MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
4201
Alexandre Julliard03468f71998-02-15 19:40:49 +00004202 debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
Juergen Schmied78513941999-04-18 14:40:32 +00004203
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004204 if (!menu)
4205 return FALSE;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004206
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004207 if (lpmii->fMask & MIIM_TYPE) {
4208 lpmii->fType = menu->fType;
4209 switch (MENU_ITEM_TYPE(menu->fType)) {
Juergen Schmied78513941999-04-18 14:40:32 +00004210 case MF_STRING:
4211 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
4212 if (unicode) {
4213 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4214 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4215 } else {
4216 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4217 lpmii->cch = lstrlenA(menu->text);
4218 }
4219 }
4220 break;
4221 case MF_OWNERDRAW:
4222 case MF_BITMAP:
4223 lpmii->dwTypeData = menu->text;
4224 /* fall through */
4225 default:
4226 lpmii->cch = 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004227 }
Alexandre Julliard641ee761997-08-04 16:34:36 +00004228 }
Juergen Schmied78513941999-04-18 14:40:32 +00004229
4230 if (lpmii->fMask & MIIM_STRING) {
4231 if (unicode) {
4232 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4233 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4234 } else {
4235 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4236 lpmii->cch = lstrlenA(menu->text);
4237 }
Alexandre Julliard641ee761997-08-04 16:34:36 +00004238 }
Juergen Schmied78513941999-04-18 14:40:32 +00004239
4240 if (lpmii->fMask & MIIM_FTYPE)
4241 lpmii->fType = menu->fType;
4242
4243 if (lpmii->fMask & MIIM_BITMAP)
4244 lpmii->hbmpItem = menu->hbmpItem;
4245
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004246 if (lpmii->fMask & MIIM_STATE)
4247 lpmii->fState = menu->fState;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004248
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004249 if (lpmii->fMask & MIIM_ID)
4250 lpmii->wID = menu->wID;
4251
4252 if (lpmii->fMask & MIIM_SUBMENU)
4253 lpmii->hSubMenu = menu->hSubMenu;
4254
4255 if (lpmii->fMask & MIIM_CHECKMARKS) {
4256 lpmii->hbmpChecked = menu->hCheckBit;
4257 lpmii->hbmpUnchecked = menu->hUnCheckBit;
4258 }
4259 if (lpmii->fMask & MIIM_DATA)
4260 lpmii->dwItemData = menu->dwItemData;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004261
4262 return TRUE;
4263}
4264
4265/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004266 * GetMenuItemInfoA (USER32.264)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004267 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004268BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
4269 LPMENUITEMINFOA lpmii)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004270{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004271 return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004272}
4273
4274/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004275 * GetMenuItemInfoW (USER32.265)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004276 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004277BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
4278 LPMENUITEMINFOW lpmii)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004279{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004280 return GetMenuItemInfo_common (hmenu, item, bypos,
4281 (LPMENUITEMINFOA)lpmii, TRUE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004282}
4283
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004284/**********************************************************************
4285 * SetMenuItemInfo32_common
4286 */
4287
Alexandre Julliarda3960291999-02-26 11:11:13 +00004288static BOOL SetMenuItemInfo_common(MENUITEM * menu,
4289 const MENUITEMINFOA *lpmii,
4290 BOOL unicode)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004291{
4292 if (!menu) return FALSE;
4293
Juergen Schmied78513941999-04-18 14:40:32 +00004294 if (lpmii->fMask & MIIM_TYPE ) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004295 /* Get rid of old string. */
Juergen Schmied78513941999-04-18 14:40:32 +00004296 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004297 HeapFree(SystemHeap, 0, menu->text);
Juergen Schmied78513941999-04-18 14:40:32 +00004298 menu->text = NULL;
4299 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004300
Juergen Schmied78513941999-04-18 14:40:32 +00004301 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4302 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4303 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
Paul Millar39da2221999-04-11 12:08:42 +00004304
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004305 menu->text = lpmii->dwTypeData;
Juergen Schmied78513941999-04-18 14:40:32 +00004306
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004307 if (IS_STRING_ITEM(menu->fType) && menu->text) {
Juergen Schmied78513941999-04-18 14:40:32 +00004308 if (unicode)
4309 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4310 else
4311 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004312 }
4313 }
Juergen Schmied78513941999-04-18 14:40:32 +00004314
4315 if (lpmii->fMask & MIIM_FTYPE ) {
4316 /* free the string when the type is changing */
4317 if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
4318 HeapFree(SystemHeap, 0, menu->text);
4319 menu->text = NULL;
4320 }
4321 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4322 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4323 }
4324
4325 if (lpmii->fMask & MIIM_STRING ) {
4326 /* free the string when used */
4327 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4328 HeapFree(SystemHeap, 0, menu->text);
4329 if (unicode)
4330 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4331 else
4332 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
4333 }
4334 }
4335
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004336 if (lpmii->fMask & MIIM_STATE)
Juergen Schmied466a6521999-05-02 11:21:08 +00004337 {
4338 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004339 menu->fState = lpmii->fState;
Juergen Schmied466a6521999-05-02 11:21:08 +00004340 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004341
4342 if (lpmii->fMask & MIIM_ID)
4343 menu->wID = lpmii->wID;
4344
Alexandre Julliarda0d77311998-09-13 16:32:00 +00004345 if (lpmii->fMask & MIIM_SUBMENU) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004346 menu->hSubMenu = lpmii->hSubMenu;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00004347 if (menu->hSubMenu) {
4348 POPUPMENU *subMenu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)menu->hSubMenu);
4349 if (IS_A_MENU(subMenu)) {
4350 subMenu->wFlags |= MF_POPUP;
4351 menu->fType |= MF_POPUP;
4352 }
4353 else
4354 /* FIXME: Return an error ? */
4355 menu->fType &= ~MF_POPUP;
4356 }
4357 else
4358 menu->fType &= ~MF_POPUP;
4359 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004360
4361 if (lpmii->fMask & MIIM_CHECKMARKS)
4362 {
4363 menu->hCheckBit = lpmii->hbmpChecked;
4364 menu->hUnCheckBit = lpmii->hbmpUnchecked;
4365 }
4366 if (lpmii->fMask & MIIM_DATA)
4367 menu->dwItemData = lpmii->dwItemData;
4368
Alexandre Julliard03468f71998-02-15 19:40:49 +00004369 debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004370 return TRUE;
4371}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004372
4373/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004374 * SetMenuItemInfo32A (USER32.491)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004375 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004376BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
4377 const MENUITEMINFOA *lpmii)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004378{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004379 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004380 lpmii, FALSE);
4381}
4382
4383/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004384 * SetMenuItemInfo32W (USER32.492)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004385 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004386BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
4387 const MENUITEMINFOW *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004388{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004389 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4390 (const MENUITEMINFOA*)lpmii, TRUE);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004391}
4392
4393/**********************************************************************
Juergen Schmied466a6521999-05-02 11:21:08 +00004394 * SetMenuDefaultItem (USER32.489)
4395 *
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004396 */
Juergen Schmied466a6521999-05-02 11:21:08 +00004397BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004398{
Juergen Schmied466a6521999-05-02 11:21:08 +00004399 UINT i;
4400 POPUPMENU *menu;
4401 MENUITEM *item;
4402
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004403 TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
Alexandre Julliarda845b881998-06-01 10:44:35 +00004404
Juergen Schmied466a6521999-05-02 11:21:08 +00004405 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return FALSE;
Alexandre Julliarda845b881998-06-01 10:44:35 +00004406
Juergen Schmied466a6521999-05-02 11:21:08 +00004407 /* reset all default-item flags */
4408 item = menu->items;
4409 for (i = 0; i < menu->nItems; i++, item++)
4410 {
4411 item->fState &= ~MFS_DEFAULT;
4412 }
4413
4414 /* no default item */
4415 if ( -1 == uItem)
4416 {
4417 return TRUE;
4418 }
Alexandre Julliarda845b881998-06-01 10:44:35 +00004419
Juergen Schmied466a6521999-05-02 11:21:08 +00004420 item = menu->items;
4421 if ( bypos )
4422 {
4423 if ( uItem >= menu->nItems ) return FALSE;
4424 item[uItem].fState |= MFS_DEFAULT;
4425 return TRUE;
4426 }
4427 else
4428 {
4429 for (i = 0; i < menu->nItems; i++, item++)
4430 {
4431 if (item->wID == uItem)
4432 {
4433 item->fState |= MFS_DEFAULT;
4434 return TRUE;
4435 }
4436 }
4437
4438 }
4439 return FALSE;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004440}
4441
Alexandre Julliarda845b881998-06-01 10:44:35 +00004442/**********************************************************************
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00004443 * GetMenuDefaultItem (USER32.260)
Alexandre Julliarda845b881998-06-01 10:44:35 +00004444 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004445UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
Alexandre Julliarda845b881998-06-01 10:44:35 +00004446{
Juergen Schmied466a6521999-05-02 11:21:08 +00004447 POPUPMENU *menu;
4448 MENUITEM * item;
4449 UINT i = 0;
Alexandre Julliarda845b881998-06-01 10:44:35 +00004450
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004451 TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
Alexandre Julliarda845b881998-06-01 10:44:35 +00004452
Juergen Schmied466a6521999-05-02 11:21:08 +00004453 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return -1;
4454
4455 /* find default item */
4456 item = menu->items;
Juergen Schmied49251861999-05-13 18:42:03 +00004457
4458 /* empty menu */
4459 if (! item) return -1;
4460
Juergen Schmied466a6521999-05-02 11:21:08 +00004461 while ( !( item->fState & MFS_DEFAULT ) )
4462 {
4463 i++; item++;
4464 if (i >= menu->nItems ) return -1;
4465 }
4466
4467 /* default: don't return disabled items */
4468 if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
4469
4470 /* search rekursiv when needed */
4471 if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
4472 {
4473 UINT ret;
4474 ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
4475 if ( -1 != ret ) return ret;
4476
4477 /* when item not found in submenu, return the popup item */
4478 }
4479 return ( bypos ) ? i : item->wID;
4480
Alexandre Julliarda845b881998-06-01 10:44:35 +00004481}
4482
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004483/*******************************************************************
4484 * InsertMenuItem16 (USER.441)
4485 *
4486 * FIXME: untested
4487 */
4488BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
4489 const MENUITEMINFO16 *mii )
4490{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004491 MENUITEMINFOA miia;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004492
4493 miia.cbSize = sizeof(miia);
4494 miia.fMask = mii->fMask;
Alexandre Julliard77b99181997-09-14 17:17:23 +00004495 miia.dwTypeData = mii->dwTypeData;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004496 miia.fType = mii->fType;
4497 miia.fState = mii->fState;
4498 miia.wID = mii->wID;
4499 miia.hSubMenu = mii->hSubMenu;
4500 miia.hbmpChecked = mii->hbmpChecked;
4501 miia.hbmpUnchecked = mii->hbmpUnchecked;
4502 miia.dwItemData = mii->dwItemData;
4503 miia.cch = mii->cch;
4504 if (IS_STRING_ITEM(miia.fType))
4505 miia.dwTypeData = PTR_SEG_TO_LIN(miia.dwTypeData);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004506 return InsertMenuItemA( hmenu, pos, byposition, &miia );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004507}
4508
4509
4510/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004511 * InsertMenuItem32A (USER32.323)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004512 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004513BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
4514 const MENUITEMINFOA *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004515{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004516 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00004517 return SetMenuItemInfo_common(item, lpmii, FALSE);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004518}
4519
4520
4521/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004522 * InsertMenuItem32W (USER32.324)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004523 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004524BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
4525 const MENUITEMINFOW *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004526{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004527 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00004528 return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004529}
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004530
4531/**********************************************************************
4532 * CheckMenuRadioItem32 (USER32.47)
4533 */
4534
Alexandre Julliarda3960291999-02-26 11:11:13 +00004535BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
4536 UINT first, UINT last, UINT check,
4537 UINT bypos)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004538{
4539 MENUITEM *mifirst, *milast, *micheck;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004540 HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004541
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004542 TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004543 hMenu, first, last, check, bypos);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004544
4545 mifirst = MENU_FindItem (&mfirst, &first, bypos);
4546 milast = MENU_FindItem (&mlast, &last, bypos);
4547 micheck = MENU_FindItem (&mcheck, &check, bypos);
4548
4549 if (mifirst == NULL || milast == NULL || micheck == NULL ||
4550 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
4551 micheck > milast || micheck < mifirst)
4552 return FALSE;
4553
4554 while (mifirst <= milast)
4555 {
4556 if (mifirst == micheck)
4557 {
4558 mifirst->fType |= MFT_RADIOCHECK;
4559 mifirst->fState |= MFS_CHECKED;
4560 } else {
4561 mifirst->fType &= ~MFT_RADIOCHECK;
4562 mifirst->fState &= ~MFS_CHECKED;
4563 }
4564 mifirst++;
4565 }
4566
4567 return TRUE;
4568}
4569
4570/**********************************************************************
4571 * CheckMenuRadioItem16 (not a Windows API)
4572 */
4573
4574BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu,
4575 UINT16 first, UINT16 last, UINT16 check,
4576 BOOL16 bypos)
4577{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004578 return CheckMenuRadioItem (hMenu, first, last, check, bypos);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004579}
4580
4581/**********************************************************************
4582 * GetMenuItemRect32 (USER32.266)
Pascal Lessard47274231999-02-13 12:21:46 +00004583 *
4584 * ATTENTION: Here, the returned values in rect are the screen
4585 * coordinates of the item just like if the menu was
4586 * always on the upper left side of the application.
4587 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004588 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004589BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
4590 LPRECT rect)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004591{
Pascal Lessard47274231999-02-13 12:21:46 +00004592 POPUPMENU *itemMenu;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004593 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004594 HWND referenceHwnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004595
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004596 TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004597
4598 item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
Pascal Lessard47274231999-02-13 12:21:46 +00004599 referenceHwnd = hwnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004600
Pascal Lessard47274231999-02-13 12:21:46 +00004601 if(!hwnd)
4602 {
4603 itemMenu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
4604 if (itemMenu == NULL)
4605 return FALSE;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004606
Marcus Meissnerac593bb1999-03-17 15:18:28 +00004607 if(itemMenu->hWnd == 0)
Pascal Lessard47274231999-02-13 12:21:46 +00004608 return FALSE;
4609 referenceHwnd = itemMenu->hWnd;
4610 }
4611
4612 if ((rect == NULL) || (item == NULL))
4613 return FALSE;
4614
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004615 *rect = item->rect;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004616
Alexandre Julliarda3960291999-02-26 11:11:13 +00004617 MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
Pascal Lessard47274231999-02-13 12:21:46 +00004618
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004619 return TRUE;
4620}
4621
4622/**********************************************************************
4623 * GetMenuItemRect16 (USER.665)
4624 */
4625
4626BOOL16 WINAPI GetMenuItemRect16 (HWND16 hwnd, HMENU16 hMenu, UINT16 uItem,
4627 LPRECT16 rect)
4628{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004629 RECT r32;
4630 BOOL res;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004631
4632 if (!rect) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004633 res = GetMenuItemRect (hwnd, hMenu, uItem, &r32);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004634 CONV_RECT32TO16 (&r32, rect);
4635 return res;
4636}
Paul Quinn1beaae51998-12-15 15:38:36 +00004637
4638/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004639 * SetMenuInfo
4640 *
4641 * FIXME
4642 * MIM_APPLYTOSUBMENUS
4643 * actually use the items to draw the menu
4644 */
4645BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
4646{
4647 POPUPMENU *menu;
4648
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004649 TRACE("(0x%04x %p)\n", hMenu, lpmi);
Juergen Schmied78513941999-04-18 14:40:32 +00004650
4651 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)USER_HEAP_LIN_ADDR(hMenu)))
4652 {
4653
4654 if (lpmi->fMask & MIM_BACKGROUND)
4655 menu->hbrBack = lpmi->hbrBack;
4656
4657 if (lpmi->fMask & MIM_HELPID)
4658 menu->dwContextHelpID = lpmi->dwContextHelpID;
4659
4660 if (lpmi->fMask & MIM_MAXHEIGHT)
4661 menu->cyMax = lpmi->cyMax;
4662
4663 if (lpmi->fMask & MIM_MENUDATA)
4664 menu->dwMenuData = lpmi->dwMenuData;
4665
4666 if (lpmi->fMask & MIM_STYLE)
4667 menu->dwStyle = lpmi->dwStyle;
4668
4669 return TRUE;
4670 }
4671 return FALSE;
4672}
4673
4674/**********************************************************************
4675 * GetMenuInfo
4676 *
4677 * NOTES
4678 * win98/NT5.0
4679 *
4680 */
4681BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
4682{ POPUPMENU *menu;
4683
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004684 TRACE("(0x%04x %p)\n", hMenu, lpmi);
Juergen Schmied78513941999-04-18 14:40:32 +00004685
4686 if (lpmi && (menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4687 {
4688
4689 if (lpmi->fMask & MIM_BACKGROUND)
4690 lpmi->hbrBack = menu->hbrBack;
4691
4692 if (lpmi->fMask & MIM_HELPID)
4693 lpmi->dwContextHelpID = menu->dwContextHelpID;
4694
4695 if (lpmi->fMask & MIM_MAXHEIGHT)
4696 lpmi->cyMax = menu->cyMax;
4697
4698 if (lpmi->fMask & MIM_MENUDATA)
4699 lpmi->dwMenuData = menu->dwMenuData;
4700
4701 if (lpmi->fMask & MIM_STYLE)
4702 lpmi->dwStyle = menu->dwStyle;
4703
4704 return TRUE;
4705 }
4706 return FALSE;
4707}
4708
4709/**********************************************************************
Paul Quinn1beaae51998-12-15 15:38:36 +00004710 * SetMenuContextHelpId16 (USER.384)
4711 */
Juergen Schmied78513941999-04-18 14:40:32 +00004712BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
Paul Quinn1beaae51998-12-15 15:38:36 +00004713{
Juergen Schmied78513941999-04-18 14:40:32 +00004714 return SetMenuContextHelpId( hMenu, dwContextHelpID );
Paul Quinn1beaae51998-12-15 15:38:36 +00004715}
4716
4717
4718/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004719 * SetMenuContextHelpId (USER32.488)
Paul Quinn1beaae51998-12-15 15:38:36 +00004720 */
Juergen Schmied78513941999-04-18 14:40:32 +00004721BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
Paul Quinn1beaae51998-12-15 15:38:36 +00004722{
Juergen Schmied78513941999-04-18 14:40:32 +00004723 LPPOPUPMENU menu;
4724
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004725 TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
Juergen Schmied78513941999-04-18 14:40:32 +00004726
4727 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4728 {
4729 menu->dwContextHelpID = dwContextHelpID;
4730 return TRUE;
4731 }
4732 return FALSE;
Paul Quinn1beaae51998-12-15 15:38:36 +00004733}
4734
4735/**********************************************************************
4736 * GetMenuContextHelpId16 (USER.385)
4737 */
4738DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
4739{
Juergen Schmied78513941999-04-18 14:40:32 +00004740 return GetMenuContextHelpId( hMenu );
Paul Quinn1beaae51998-12-15 15:38:36 +00004741}
4742
4743/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004744 * GetMenuContextHelpId (USER32.488)
Paul Quinn1beaae51998-12-15 15:38:36 +00004745 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004746DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
Paul Quinn1beaae51998-12-15 15:38:36 +00004747{
Juergen Schmied78513941999-04-18 14:40:32 +00004748 LPPOPUPMENU menu;
4749
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004750 TRACE("(0x%04x)\n", hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00004751
4752 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4753 {
4754 return menu->dwContextHelpID;
4755 }
4756 return 0;
Paul Quinn1beaae51998-12-15 15:38:36 +00004757}
Eric Pouech0c62bf01999-09-13 15:11:35 +00004758
4759/**********************************************************************
4760 * MenuItemFromPoint (USER32.387)
4761 */
4762UINT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen)
4763{
4764 FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
4765 hWnd, hMenu, ptScreen.x, ptScreen.y);
4766 return 0;
4767}