blob: 3002218be635cbe36c6579ae6d43bfd1e93651af [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/***********************************************************************
Rein Klazes80c924f1999-12-12 19:40:46 +0000582 * MENU_FindSubMenu
583 *
584 * Find a Sub menu. Return the position of the submenu, and modifies
585 * *hmenu in case it is found in another sub-menu.
586 * If the submenu cannot be found, NO_SELECTED_ITEM is returned.
587 */
588UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget )
589{
590 POPUPMENU *menu;
591 UINT i;
592 MENUITEM *item;
593 if (((*hmenu)==0xffff) ||
594 (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(*hmenu))))
595 return NO_SELECTED_ITEM;
596 item = menu->items;
597 for (i = 0; i < menu->nItems; i++, item++) {
598 if(!(item->fType & MF_POPUP)) continue;
599 if (item->hSubMenu == hSubTarget) {
600 return i;
601 }
602 else {
603 HMENU hsubmenu = item->hSubMenu;
604 UINT pos = MENU_FindSubMenu( &hsubmenu, hSubTarget );
605 if (pos != NO_SELECTED_ITEM) {
606 *hmenu = hsubmenu;
607 return pos;
608 }
609 }
610 }
611 return NO_SELECTED_ITEM;
612}
613
614/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000615 * MENU_FreeItemData
616 */
617static void MENU_FreeItemData( MENUITEM* item )
618{
619 /* delete text */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000620 if (IS_STRING_ITEM(item->fType) && item->text)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000621 HeapFree( SystemHeap, 0, item->text );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000622}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000623
624/***********************************************************************
625 * MENU_FindItemByCoords
626 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000627 * Find the item at the specified coordinates (screen coords). Does
628 * not work for child windows and therefore should not be called for
629 * an arbitrary system menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000630 */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000631static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000632 POINT pt, UINT *pos )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000633{
634 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000635 UINT i;
Marcus Meissnerac593bb1999-03-17 15:18:28 +0000636 RECT wrect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000637
Marcus Meissnerac593bb1999-03-17 15:18:28 +0000638 if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
639 pt.x -= wrect.left;pt.y -= wrect.top;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000640 item = menu->items;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000641 for (i = 0; i < menu->nItems; i++, item++)
642 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000643 if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
644 (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000645 {
646 if (pos) *pos = i;
647 return item;
648 }
649 }
650 return NULL;
651}
652
653
654/***********************************************************************
655 * MENU_FindItemByKey
656 *
657 * Find the menu item selected by a key press.
658 * Return item id, -1 if none, -2 if we should close the menu.
659 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000660static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
661 UINT key, BOOL forceMenuChar )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000662{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000663 TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000664
Alexandre Julliarda3960291999-02-26 11:11:13 +0000665 if (!IsMenu( hmenu ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000666 {
667 WND* w = WIN_FindWndPtr(hwndOwner);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000668 hmenu = GetSubMenu(w->hSysMenu, 0);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000669 WIN_ReleaseWndPtr(w);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000670 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000671
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000672 if (hmenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000673 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000674 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
675 MENUITEM *item = menu->items;
676 LONG menuchar;
677
678 if( !forceMenuChar )
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000679 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000680 UINT i;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000681
682 key = toupper(key);
683 for (i = 0; i < menu->nItems; i++, item++)
684 {
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000685 if (item->text && (IS_STRING_ITEM(item->fType)))
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000686 {
Norman Stevensa83d0651998-10-12 07:25:35 +0000687 char *p = item->text - 2;
688 do
689 {
690 p = strchr (p + 2, '&');
691 }
692 while (p != NULL && p [1] == '&');
693 if (p && (toupper(p[1]) == key)) return i;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000694 }
695 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000696 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000697 menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000698 MAKEWPARAM( key, menu->wFlags ), hmenu );
699 if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000700 if (HIWORD(menuchar) == 1) return (UINT)(-2);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000701 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000702 return (UINT)(-1);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000703}
Francois Boisvert8b391741999-02-09 14:09:55 +0000704/***********************************************************************
705 * MENU_LoadMagicItem
706 *
707 * Load the bitmap associated with the magic menu item and its style
708 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000709
Juergen Schmied78513941999-04-18 14:40:32 +0000710static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
Francois Boisvert8b391741999-02-09 14:09:55 +0000711{
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000712 /*
713 * Magic menu item id's section
714 * These magic id's are used by windows to insert "standard" mdi
715 * buttons (minimize,restore,close) on menu. Under windows,
716 * these magic id's make sure the right things appear when those
717 * bitmap buttons are pressed/selected/released.
718 */
Francois Boisvert8b391741999-02-09 14:09:55 +0000719
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000720 switch(id & 0xffff)
Juergen Schmied78513941999-04-18 14:40:32 +0000721 { case HBMMENU_SYSTEM:
722 return (dwItemData) ?
723 (HBITMAP)dwItemData :
724 (hilite ? hBmpMinimizeD : hBmpMinimize);
725 case HBMMENU_MBAR_RESTORE:
726 return (hilite ? hBmpMaximizeD: hBmpMaximize);
727 case HBMMENU_MBAR_MINIMIZE:
728 return (hilite ? hBmpMinimizeD : hBmpMinimize);
729 case HBMMENU_MBAR_CLOSE:
730 return (hilite ? hBmpCloseD : hBmpClose);
731 case HBMMENU_CALLBACK:
732 case HBMMENU_MBAR_CLOSE_D:
733 case HBMMENU_MBAR_MINIMIZE_D:
734 case HBMMENU_POPUP_CLOSE:
735 case HBMMENU_POPUP_RESTORE:
736 case HBMMENU_POPUP_MAXIMIZE:
737 case HBMMENU_POPUP_MINIMIZE:
738 default:
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000739 FIXME("Magic 0x%08x not implemented\n", id);
Juergen Schmied78513941999-04-18 14:40:32 +0000740 return 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000741 }
742
743}
Alexandre Julliardf7207251994-07-23 07:57:48 +0000744
745/***********************************************************************
746 * MENU_CalcItemSize
747 *
748 * Calculate the size of the menu item and store it in lpitem->rect.
749 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000750static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
751 INT orgX, INT orgY, BOOL menuBar )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000752{
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000753 char *p;
754
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000755 TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000756 debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
757 (menuBar ? " (MenuBar)" : ""));
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000758
Alexandre Julliarda3960291999-02-26 11:11:13 +0000759 SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000760
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000761 if (lpitem->fType & MF_OWNERDRAW)
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000762 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000763 MEASUREITEMSTRUCT mis;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000764 mis.CtlType = ODT_MENU;
Juergen Schmied7abca951999-04-11 17:02:30 +0000765 mis.CtlID = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000766 mis.itemID = lpitem->wID;
Juergen Schmied7abca951999-04-11 17:02:30 +0000767 mis.itemData = (DWORD)lpitem->dwItemData;
768 mis.itemHeight = 0;
769 mis.itemWidth = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000770 SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000771 lpitem->rect.bottom += mis.itemHeight;
772 lpitem->rect.right += mis.itemWidth;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000773 TRACE("id=%04x size=%dx%d\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000774 lpitem->wID, mis.itemWidth, mis.itemHeight);
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000775 return;
Alexandre Julliardfa68b751995-04-03 16:55:37 +0000776 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000777
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000778 if (lpitem->fType & MF_SEPARATOR)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000779 {
780 lpitem->rect.bottom += SEPARATOR_HEIGHT;
781 return;
782 }
783
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000784 if (!menuBar)
785 {
786 lpitem->rect.right += 2 * check_bitmap_width;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000787 if (lpitem->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000788 lpitem->rect.right += arrow_bitmap_width;
789 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000790
Juergen Schmied78513941999-04-18 14:40:32 +0000791 if (IS_BITMAP_ITEM(lpitem->fType))
Alexandre Julliardf7207251994-07-23 07:57:48 +0000792 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000793 BITMAP bm;
Juergen Schmied78513941999-04-18 14:40:32 +0000794 HBITMAP resBmp = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000795
Patrik Stridvall1bb94031999-05-08 15:47:44 +0000796 /* Check if there is a magic menu item associated with this item */
Juergen Schmied78513941999-04-18 14:40:32 +0000797 if((LOWORD((int)lpitem->text))<12)
798 {
799 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
800 lpitem->dwItemData);
Francois Boisvert8b391741999-02-09 14:09:55 +0000801 }
802 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000803 resBmp = (HBITMAP)lpitem->text;
Francois Boisvert8b391741999-02-09 14:09:55 +0000804
Alexandre Julliarda3960291999-02-26 11:11:13 +0000805 if (GetObjectA(resBmp, sizeof(bm), &bm ))
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000806 {
807 lpitem->rect.right += bm.bmWidth;
808 lpitem->rect.bottom += bm.bmHeight;
Francois Boisvert8b391741999-02-09 14:09:55 +0000809
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000810 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000811 }
812
Juergen Schmied78513941999-04-18 14:40:32 +0000813
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000814 /* If we get here, then it must be a text item */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000815 if (IS_STRING_ITEM( lpitem->fType ))
Juergen Schmied78513941999-04-18 14:40:32 +0000816 { SIZE size;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000817
Juergen Schmied78513941999-04-18 14:40:32 +0000818 GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
819
820 lpitem->rect.right += size.cx;
821 if (TWEAK_WineLook == WIN31_LOOK)
Marcus Meissnerddca3151999-05-22 11:33:23 +0000822 lpitem->rect.bottom += MAX( size.cy, GetSystemMetrics(SM_CYMENU) );
Juergen Schmied78513941999-04-18 14:40:32 +0000823 else
Marcus Meissnerddca3151999-05-22 11:33:23 +0000824 lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
Juergen Schmied78513941999-04-18 14:40:32 +0000825 lpitem->xTab = 0;
826
827 if (menuBar)
828 {
829 lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
830 }
831 else if ((p = strchr( lpitem->text, '\t' )) != NULL)
832 {
833 /* Item contains a tab (only meaningful in popup menus) */
834 GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
835 lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
836 lpitem->rect.right += MENU_TAB_SPACE;
837 }
838 else
839 {
840 if (strchr( lpitem->text, '\b' ))
841 lpitem->rect.right += MENU_TAB_SPACE;
842 lpitem->xTab = lpitem->rect.right - check_bitmap_width
843 - arrow_bitmap_width;
844 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000845 }
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000846 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 +0000847}
848
849
850/***********************************************************************
851 * MENU_PopupMenuCalcSize
852 *
853 * Calculate the size of a popup menu.
854 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000855static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000856{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000857 MENUITEM *lpitem;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000858 HDC hdc;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000859 int start, i;
860 int orgX, orgY, maxX, maxTab, maxTabWidth;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000861
Alexandre Julliardf7207251994-07-23 07:57:48 +0000862 lppop->Width = lppop->Height = 0;
863 if (lppop->nItems == 0) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000864 hdc = GetDC( 0 );
Juergen Schmied78513941999-04-18 14:40:32 +0000865
866 SelectObject( hdc, hMenuFont);
867
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000868 start = 0;
Marcus Meissnerddca3151999-05-22 11:33:23 +0000869 maxX = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CXBORDER) : 2 ;
Juergen Schmied466a6521999-05-02 11:21:08 +0000870
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000871 while (start < lppop->nItems)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000872 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000873 lpitem = &lppop->items[start];
Alexandre Julliardf7207251994-07-23 07:57:48 +0000874 orgX = maxX;
Marcus Meissnerddca3151999-05-22 11:33:23 +0000875 orgY = (TWEAK_WineLook == WIN31_LOOK) ? GetSystemMetrics(SM_CYBORDER) : 2;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000876
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000877 maxTab = maxTabWidth = 0;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000878
879 /* Parse items until column break or end of menu */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000880 for (i = start; i < lppop->nItems; i++, lpitem++)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000881 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000882 if ((i != start) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000883 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000884
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000885 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
Pascal Lessard47274231999-02-13 12:21:46 +0000886
Juergen Schmied466a6521999-05-02 11:21:08 +0000887 if (lpitem->fType & MF_MENUBARBREAK) orgX++;
Alexandre Julliard902da691995-11-05 14:39:02 +0000888 maxX = MAX( maxX, lpitem->rect.right );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000889 orgY = lpitem->rect.bottom;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000890 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000891 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000892 maxTab = MAX( maxTab, lpitem->xTab );
893 maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000894 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000895 }
896
897 /* Finish the column (set all items to the largest width found) */
Alexandre Julliard902da691995-11-05 14:39:02 +0000898 maxX = MAX( maxX, maxTab + maxTabWidth );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000899 for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000900 {
901 lpitem->rect.right = maxX;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000902 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
Juergen Schmied466a6521999-05-02 11:21:08 +0000903 lpitem->xTab = maxTab;
904
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000905 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000906 lppop->Height = MAX( lppop->Height, orgY );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000907 }
908
909 lppop->Width = maxX;
Juergen Schmied466a6521999-05-02 11:21:08 +0000910
911 /* space for 3d border */
912 if(TWEAK_WineLook > WIN31_LOOK)
913 {
914 lppop->Height += 2;
915 lppop->Width += 2;
916 }
917
Alexandre Julliarda3960291999-02-26 11:11:13 +0000918 ReleaseDC( 0, hdc );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000919}
920
921
922/***********************************************************************
923 * MENU_MenuBarCalcSize
924 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000925 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000926 * height is off by 1 pixel which causes lengthy window relocations when
927 * active document window is maximized/restored.
928 *
Alexandre Julliardf7207251994-07-23 07:57:48 +0000929 * Calculate the size of the menu bar.
930 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000931static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
932 LPPOPUPMENU lppop, HWND hwndOwner )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000933{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000934 MENUITEM *lpitem;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000935 int start, i, orgX, orgY, maxY, helpPos;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000936
937 if ((lprect == NULL) || (lppop == NULL)) return;
938 if (lppop->nItems == 0) return;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000939 TRACE("left=%d top=%d right=%d bottom=%d\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000940 lprect->left, lprect->top, lprect->right, lprect->bottom);
Alexandre Julliardf7207251994-07-23 07:57:48 +0000941 lppop->Width = lprect->right - lprect->left;
942 lppop->Height = 0;
943 maxY = lprect->top;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000944 start = 0;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000945 helpPos = -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000946 while (start < lppop->nItems)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000947 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000948 lpitem = &lppop->items[start];
Alexandre Julliardf7207251994-07-23 07:57:48 +0000949 orgX = lprect->left;
950 orgY = maxY;
951
952 /* Parse items until line break or end of menu */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000953 for (i = start; i < lppop->nItems; i++, lpitem++)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000954 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000955 if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000956 if ((i != start) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000957 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000958
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000959 TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000960 orgX, orgY );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000961 debug_print_menuitem (" item: ", lpitem, "");
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000962 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
Pascal Lessard47274231999-02-13 12:21:46 +0000963
Alexandre Julliardf7207251994-07-23 07:57:48 +0000964 if (lpitem->rect.right > lprect->right)
965 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000966 if (i != start) break;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000967 else lpitem->rect.right = lprect->right;
968 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000969 maxY = MAX( maxY, lpitem->rect.bottom );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000970 orgX = lpitem->rect.right;
971 }
972
973 /* Finish the line (set all items to the largest height found) */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000974 while (start < i) lppop->items[start++].rect.bottom = maxY;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000975 }
976
977 lprect->bottom = maxY;
978 lppop->Height = lprect->bottom - lprect->top;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000979
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000980 /* Flush right all magic items and items between the MF_HELP and */
981 /* the last item (if several lines, only move the last line) */
982 lpitem = &lppop->items[lppop->nItems-1];
983 orgY = lpitem->rect.top;
984 orgX = lprect->right;
985 for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000986 {
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +0000987 if ( !IS_BITMAP_ITEM(lpitem->fType) && ((helpPos ==-1) ? TRUE : (helpPos>i) ))
988 break; /* done */
989 if (lpitem->rect.top != orgY) break; /* Other line */
990 if (lpitem->rect.right >= orgX) break; /* Too far right already */
991 lpitem->rect.left += orgX - lpitem->rect.right;
992 lpitem->rect.right = orgX;
993 orgX = lpitem->rect.left;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000994 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000995}
996
Alexandre Julliardf7207251994-07-23 07:57:48 +0000997/***********************************************************************
998 * MENU_DrawMenuItem
999 *
1000 * Draw a single menu item.
1001 */
Juergen Schmied78513941999-04-18 14:40:32 +00001002static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
Alexandre Julliarda3960291999-02-26 11:11:13 +00001003 UINT height, BOOL menuBar, UINT odaction )
Alexandre Julliardf7207251994-07-23 07:57:48 +00001004{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001005 RECT rect;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001006
Alexandre Julliard03468f71998-02-15 19:40:49 +00001007 debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001008
1009 if (lpitem->fType & MF_SYSMENU)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001010 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001011 if( !IsIconic(hwnd) ) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001012 if (TWEAK_WineLook > WIN31_LOOK)
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001013 NC_DrawSysButton95( hwnd, hdc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001014 lpitem->fState &
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001015 (MF_HILITE | MF_MOUSESELECT) );
1016 else
1017 NC_DrawSysButton( hwnd, hdc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001018 lpitem->fState &
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001019 (MF_HILITE | MF_MOUSESELECT) );
1020 }
1021
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001022 return;
1023 }
1024
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001025 if (lpitem->fType & MF_OWNERDRAW)
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001026 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001027 DRAWITEMSTRUCT dis;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001028
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001029 dis.CtlType = ODT_MENU;
Juergen Schmied7abca951999-04-11 17:02:30 +00001030 dis.CtlID = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001031 dis.itemID = lpitem->wID;
Juergen Schmied7abca951999-04-11 17:02:30 +00001032 dis.itemData = (DWORD)lpitem->dwItemData;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001033 dis.itemState = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001034 if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
1035 if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
1036 if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001037 dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
Juergen Schmied78513941999-04-18 14:40:32 +00001038 dis.hwndItem = hmenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001039 dis.hDC = hdc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001040 dis.rcItem = lpitem->rect;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001041 TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
Juergen Schmied78513941999-04-18 14:40:32 +00001042 "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
1043 dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
1044 dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
1045 dis.rcItem.bottom);
1046 SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001047 return;
Alexandre Julliardfa68b751995-04-03 16:55:37 +00001048 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001049
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001050 TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
Juergen Schmied78513941999-04-18 14:40:32 +00001051 lpitem->rect.right,lpitem->rect.bottom);
1052
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001053 if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
Juergen Schmied78513941999-04-18 14:40:32 +00001054
Alexandre Julliardf7207251994-07-23 07:57:48 +00001055 rect = lpitem->rect;
1056
Juergen Schmied466a6521999-05-02 11:21:08 +00001057 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
Juergen Schmied78513941999-04-18 14:40:32 +00001058 if ((menuBar) && (TWEAK_WineLook==WIN98_LOOK))
1059 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
1060 else
1061 FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001062 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001063 FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001064
Alexandre Julliarda3960291999-02-26 11:11:13 +00001065 SetBkMode( hdc, TRANSPARENT );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001066
Juergen Schmied78513941999-04-18 14:40:32 +00001067 /* vertical separator */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001068 if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
Alexandre Julliardf7207251994-07-23 07:57:48 +00001069 {
Juergen Schmied78513941999-04-18 14:40:32 +00001070 if (TWEAK_WineLook > WIN31_LOOK)
1071 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001072 RECT rc = rect;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001073 rc.top = 3;
1074 rc.bottom = height - 3;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001075 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001076 }
Juergen Schmied78513941999-04-18 14:40:32 +00001077 else
1078 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001079 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1080 MoveTo16( hdc, rect.left, 0 );
1081 LineTo( hdc, rect.left, height );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001082 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001083 }
Juergen Schmied78513941999-04-18 14:40:32 +00001084
1085 /* horizontal separator */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001086 if (lpitem->fType & MF_SEPARATOR)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001087 {
Juergen Schmied78513941999-04-18 14:40:32 +00001088 if (TWEAK_WineLook > WIN31_LOOK)
1089 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001090 RECT rc = rect;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001091 rc.left++;
1092 rc.right--;
1093 rc.top += SEPARATOR_HEIGHT / 2;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001094 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001095 }
Juergen Schmied78513941999-04-18 14:40:32 +00001096 else
1097 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001098 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1099 MoveTo16( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2 );
1100 LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001101 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001102 return;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001103 }
1104
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001105 /* Setup colors */
1106
Juergen Schmied78513941999-04-18 14:40:32 +00001107 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001108 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001109 if (lpitem->fState & MF_GRAYED)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001110 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001111 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001112 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
1113 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001114 }
1115 else
1116 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001117 if (lpitem->fState & MF_GRAYED)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001118 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001119 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001120 SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
1121 SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001122 }
1123
Juergen Schmied78513941999-04-18 14:40:32 +00001124 /* helper lines for debugging */
1125/* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1126 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1127 MoveTo16( hdc, rect.left, (rect.top + rect.bottom)/2 );
1128 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1129*/
1130
Alexandre Julliardf7207251994-07-23 07:57:48 +00001131 if (!menuBar)
1132 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001133 INT y = rect.top + rect.bottom;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001134
1135 /* Draw the check mark
1136 *
Huw D M Davies2d617be1998-12-08 09:14:09 +00001137 * FIXME:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001138 * Custom checkmark bitmaps are monochrome but not always 1bpp.
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001139 */
Alexandre Julliardf7207251994-07-23 07:57:48 +00001140
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001141 if (lpitem->fState & MF_CHECKED)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001142 {
Juergen Schmied78513941999-04-18 14:40:32 +00001143 HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
1144 ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001145 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001146
Alexandre Julliarda3960291999-02-26 11:11:13 +00001147 SelectObject( hdcMem, bm );
Juergen Schmied78513941999-04-18 14:40:32 +00001148 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001149 check_bitmap_width, check_bitmap_height,
1150 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001151 DeleteDC( hdcMem );
Juergen Schmied78513941999-04-18 14:40:32 +00001152 }
1153 else if (lpitem->hUnCheckBit)
1154 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001155 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001156
Alexandre Julliarda3960291999-02-26 11:11:13 +00001157 SelectObject( hdcMem, lpitem->hUnCheckBit );
Juergen Schmied78513941999-04-18 14:40:32 +00001158 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001159 check_bitmap_width, check_bitmap_height,
1160 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001161 DeleteDC( hdcMem );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001162 }
Juergen Schmied78513941999-04-18 14:40:32 +00001163
Alexandre Julliardf7207251994-07-23 07:57:48 +00001164 /* Draw the popup-menu arrow */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001165 if (lpitem->fType & MF_POPUP)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001166 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001167 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001168
Alexandre Julliarda3960291999-02-26 11:11:13 +00001169 SelectObject( hdcMem, hStdMnArrow );
Juergen Schmied78513941999-04-18 14:40:32 +00001170 BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001171 (y - arrow_bitmap_height) / 2,
1172 arrow_bitmap_width, arrow_bitmap_height,
1173 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001174 DeleteDC( hdcMem );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001175 }
1176
1177 rect.left += check_bitmap_width;
1178 rect.right -= arrow_bitmap_width;
1179 }
1180
Juergen Schmied78513941999-04-18 14:40:32 +00001181 /* Draw the item text or bitmap */
1182 if (IS_BITMAP_ITEM(lpitem->fType))
1183 { int top;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001184
Alexandre Julliarda3960291999-02-26 11:11:13 +00001185 HBITMAP resBmp = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +00001186
Alexandre Julliarda3960291999-02-26 11:11:13 +00001187 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001188
Patrik Stridvall1bb94031999-05-08 15:47:44 +00001189 /*
1190 * Check if there is a magic menu item associated with this item
1191 * and load the appropriate bitmap
1192 */
Juergen Schmied78513941999-04-18 14:40:32 +00001193 if((LOWORD((int)lpitem->text)) < 12)
1194 {
1195 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
1196 lpitem->dwItemData);
Francois Boisvert8b391741999-02-09 14:09:55 +00001197 }
1198 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001199 resBmp = (HBITMAP)lpitem->text;
Juergen Schmied78513941999-04-18 14:40:32 +00001200
1201 if (resBmp)
1202 {
1203 BITMAP bm;
1204 GetObjectA( resBmp, sizeof(bm), &bm );
1205
1206 SelectObject(hdcMem,resBmp );
1207
1208 /* handle fontsize > bitmap_height */
1209 top = ((rect.bottom-rect.top)>bm.bmHeight) ?
1210 rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
1211
1212 BitBlt( hdc, rect.left, top, rect.right - rect.left,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001213 rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
Juergen Schmied78513941999-04-18 14:40:32 +00001214 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001215 DeleteDC( hdcMem );
Juergen Schmied78513941999-04-18 14:40:32 +00001216
Alexandre Julliardf7207251994-07-23 07:57:48 +00001217 return;
Francois Boisvert8b391741999-02-09 14:09:55 +00001218
Alexandre Julliardf7207251994-07-23 07:57:48 +00001219 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001220 /* No bitmap - process text if present */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001221 else if (IS_STRING_ITEM(lpitem->fType))
Alexandre Julliardf7207251994-07-23 07:57:48 +00001222 {
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001223 register int i;
Juergen Schmied466a6521999-05-02 11:21:08 +00001224 HFONT hfontOld = 0;
1225
Juergen Schmied78513941999-04-18 14:40:32 +00001226 UINT uFormat = (menuBar) ?
1227 DT_CENTER | DT_VCENTER | DT_SINGLELINE :
1228 DT_LEFT | DT_VCENTER | DT_SINGLELINE;
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001229
Juergen Schmied466a6521999-05-02 11:21:08 +00001230 if ( lpitem->fState & MFS_DEFAULT )
1231 {
1232 hfontOld = SelectObject( hdc, hMenuFontBold);
1233 }
1234
Alexandre Julliardf7207251994-07-23 07:57:48 +00001235 if (menuBar)
1236 {
1237 rect.left += MENU_BAR_ITEMS_SPACE / 2;
1238 rect.right -= MENU_BAR_ITEMS_SPACE / 2;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001239 i = strlen( lpitem->text );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001240 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001241 else
Alexandre Julliardf7207251994-07-23 07:57:48 +00001242 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001243 for (i = 0; lpitem->text[i]; i++)
Juergen Schmied466a6521999-05-02 11:21:08 +00001244 if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
1245 break;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001246 }
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001247
Juergen Schmied466a6521999-05-02 11:21:08 +00001248 if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
Juergen Schmied78513941999-04-18 14:40:32 +00001249 {
Juergen Schmied466a6521999-05-02 11:21:08 +00001250 if (!(lpitem->fState & MF_HILITE) )
Juergen Schmied78513941999-04-18 14:40:32 +00001251 {
Juergen Schmied466a6521999-05-02 11:21:08 +00001252 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001253 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
Juergen Schmied78513941999-04-18 14:40:32 +00001254 DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
Juergen Schmied466a6521999-05-02 11:21:08 +00001255 --rect.left; --rect.top; --rect.right; --rect.bottom;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001256 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001257 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001258 }
Juergen Schmied466a6521999-05-02 11:21:08 +00001259
1260 DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001261
Juergen Schmied466a6521999-05-02 11:21:08 +00001262 /* paint the shortcut text */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001263 if (lpitem->text[i]) /* There's a tab or flush-right char */
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001264 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001265 if (lpitem->text[i] == '\t')
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001266 {
1267 rect.left = lpitem->xTab;
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +00001268 uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001269 }
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +00001270 else
1271 {
1272 uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
1273 }
1274
Juergen Schmied466a6521999-05-02 11:21:08 +00001275 if( !(TWEAK_WineLook == WIN31_LOOK) && (lpitem->fState & MF_GRAYED))
1276 {
1277 if (!(lpitem->fState & MF_HILITE) )
1278 {
1279 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
1280 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
1281 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
1282 --rect.left; --rect.top; --rect.right; --rect.bottom;
1283 }
1284 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
1285 }
Juergen Schmiedcd0ed1e1999-04-26 14:54:38 +00001286 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001287 }
Juergen Schmied466a6521999-05-02 11:21:08 +00001288
1289 if (hfontOld)
1290 SelectObject (hdc, hfontOld);
Alexandre Julliardf7207251994-07-23 07:57:48 +00001291 }
1292}
1293
1294
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001295/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001296 * MENU_DrawPopupMenu
1297 *
1298 * Paint a popup menu.
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001299 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001300static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001301{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001302 HBRUSH hPrevBrush = 0;
1303 RECT rect;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001304
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001305 TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
Juergen Schmied78513941999-04-18 14:40:32 +00001306
Alexandre Julliarda3960291999-02-26 11:11:13 +00001307 GetClientRect( hwnd, &rect );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001308
Alex Korobka44a1b591999-04-01 12:03:52 +00001309 if(TWEAK_WineLook == WIN31_LOOK)
1310 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001311 rect.bottom -= POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
1312 rect.right -= POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER);
Alex Korobka44a1b591999-04-01 12:03:52 +00001313 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001314
Juergen Schmied78513941999-04-18 14:40:32 +00001315 if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
1316 && (SelectObject( hdc, hMenuFont)))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001317 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001318 HPEN hPrevPen;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001319
Alexandre Julliarda3960291999-02-26 11:11:13 +00001320 Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001321
Alexandre Julliarda3960291999-02-26 11:11:13 +00001322 hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001323 if( hPrevPen )
1324 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001325 INT ropPrev, i;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001326 POPUPMENU *menu;
1327
1328 /* draw 3-d shade */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001329 if(TWEAK_WineLook == WIN31_LOOK) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001330 SelectObject( hdc, hShadeBrush );
1331 SetBkMode( hdc, TRANSPARENT );
1332 ropPrev = SetROP2( hdc, R2_MASKPEN );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001333
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001334 i = rect.right; /* why SetBrushOrg() doesn't? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001335 PatBlt( hdc, i & 0xfffffffe,
Marcus Meissnerddca3151999-05-22 11:33:23 +00001336 rect.top + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER),
1337 i%2 + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001338 rect.bottom - rect.top, 0x00a000c9 );
1339 i = rect.bottom;
Marcus Meissnerddca3151999-05-22 11:33:23 +00001340 PatBlt( hdc, rect.left + POPUP_XSHADE*GetSystemMetrics(SM_CXBORDER),
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001341 i & 0xfffffffe,rect.right - rect.left,
Marcus Meissnerddca3151999-05-22 11:33:23 +00001342 i%2 + POPUP_YSHADE*GetSystemMetrics(SM_CYBORDER), 0x00a000c9 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001343 SelectObject( hdc, hPrevPen );
1344 SelectObject( hdc, hPrevBrush );
1345 SetROP2( hdc, ropPrev );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001346 }
1347 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001348 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001349
1350 /* draw menu items */
1351
1352 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1353 if (menu && menu->nItems)
1354 {
1355 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001356 UINT u;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001357
1358 for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
Juergen Schmied78513941999-04-18 14:40:32 +00001359 MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
1360 menu->Height, FALSE, ODA_DRAWENTIRE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001361
1362 }
Juergen Schmied78513941999-04-18 14:40:32 +00001363 } else
1364 {
1365 SelectObject( hdc, hPrevBrush );
1366 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001367 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001368}
1369
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001370/***********************************************************************
1371 * MENU_DrawMenuBar
1372 *
1373 * Paint a menu bar. Returns the height of the menu bar.
Juergen Schmied78513941999-04-18 14:40:32 +00001374 * called from [windows/nonclient.c]
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001375 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001376UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
1377 BOOL suppress_draw)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001378{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001379 LPPOPUPMENU lppop;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001380 UINT i,retvalue;
Juergen Schmied78513941999-04-18 14:40:32 +00001381 HFONT hfontOld = 0;
1382
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001383 WND *wndPtr = WIN_FindWndPtr( hwnd );
1384
Juergen Schmied78513941999-04-18 14:40:32 +00001385 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( (HMENU)wndPtr->wIDmenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001386 if (lppop == NULL || lprect == NULL)
1387 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001388 retvalue = GetSystemMetrics(SM_CYMENU);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001389 goto END;
1390 }
Juergen Schmied78513941999-04-18 14:40:32 +00001391
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001392 TRACE("(%04x, %p, %p)\n", hDC, lprect, lppop);
Juergen Schmied78513941999-04-18 14:40:32 +00001393
1394 hfontOld = SelectObject( hDC, hMenuFont);
1395
1396 if (lppop->Height == 0)
1397 MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
1398
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001399 lprect->bottom = lprect->top + lppop->Height;
Juergen Schmied78513941999-04-18 14:40:32 +00001400
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001401 if (suppress_draw)
1402 {
1403 retvalue = lppop->Height;
1404 goto END;
1405 }
Juergen Schmied78513941999-04-18 14:40:32 +00001406
Alexandre Julliarda3960291999-02-26 11:11:13 +00001407 FillRect(hDC, lprect, GetSysColorBrush(COLOR_MENU) );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001408
Juergen Schmied78513941999-04-18 14:40:32 +00001409 if (TWEAK_WineLook == WIN31_LOOK)
1410 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001411 SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
1412 MoveTo16( hDC, lprect->left, lprect->bottom );
1413 LineTo( hDC, lprect->right, lprect->bottom );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001414 }
Juergen Schmied78513941999-04-18 14:40:32 +00001415 else
1416 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001417 SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
1418 MoveTo16( hDC, lprect->left, lprect->bottom );
1419 LineTo( hDC, lprect->right, lprect->bottom );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001420 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001421
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001422 if (lppop->nItems == 0)
1423 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001424 retvalue = GetSystemMetrics(SM_CYMENU);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001425 goto END;
1426 }
Juergen Schmied78513941999-04-18 14:40:32 +00001427
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001428 for (i = 0; i < lppop->nItems; i++)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001429 {
Juergen Schmied78513941999-04-18 14:40:32 +00001430 MENU_DrawMenuItem( hwnd, (HMENU)wndPtr->wIDmenu, GetWindow(hwnd,GW_OWNER),
1431 hDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001432 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001433 retvalue = lppop->Height;
Juergen Schmied78513941999-04-18 14:40:32 +00001434
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001435END:
Juergen Schmied78513941999-04-18 14:40:32 +00001436 if (hfontOld)
1437 SelectObject (hDC, hfontOld);
1438
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001439 WIN_ReleaseWndPtr(wndPtr);
1440 return retvalue;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001441}
1442
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001443/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001444 * MENU_PatchResidentPopup
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001445 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001446BOOL MENU_PatchResidentPopup( HQUEUE16 checkQueue, WND* checkWnd )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001447{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001448 WND *pTPWnd = MENU_GetTopPopupWnd();
1449
1450 if( pTPWnd )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001451 {
1452 HTASK16 hTask = 0;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001453
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001454 TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001455 checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
1456 pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001457
Alexandre Julliard77b99181997-09-14 17:17:23 +00001458 switch( checkQueue )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001459 {
Alexandre Julliard77b99181997-09-14 17:17:23 +00001460 case 0: /* checkWnd is the new popup owner */
1461 if( checkWnd )
1462 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001463 pTPWnd->owner = checkWnd;
1464 if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
Alexandre Julliard77b99181997-09-14 17:17:23 +00001465 hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
1466 }
1467 break;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001468
Alexandre Julliard77b99181997-09-14 17:17:23 +00001469 case 0xFFFF: /* checkWnd is destroyed */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001470 if( pTPWnd->owner == checkWnd )
1471 pTPWnd->owner = NULL;
1472 MENU_ReleaseTopPopupWnd();
Alexandre Julliard77b99181997-09-14 17:17:23 +00001473 return TRUE;
1474
1475 default: /* checkQueue is exiting */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001476 if( pTPWnd->hmemTaskQ == checkQueue )
Alexandre Julliard77b99181997-09-14 17:17:23 +00001477 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001478 hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
Alexandre Julliard77b99181997-09-14 17:17:23 +00001479 hTask = TASK_GetNextTask( hTask );
1480 }
1481 break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001482 }
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001483
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001484 if( hTask )
1485 {
1486 TDB* task = (TDB*)GlobalLock16( hTask );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001487 if( task )
1488 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001489 pTPWnd->hInstance = task->hInstance;
1490 pTPWnd->hmemTaskQ = task->hQueue;
1491 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001492 return TRUE;
1493 }
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001494 else WARN("failed to patch resident popup.\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001495 }
1496 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001497 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001498 return FALSE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001499}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001500
1501/***********************************************************************
1502 * MENU_ShowPopup
1503 *
1504 * Display a popup menu.
1505 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001506static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
1507 INT x, INT y, INT xanchor, INT yanchor )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001508{
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001509 POPUPMENU *menu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001510 WND *wndOwner = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001511
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001512 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 +00001513 hwndOwner, hmenu, id, x, y, xanchor, yanchor);
1514
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001515 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001516 if (menu->FocusedItem != NO_SELECTED_ITEM)
1517 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001518 menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001519 menu->FocusedItem = NO_SELECTED_ITEM;
1520 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001521
Juergen Schmied78513941999-04-18 14:40:32 +00001522 /* store the owner for DrawItem*/
1523 menu->hwndOwner = hwndOwner;
1524
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001525 if( (wndOwner = WIN_FindWndPtr( hwndOwner )) )
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001526 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001527 UINT width, height;
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001528
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001529 MENU_PopupMenuCalcSize( menu, hwndOwner );
1530
1531 /* adjust popup menu pos so that it fits within the desktop */
1532
Marcus Meissnerddca3151999-05-22 11:33:23 +00001533 width = menu->Width + GetSystemMetrics(SM_CXBORDER);
1534 height = menu->Height + GetSystemMetrics(SM_CYBORDER);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001535
Marcus Meissnerddca3151999-05-22 11:33:23 +00001536 if( x + width > GetSystemMetrics(SM_CXSCREEN ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001537 {
1538 if( xanchor )
1539 x -= width - xanchor;
Marcus Meissnerddca3151999-05-22 11:33:23 +00001540 if( x + width > GetSystemMetrics(SM_CXSCREEN))
1541 x = GetSystemMetrics(SM_CXSCREEN) - width;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001542 }
1543 if( x < 0 ) x = 0;
1544
Marcus Meissnerddca3151999-05-22 11:33:23 +00001545 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001546 {
1547 if( yanchor )
1548 y -= height + yanchor;
Marcus Meissnerddca3151999-05-22 11:33:23 +00001549 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
1550 y = GetSystemMetrics(SM_CYSCREEN) - height;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001551 }
1552 if( y < 0 ) y = 0;
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001553
Alex Korobka44a1b591999-04-01 12:03:52 +00001554 if( TWEAK_WineLook == WIN31_LOOK )
1555 {
Marcus Meissnerddca3151999-05-22 11:33:23 +00001556 width += POPUP_XSHADE * GetSystemMetrics(SM_CXBORDER); /* add space for shading */
1557 height += POPUP_YSHADE * GetSystemMetrics(SM_CYBORDER);
Alex Korobka44a1b591999-04-01 12:03:52 +00001558 }
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001559
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001560 /* NOTE: In Windows, top menu popup is not owned. */
1561 if (!pTopPopupWnd) /* create top level popup menu window */
1562 {
1563 assert( uSubPWndLevel == 0 );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001564
Alexandre Julliarda3960291999-02-26 11:11:13 +00001565 pTopPopupWnd = WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001566 WS_POPUP, x, y, width, height,
1567 hwndOwner, 0, wndOwner->hInstance,
1568 (LPVOID)hmenu ));
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001569 if (!pTopPopupWnd)
1570 {
1571 WIN_ReleaseWndPtr(wndOwner);
1572 return FALSE;
1573 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001574 menu->hWnd = pTopPopupWnd->hwndSelf;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001575 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001576 }
1577 else
1578 if( uSubPWndLevel )
1579 {
1580 /* create a new window for the submenu */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001581
Alexandre Julliarda3960291999-02-26 11:11:13 +00001582 menu->hWnd = CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001583 WS_POPUP, x, y, width, height,
Juergen Schmied78513941999-04-18 14:40:32 +00001584 hwndOwner, 0, wndOwner->hInstance,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001585 (LPVOID)hmenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001586 if( !menu->hWnd )
1587 {
1588 WIN_ReleaseWndPtr(wndOwner);
1589 return FALSE;
1590 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001591 }
1592 else /* top level popup menu window already exists */
1593 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001594 WND *pTPWnd = MENU_GetTopPopupWnd();
1595 menu->hWnd = pTPWnd->hwndSelf;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001596
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001597 MENU_PatchResidentPopup( 0, wndOwner );
Juergen Schmied78513941999-04-18 14:40:32 +00001598 SendMessageA( pTPWnd->hwndSelf, MM_SETMENUHANDLE, (WPARAM16)hmenu, 0L);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001599
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001600 /* adjust its size */
1601
Alexandre Julliarda3960291999-02-26 11:11:13 +00001602 SetWindowPos( menu->hWnd, 0, x, y, width, height,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001603 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001604 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001605 }
1606
1607 uSubPWndLevel++; /* menu level counter */
1608
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001609 /* Display the window */
1610
Alexandre Julliarda3960291999-02-26 11:11:13 +00001611 SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001612 SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001613 UpdateWindow( menu->hWnd );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001614 WIN_ReleaseWndPtr(wndOwner);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001615 return TRUE;
1616 }
1617 return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001618}
1619
1620
1621/***********************************************************************
1622 * MENU_SelectItem
1623 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001624static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
Rein Klazes80c924f1999-12-12 19:40:46 +00001625 BOOL sendMenuSelect, HMENU topmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001626{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001627 LPPOPUPMENU lppop;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001628 HDC hdc;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001629
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001630 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 +00001631
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001632 lppop = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001633 if (!lppop->nItems) return;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001634
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001635 if (lppop->FocusedItem == wIndex) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001636 if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
1637 else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
Alexandre Julliardf7207251994-07-23 07:57:48 +00001638
Juergen Schmied78513941999-04-18 14:40:32 +00001639 SelectObject( hdc, hMenuFont);
1640
Alexandre Julliardf7207251994-07-23 07:57:48 +00001641 /* Clear previous highlighted item */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001642 if (lppop->FocusedItem != NO_SELECTED_ITEM)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001643 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001644 lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
Juergen Schmied78513941999-04-18 14:40:32 +00001645 MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001646 lppop->Height, !(lppop->wFlags & MF_POPUP),
1647 ODA_SELECT );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001648 }
1649
1650 /* Highlight new item (if any) */
1651 lppop->FocusedItem = wIndex;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001652 if (lppop->FocusedItem != NO_SELECTED_ITEM)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001653 {
Rein Klazes80c924f1999-12-12 19:40:46 +00001654 if(!(lppop->items[wIndex].fType & MF_SEPARATOR)) {
1655 lppop->items[wIndex].fState |= MF_HILITE;
1656 MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc,
1657 &lppop->items[wIndex], lppop->Height,
1658 !(lppop->wFlags & MF_POPUP), ODA_SELECT );
1659 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001660 if (sendMenuSelect)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001661 {
1662 MENUITEM *ip = &lppop->items[lppop->FocusedItem];
Juergen Schmied78513941999-04-18 14:40:32 +00001663 SendMessageA( hwndOwner, WM_MENUSELECT,
Rein Klazes80c924f1999-12-12 19:40:46 +00001664 MAKELONG(ip->fType & MF_POPUP ? wIndex: ip->wID,
1665 ip->fType | ip->fState | MF_MOUSESELECT |
1666 (lppop->wFlags & MF_SYSMENU)), hmenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001667 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001668 }
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001669 else if (sendMenuSelect) {
Rein Klazes80c924f1999-12-12 19:40:46 +00001670 if(topmenu){
1671 int pos;
1672 if((pos=MENU_FindSubMenu(&topmenu, hmenu))!=NO_SELECTED_ITEM){
1673 POPUPMENU *ptm = (POPUPMENU *) USER_HEAP_LIN_ADDR( topmenu );
1674 MENUITEM *ip = &ptm->items[pos];
1675 SendMessageA( hwndOwner, WM_MENUSELECT, MAKELONG(pos,
1676 ip->fType | ip->fState | MF_MOUSESELECT |
1677 (ptm->wFlags & MF_SYSMENU)), topmenu);
1678 }
1679 }
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001680 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001681 ReleaseDC( lppop->hWnd, hdc );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001682}
1683
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001684
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001685/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001686 * MENU_MoveSelection
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001687 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001688 * Moves currently selected item according to the offset parameter.
1689 * If there is no selection then it should select the last item if
1690 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001691 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001692static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001693{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001694 INT i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001695 POPUPMENU *menu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001696
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001697 TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner, hmenu, offset);
Juergen Schmied466a6521999-05-02 11:21:08 +00001698
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001699 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001700 if (!menu->items) return;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001701
1702 if ( menu->FocusedItem != NO_SELECTED_ITEM )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001703 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001704 if( menu->nItems == 1 ) return; else
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001705 for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
1706 ; i += offset)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001707 if (!(menu->items[i].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001708 {
Rein Klazes80c924f1999-12-12 19:40:46 +00001709 MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001710 return;
1711 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001712 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001713
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001714 for ( i = (offset > 0) ? 0 : menu->nItems - 1;
1715 i >= 0 && i < menu->nItems ; i += offset)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001716 if (!(menu->items[i].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001717 {
Rein Klazes80c924f1999-12-12 19:40:46 +00001718 MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001719 return;
1720 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001721}
1722
1723
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001724/**********************************************************************
1725 * MENU_SetItemData
1726 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001727 * Set an item flags, id and text ptr. Called by InsertMenu() and
1728 * ModifyMenu().
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001729 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001730static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001731 LPCSTR str )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001732{
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001733 LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001734
Alexandre Julliard03468f71998-02-15 19:40:49 +00001735 debug_print_menuitem("MENU_SetItemData from: ", item, "");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001736
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001737 if (IS_STRING_ITEM(flags))
1738 {
Alexandre Julliard491502b1997-11-01 19:08:16 +00001739 if (!str || !*str)
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001740 {
1741 flags |= MF_SEPARATOR;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001742 item->text = NULL;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001743 }
1744 else
1745 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001746 LPSTR text;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001747 /* Item beginning with a backspace is a help item */
1748 if (*str == '\b')
1749 {
1750 flags |= MF_HELP;
1751 str++;
1752 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001753 if (!(text = HEAP_strdupA( SystemHeap, 0, str ))) return FALSE;
1754 item->text = text;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001755 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001756 }
Juergen Schmied78513941999-04-18 14:40:32 +00001757 else if (IS_BITMAP_ITEM(flags))
1758 item->text = (LPSTR)(HBITMAP)LOWORD(str);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001759 else item->text = NULL;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001760
Alexandre Julliarda845b881998-06-01 10:44:35 +00001761 if (flags & MF_OWNERDRAW)
1762 item->dwItemData = (DWORD)str;
1763 else
1764 item->dwItemData = 0;
1765
Alexandre Julliard02e90081998-01-04 17:49:09 +00001766 if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00001767 DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001768
1769 if (flags & MF_POPUP)
1770 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001771 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)id);
1772 if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001773 else
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001774 {
1775 item->wID = 0;
1776 item->hSubMenu = 0;
1777 item->fType = 0;
1778 item->fState = 0;
1779 return FALSE;
1780 }
Alexandre Julliard02e90081998-01-04 17:49:09 +00001781 }
1782
1783 item->wID = id;
1784 if (flags & MF_POPUP)
1785 item->hSubMenu = id;
1786
1787 if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
1788 flags |= MF_POPUP; /* keep popup */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001789
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001790 item->fType = flags & TYPE_MASK;
1791 item->fState = (flags & STATE_MASK) &
1792 ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001793
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001794
1795 /* Don't call SetRectEmpty here! */
1796
1797
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001798 if (prevText) HeapFree( SystemHeap, 0, prevText );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001799
Alexandre Julliard03468f71998-02-15 19:40:49 +00001800 debug_print_menuitem("MENU_SetItemData to : ", item, "");
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001801 return TRUE;
1802}
1803
1804
1805/**********************************************************************
1806 * MENU_InsertItem
1807 *
1808 * Insert a new item into a menu.
1809 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001810static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001811{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001812 MENUITEM *newItems;
1813 POPUPMENU *menu;
1814
1815 if (!(menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu)))
1816 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001817 WARN("%04x not a menu handle\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001818 hMenu );
1819 return NULL;
1820 }
1821
1822 /* Find where to insert new item */
1823
Marcus Meissnercb3c7bf2000-01-08 22:25:57 +00001824 if ((pos==(UINT)-1) || ((flags & MF_BYPOSITION) && (pos == menu->nItems))) {
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001825 /* Special case: append to menu */
1826 /* Some programs specify the menu length to do that */
1827 pos = menu->nItems;
Marcus Meissnercb3c7bf2000-01-08 22:25:57 +00001828 } else {
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001829 if (!MENU_FindItem( &hMenu, &pos, flags ))
1830 {
Marcus Meissnercb3c7bf2000-01-08 22:25:57 +00001831 FIXME("item %x not found\n", pos );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001832 return NULL;
1833 }
1834 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
1835 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001836 WARN("%04x not a menu handle\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001837 hMenu);
1838 return NULL;
1839 }
1840 }
1841
1842 /* Create new items array */
1843
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001844 newItems = HeapAlloc( SystemHeap, 0, sizeof(MENUITEM) * (menu->nItems+1) );
1845 if (!newItems)
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001846 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001847 WARN("allocation failed\n" );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001848 return NULL;
1849 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001850 if (menu->nItems > 0)
1851 {
1852 /* Copy the old array into the new */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001853 if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
1854 if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001855 (menu->nItems-pos)*sizeof(MENUITEM) );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001856 HeapFree( SystemHeap, 0, menu->items );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001857 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001858 menu->items = newItems;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001859 menu->nItems++;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001860 memset( &newItems[pos], 0, sizeof(*newItems) );
Gerard Patel6df06941999-09-28 13:05:54 +00001861 menu->Height = 0; /* force size recalculate */
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001862 return &newItems[pos];
1863}
1864
1865
1866/**********************************************************************
1867 * MENU_ParseResource
1868 *
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001869 * Parse a standard menu resource and add items to the menu.
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001870 * Return a pointer to the end of the resource.
1871 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001872static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001873{
1874 WORD flags, id = 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001875 LPCSTR str;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001876
1877 do
1878 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001879 flags = GET_WORD(res);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001880 res += sizeof(WORD);
1881 if (!(flags & MF_POPUP))
1882 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001883 id = GET_WORD(res);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001884 res += sizeof(WORD);
1885 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001886 if (!IS_STRING_ITEM(flags))
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001887 ERR("not a string item %04x\n", flags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001888 str = res;
1889 if (!unicode) res += strlen(str) + 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001890 else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001891 if (flags & MF_POPUP)
1892 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001893 HMENU hSubMenu = CreatePopupMenu();
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001894 if (!hSubMenu) return NULL;
1895 if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
1896 return NULL;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001897 if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
1898 else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001899 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001900 else /* Not a popup */
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001901 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001902 if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1903 else AppendMenuW( hMenu, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001904 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001905 }
1906 } while (!(flags & MF_END));
1907 return res;
1908}
1909
1910
Alexandre Julliard641ee761997-08-04 16:34:36 +00001911/**********************************************************************
1912 * MENUEX_ParseResource
1913 *
1914 * Parse an extended menu resource and add items to the menu.
1915 * Return a pointer to the end of the resource.
1916 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001917static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
Alexandre Julliard641ee761997-08-04 16:34:36 +00001918{
Alexandre Julliard641ee761997-08-04 16:34:36 +00001919 WORD resinfo;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001920 do {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001921 MENUITEMINFOW mii;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001922
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001923 mii.cbSize = sizeof(mii);
1924 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
1925 mii.fType = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001926 res += sizeof(DWORD);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001927 mii.fState = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001928 res += sizeof(DWORD);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001929 mii.wID = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001930 res += sizeof(DWORD);
1931 resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte. */
1932 res += sizeof(WORD);
1933 /* Align the text on a word boundary. */
1934 res += (~((int)res - 1)) & 1;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001935 mii.dwTypeData = (LPWSTR) res;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001936 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001937 /* Align the following fields on a dword boundary. */
1938 res += (~((int)res - 1)) & 3;
1939
1940 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1941 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001942 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
1943 0, mii.dwTypeData);
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001944 TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001945 mii.fType, mii.fState, mii.wID, resinfo, newstr);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001946 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001947 }
1948
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001949 if (resinfo & 1) { /* Pop-up? */
Marcus Meissnerde43ef41999-02-28 19:56:59 +00001950 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
Alexandre Julliard641ee761997-08-04 16:34:36 +00001951 res += sizeof(DWORD);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001952 mii.hSubMenu = CreatePopupMenu();
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001953 if (!mii.hSubMenu)
1954 return NULL;
1955 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001956 DestroyMenu(mii.hSubMenu);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001957 return NULL;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001958 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001959 mii.fMask |= MIIM_SUBMENU;
1960 mii.fType |= MF_POPUP;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001961 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001962 InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001963 } while (!(resinfo & MF_END));
1964 return res;
1965}
1966
1967
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001968/***********************************************************************
1969 * MENU_GetSubPopup
1970 *
1971 * Return the handle of the selected sub-popup menu (if any).
1972 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001973static HMENU MENU_GetSubPopup( HMENU hmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001974{
1975 POPUPMENU *menu;
1976 MENUITEM *item;
1977
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001978 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001979
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001980 if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001981
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001982 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001983 if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
1984 return item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001985 return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001986}
1987
1988
1989/***********************************************************************
1990 * MENU_HideSubPopups
1991 *
1992 * Hide the sub-popup menus of this menu.
1993 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001994static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
1995 BOOL sendMenuSelect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001996{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001997 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR( hmenu );;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001998
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00001999 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
Juergen Schmied466a6521999-05-02 11:21:08 +00002000
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002001 if (menu && uSubPWndLevel)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002002 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002003 HMENU hsubmenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002004 POPUPMENU *submenu;
2005 MENUITEM *item;
2006
2007 if (menu->FocusedItem != NO_SELECTED_ITEM)
2008 {
2009 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002010 if (!(item->fType & MF_POPUP) ||
2011 !(item->fState & MF_MOUSESELECT)) return;
2012 item->fState &= ~MF_MOUSESELECT;
2013 hsubmenu = item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002014 } else return;
2015
2016 submenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hsubmenu );
2017 MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
Rein Klazes80c924f1999-12-12 19:40:46 +00002018 MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002019
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002020 if (submenu->hWnd == MENU_GetTopPopupWnd()->hwndSelf )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002021 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002022 ShowWindow( submenu->hWnd, SW_HIDE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002023 uSubPWndLevel = 0;
2024 }
2025 else
2026 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002027 DestroyWindow( submenu->hWnd );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002028 submenu->hWnd = 0;
2029 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002030 MENU_ReleaseTopPopupWnd();
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002031 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002032}
2033
2034
2035/***********************************************************************
2036 * MENU_ShowSubPopup
2037 *
2038 * Display the sub-menu of the selected item of this menu.
2039 * Return the handle of the submenu, or hmenu if no submenu to display.
2040 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002041static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002042 BOOL selectFirst, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002043{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002044 RECT rect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002045 POPUPMENU *menu;
2046 MENUITEM *item;
2047 WND *wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002048 HDC hdc;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002049
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002050 TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
Juergen Schmied466a6521999-05-02 11:21:08 +00002051
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002052 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return hmenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002053
2054 if (!(wndPtr = WIN_FindWndPtr( menu->hWnd )) ||
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002055 (menu->FocusedItem == NO_SELECTED_ITEM))
2056 {
2057 WIN_ReleaseWndPtr(wndPtr);
2058 return hmenu;
2059 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002060
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002061 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002062 if (!(item->fType & MF_POPUP) ||
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002063 (item->fState & (MF_GRAYED | MF_DISABLED)))
2064 {
2065 WIN_ReleaseWndPtr(wndPtr);
2066 return hmenu;
2067 }
Alexandre Julliard02e90081998-01-04 17:49:09 +00002068
2069 /* message must be send before using item,
2070 because nearly everything may by changed by the application ! */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002071
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002072 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2073 if (!(wFlags & TPM_NONOTIFY))
2074 SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
Alexandre Julliard02e90081998-01-04 17:49:09 +00002075 MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
2076
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002077 item = &menu->items[menu->FocusedItem];
2078 rect = item->rect;
2079
Alexandre Julliard02e90081998-01-04 17:49:09 +00002080 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2081 if (!(item->fState & MF_HILITE))
2082 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002083 if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
2084 else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
Juergen Schmied78513941999-04-18 14:40:32 +00002085
2086 SelectObject( hdc, hMenuFont);
2087
Alexandre Julliard02e90081998-01-04 17:49:09 +00002088 item->fState |= MF_HILITE;
Juergen Schmied78513941999-04-18 14:40:32 +00002089 MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002090 ReleaseDC( menu->hWnd, hdc );
Alexandre Julliard02e90081998-01-04 17:49:09 +00002091 }
2092 if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
2093 item->rect = rect;
2094
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002095 item->fState |= MF_MOUSESELECT;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002096
2097 if (IS_SYSTEM_MENU(menu))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002098 {
Patrik Stridvall4bf33541999-06-12 14:52:15 +00002099 MENU_InitSysMenuPopup(item->hSubMenu, wndPtr->dwStyle, GetClassLongA(wndPtr->hwndSelf, GCL_STYLE));
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002100
2101 NC_GetSysPopupPos( wndPtr, &rect );
2102 rect.top = rect.bottom;
Marcus Meissnerddca3151999-05-22 11:33:23 +00002103 rect.right = GetSystemMetrics(SM_CXSIZE);
2104 rect.bottom = GetSystemMetrics(SM_CYSIZE);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002105 }
2106 else
2107 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002108 if (menu->wFlags & MF_POPUP)
2109 {
2110 rect.left = wndPtr->rectWindow.left + item->rect.right-arrow_bitmap_width;
2111 rect.top = wndPtr->rectWindow.top + item->rect.top;
2112 rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
2113 rect.bottom = item->rect.top - item->rect.bottom;
2114 }
2115 else
2116 {
2117 rect.left = wndPtr->rectWindow.left + item->rect.left;
2118 rect.top = wndPtr->rectWindow.top + item->rect.bottom;
2119 rect.right = item->rect.right - item->rect.left;
2120 rect.bottom = item->rect.bottom - item->rect.top;
2121 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002122 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002123
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002124 MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002125 rect.left, rect.top, rect.right, rect.bottom );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002126 if (selectFirst)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002127 MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002128 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002129 return item->hSubMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002130}
2131
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002132/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002133 * MENU_PtMenu
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002134 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002135 * Walks menu chain trying to find a menu pt maps to.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002136 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002137static HMENU MENU_PtMenu( HMENU hMenu, POINT16 pt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002138{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002139 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002140 register UINT ht = menu->FocusedItem;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002141
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002142 /* try subpopup first (if any) */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002143 ht = (ht != NO_SELECTED_ITEM &&
2144 (menu->items[ht].fType & MF_POPUP) &&
2145 (menu->items[ht].fState & MF_MOUSESELECT))
Alexandre Julliarda3960291999-02-26 11:11:13 +00002146 ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002147
2148 if( !ht ) /* check the current window (avoiding WM_HITTEST) */
2149 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002150 ht = (UINT)NC_HandleNCHitTest( menu->hWnd, pt );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002151 if( menu->wFlags & MF_POPUP )
Alexandre Julliarda3960291999-02-26 11:11:13 +00002152 ht = (ht != (UINT)HTNOWHERE &&
2153 ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002154 else
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002155 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002156 WND* wndPtr = WIN_FindWndPtr(menu->hWnd);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002157
Alexandre Julliarda3960291999-02-26 11:11:13 +00002158 ht = ( ht == HTSYSMENU ) ? (UINT)(wndPtr->hSysMenu)
2159 : ( ht == HTMENU ) ? (UINT)(wndPtr->wIDmenu) : 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002160 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002161 }
2162 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002163 return (HMENU)ht;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002164}
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002165
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002166/***********************************************************************
2167 * MENU_ExecFocusedItem
2168 *
2169 * Execute a menu item (for instance when user pressed Enter).
Karl Lessard13409b31999-09-28 16:24:58 +00002170 * Return the wID of the executed item. Otherwise, -1 indicating
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002171 * that no menu item wase executed;
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002172 * Have to receive the flags for the TrackPopupMenu options to avoid
2173 * sending unwanted message.
2174 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002175 */
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002176static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002177{
2178 MENUITEM *item;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002179 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
Juergen Schmied466a6521999-05-02 11:21:08 +00002180
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002181 TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
Juergen Schmied466a6521999-05-02 11:21:08 +00002182
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002183 if (!menu || !menu->nItems ||
Karl Lessard13409b31999-09-28 16:24:58 +00002184 (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002185
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002186 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002187
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002188 TRACE("%08x %08x %08x\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002189 hMenu, item->wID, item->hSubMenu);
2190
2191 if (!(item->fType & MF_POPUP))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002192 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002193 if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002194 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002195 /* If TPM_RETURNCMD is set you return the id, but
2196 do not send a message to the owner */
2197 if(!(wFlags & TPM_RETURNCMD))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002198 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002199 if( menu->wFlags & MF_SYSMENU )
2200 PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
2201 MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
2202 else
2203 PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002204 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002205 return item->wID;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002206 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002207 }
2208 else
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002209 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags);
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002210
Karl Lessard13409b31999-09-28 16:24:58 +00002211 return -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002212}
2213
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002214/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002215 * MENU_SwitchTracking
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002216 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002217 * Helper function for menu navigation routines.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002218 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002219static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002220{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002221 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2222 POPUPMENU *topmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002223
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002224 TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
Juergen Schmied466a6521999-05-02 11:21:08 +00002225
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002226 if( pmt->hTopMenu != hPtMenu &&
2227 !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002228 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002229 /* both are top level menus (system and menu-bar) */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002230 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
Rein Klazes80c924f1999-12-12 19:40:46 +00002231 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002232 pmt->hTopMenu = hPtMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002233 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002234 else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
Rein Klazes80c924f1999-12-12 19:40:46 +00002235 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002236}
2237
2238
2239/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002240 * MENU_ButtonDown
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002241 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002242 * Return TRUE if we can go on with menu tracking.
2243 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002244static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002245{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002246 TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
Juergen Schmied466a6521999-05-02 11:21:08 +00002247
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002248 if (hPtMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002249 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002250 UINT id = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002251 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2252 MENUITEM *item;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002253
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002254 if( IS_SYSTEM_MENU(ptmenu) )
2255 item = ptmenu->items;
2256 else
2257 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002258
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002259 if( item )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002260 {
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002261 if( ptmenu->FocusedItem != id )
2262 MENU_SwitchTracking( pmt, hPtMenu, id );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002263
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002264 /* If the popup menu is not already "popped" */
2265 if(!(item->fState & MF_MOUSESELECT ))
Pascal Lessard07c447f1999-09-19 12:03:25 +00002266 {
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002267 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE, wFlags );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002268
Pascal Lessard07c447f1999-09-19 12:03:25 +00002269 /* In win31, a newly popped menu always remain opened for the next buttonup */
2270 if(TWEAK_WineLook == WIN31_LOOK)
2271 ptmenu->bTimeToHide = FALSE;
2272 }
2273
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002274 return TRUE;
2275 }
Pascal Lessard445c9101999-09-20 18:27:14 +00002276 /* Else the click was on the menu bar, finish the tracking */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002277 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002278 return FALSE;
2279}
2280
2281/***********************************************************************
2282 * MENU_ButtonUp
2283 *
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002284 * Return the value of MENU_ExecFocusedItem if
2285 * the selected item was not a popup. Else open the popup.
Karl Lessard13409b31999-09-28 16:24:58 +00002286 * A -1 return value indicates that we go on with menu tracking.
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002287 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002288 */
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002289static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002290{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002291 TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
Juergen Schmied466a6521999-05-02 11:21:08 +00002292
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002293 if (hPtMenu)
2294 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002295 UINT id = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002296 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2297 MENUITEM *item;
2298
2299 if( IS_SYSTEM_MENU(ptmenu) )
2300 item = ptmenu->items;
2301 else
2302 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2303
Alexandre Julliard491502b1997-11-01 19:08:16 +00002304 if( item && (ptmenu->FocusedItem == id ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002305 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002306 if( !(item->fType & MF_POPUP) )
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002307 return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002308
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002309 /* If we are dealing with the top-level menu and that this */
2310 /* is a click on an already "poppped" item */
2311 /* Stop the menu tracking and close the opened submenus */
2312 if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
Karl Lessard13409b31999-09-28 16:24:58 +00002313 return 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002314 }
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002315 ptmenu->bTimeToHide = TRUE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002316 }
Karl Lessard13409b31999-09-28 16:24:58 +00002317 return -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002318}
2319
2320
2321/***********************************************************************
2322 * MENU_MouseMove
2323 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002324 * Return TRUE if we can go on with menu tracking.
2325 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002326static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002327{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002328 UINT id = NO_SELECTED_ITEM;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002329 POPUPMENU *ptmenu = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002330
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002331 if( hPtMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002332 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002333 ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2334 if( IS_SYSTEM_MENU(ptmenu) )
2335 id = 0;
2336 else
2337 MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2338 }
2339
2340 if( id == NO_SELECTED_ITEM )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002341 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002342 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
Rein Klazes80c924f1999-12-12 19:40:46 +00002343 NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
2344
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002345 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002346 else if( ptmenu->FocusedItem != id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002347 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002348 MENU_SwitchTracking( pmt, hPtMenu, id );
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002349 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002350 }
2351 return TRUE;
2352}
2353
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002354
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002355/***********************************************************************
2356 * MENU_DoNextMenu
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002357 *
2358 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002359 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002360static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002361{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002362 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002363
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002364 if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
2365 (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
2366 {
2367 WND* wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002368 HMENU hNewMenu;
2369 HWND hNewWnd;
2370 UINT id = 0;
Juergen Schmied78513941999-04-18 14:40:32 +00002371 LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002372 (IS_SYSTEM_MENU(menu)) ? GetSubMenu16(pmt->hTopMenu,0) : pmt->hTopMenu );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002373
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002374 TRACE("%04x [%04x] -> %04x [%04x]\n",
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002375 (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002376
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002377 if( l == 0 )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002378 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002379 wndPtr = WIN_FindWndPtr(pmt->hOwnerWnd);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002380
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002381 hNewWnd = pmt->hOwnerWnd;
2382 if( IS_SYSTEM_MENU(menu) )
2383 {
2384 /* switch to the menu bar */
2385
2386 if( wndPtr->dwStyle & WS_CHILD || !wndPtr->wIDmenu )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002387 {
2388 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002389 return FALSE;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002390 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002391
2392 hNewMenu = wndPtr->wIDmenu;
2393 if( vk == VK_LEFT )
2394 {
2395 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hNewMenu );
2396 id = menu->nItems - 1;
2397 }
2398 }
2399 else if( wndPtr->dwStyle & WS_SYSMENU )
2400 {
2401 /* switch to the system menu */
2402 hNewMenu = wndPtr->hSysMenu;
2403 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002404 else
2405 {
2406 WIN_ReleaseWndPtr(wndPtr);
2407 return FALSE;
2408 }
2409 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002410 }
2411 else /* application returned a new menu to switch to */
2412 {
2413 hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
2414
Alexandre Julliarda3960291999-02-26 11:11:13 +00002415 if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002416 {
2417 wndPtr = WIN_FindWndPtr(hNewWnd);
2418
2419 if( wndPtr->dwStyle & WS_SYSMENU &&
2420 GetSubMenu16(wndPtr->hSysMenu, 0) == hNewMenu )
2421 {
2422 /* get the real system menu */
2423 hNewMenu = wndPtr->hSysMenu;
2424 }
2425 else if( wndPtr->dwStyle & WS_CHILD || wndPtr->wIDmenu != hNewMenu )
2426 {
2427 /* FIXME: Not sure what to do here, perhaps,
2428 * try to track hNewMenu as a popup? */
2429
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002430 TRACE(" -- got confused.\n");
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002431 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002432 return FALSE;
2433 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002434 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002435 }
2436 else return FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002437 }
2438
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002439 if( hNewMenu != pmt->hTopMenu )
2440 {
Rein Klazes80c924f1999-12-12 19:40:46 +00002441 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
2442 FALSE, 0 );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002443 if( pmt->hCurrentMenu != pmt->hTopMenu )
2444 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2445 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002446
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002447 if( hNewWnd != pmt->hOwnerWnd )
2448 {
2449 ReleaseCapture();
2450 pmt->hOwnerWnd = hNewWnd;
2451 EVENT_Capture( pmt->hOwnerWnd, HTMENU );
2452 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002453
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002454 pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
Rein Klazes80c924f1999-12-12 19:40:46 +00002455 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002456
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002457 return TRUE;
2458 }
2459 return FALSE;
2460}
2461
2462/***********************************************************************
2463 * MENU_SuspendPopup
2464 *
2465 * The idea is not to show the popup if the next input message is
2466 * going to hide it anyway.
2467 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002468static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT16 uMsg )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002469{
Juergen Schmied78513941999-04-18 14:40:32 +00002470 MSG msg;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002471
2472 msg.hwnd = pmt->hOwnerWnd;
2473
Juergen Schmied78513941999-04-18 14:40:32 +00002474 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002475 pmt->trackFlags |= TF_SKIPREMOVE;
2476
2477 switch( uMsg )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002478 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002479 case WM_KEYDOWN:
Juergen Schmied78513941999-04-18 14:40:32 +00002480 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002481 if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
2482 {
Juergen Schmied78513941999-04-18 14:40:32 +00002483 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2484 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002485 if( msg.message == WM_KEYDOWN &&
2486 (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
2487 {
2488 pmt->trackFlags |= TF_SUSPENDPOPUP;
2489 return TRUE;
2490 }
2491 }
2492 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002493 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002494
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002495 /* failures go through this */
2496 pmt->trackFlags &= ~TF_SUSPENDPOPUP;
2497 return FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002498}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002499
2500/***********************************************************************
2501 * MENU_KeyLeft
2502 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002503 * Handle a VK_LEFT key event in a menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002504 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002505static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002506{
2507 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002508 HMENU hmenutmp, hmenuprev;
2509 UINT prevcol;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002510
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002511 hmenuprev = hmenutmp = pmt->hTopMenu;
2512 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenutmp );
2513
Alexandre Julliard641ee761997-08-04 16:34:36 +00002514 /* Try to move 1 column left (if possible) */
2515 if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
2516 NO_SELECTED_ITEM ) {
2517
2518 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
Rein Klazes80c924f1999-12-12 19:40:46 +00002519 prevcol, TRUE, 0 );
Alexandre Julliard641ee761997-08-04 16:34:36 +00002520 return;
2521 }
2522
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002523 /* close topmost popup */
2524 while (hmenutmp != pmt->hCurrentMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002525 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002526 hmenuprev = hmenutmp;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002527 hmenutmp = MENU_GetSubPopup( hmenuprev );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002528 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002529
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002530 MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
2531 pmt->hCurrentMenu = hmenuprev;
2532
2533 if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002534 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002535 /* move menu bar selection if no more popups are left */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002536
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002537 if( !MENU_DoNextMenu( pmt, VK_LEFT) )
2538 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002539
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002540 if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002541 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002542 /* A sublevel menu was displayed - display the next one
2543 * unless there is another displacement coming up */
2544
2545 if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002546 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2547 pmt->hTopMenu, TRUE, wFlags);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002548 }
2549 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002550}
2551
2552
2553/***********************************************************************
2554 * MENU_KeyRight
2555 *
2556 * Handle a VK_RIGHT key event in a menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002557 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002558static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002559{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002560 HMENU hmenutmp;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002561 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002562 UINT nextcol;
Alexandre Julliard641ee761997-08-04 16:34:36 +00002563
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002564 TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
Alexandre Julliard641ee761997-08-04 16:34:36 +00002565 pmt->hCurrentMenu,
2566 ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
2567 items[0].text,
2568 pmt->hTopMenu, menu->items[0].text );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002569
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002570 if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002571 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002572 /* If already displaying a popup, try to display sub-popup */
2573
2574 hmenutmp = pmt->hCurrentMenu;
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002575 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002576
2577 /* if subpopup was displayed then we are done */
2578 if (hmenutmp != pmt->hCurrentMenu) return;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002579 }
2580
Alexandre Julliard641ee761997-08-04 16:34:36 +00002581 /* Check to see if there's another column */
2582 if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
2583 NO_SELECTED_ITEM ) {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002584 TRACE("Going to %d.\n", nextcol );
Alexandre Julliard641ee761997-08-04 16:34:36 +00002585 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
Rein Klazes80c924f1999-12-12 19:40:46 +00002586 nextcol, TRUE, 0 );
Alexandre Julliard641ee761997-08-04 16:34:36 +00002587 return;
2588 }
2589
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002590 if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002591 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002592 if( pmt->hCurrentMenu != pmt->hTopMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002593 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002594 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2595 hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
2596 } else hmenutmp = 0;
2597
2598 /* try to move to the next item */
2599 if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
2600 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
2601
2602 if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2603 if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002604 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2605 pmt->hTopMenu, TRUE, wFlags);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002606 }
2607}
2608
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002609/***********************************************************************
2610 * MENU_TrackMenu
2611 *
2612 * Menu tracking code.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002613 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002614static INT MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
2615 HWND hwnd, const RECT *lprect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002616{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002617 MSG msg;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002618 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002619 BOOL fRemove;
Karl Lessard13409b31999-09-28 16:24:58 +00002620 INT executedMenuId = -1;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +00002621 MTRACKER mt;
Francis Beaudet7ed1af31999-08-15 16:58:03 +00002622 BOOL enterIdleSent = FALSE;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +00002623
2624 mt.trackFlags = 0;
2625 mt.hCurrentMenu = hmenu;
2626 mt.hTopMenu = hmenu;
2627 mt.hOwnerWnd = hwnd;
2628 mt.pt.x = x;
2629 mt.pt.y = y;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002630
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002631 TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00002632 hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
2633 (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
Juergen Schmied78513941999-04-18 14:40:32 +00002634
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002635 fEndMenu = FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002636 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002637
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002638 if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu, wFlags );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002639
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002640 EVENT_Capture( mt.hOwnerWnd, HTMENU );
2641
2642 while (!fEndMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002643 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002644 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2645 msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
2646
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002647 /* we have to keep the message in the queue until it's
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002648 * clear that menu loop is not over yet. */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002649
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00002650 if (!MSG_InternalGetMessage( QMSG_WIN32A, &msg, msg.hwnd, mt.hOwnerWnd,
Francis Beaudet7ed1af31999-08-15 16:58:03 +00002651 MSGF_MENU, PM_NOREMOVE, !enterIdleSent, &enterIdleSent )) break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002652
Alexandre Julliarda3960291999-02-26 11:11:13 +00002653 TranslateMessage( &msg );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002654 mt.pt = msg.pt;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +00002655
Francis Beaudet7ed1af31999-08-15 16:58:03 +00002656 if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
2657 enterIdleSent=FALSE;
2658
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002659 fRemove = FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002660 if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002661 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002662 /* Find a menu for this mouse event */
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002663 POINT16 pt16;
2664 CONV_POINT32TO16( &msg.pt, &pt16 );
2665 hmenu = MENU_PtMenu( mt.hTopMenu, pt16 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002666
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002667 switch(msg.message)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002668 {
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002669 /* no WM_NC... messages in captured state */
2670
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002671 case WM_RBUTTONDBLCLK:
2672 case WM_RBUTTONDOWN:
2673 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2674 /* fall through */
2675 case WM_LBUTTONDBLCLK:
2676 case WM_LBUTTONDOWN:
Karl Lessard4a0a7df1999-11-07 05:17:10 +00002677 /* If the message belongs to the menu, removes it from the queue */
2678 /* Else, end menu tracking */
2679 fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
2680 fEndMenu = !fRemove;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002681 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002682
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002683 case WM_RBUTTONUP:
2684 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2685 /* fall through */
2686 case WM_LBUTTONUP:
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002687 /* Check if a menu was selected by the mouse */
2688 if (hmenu)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002689 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002690 executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002691
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002692 /* End the loop if executedMenuId is an item ID */
Karl Lessard13409b31999-09-28 16:24:58 +00002693 /* or if the job was done (executedMenuId = 0). */
2694 fEndMenu = fRemove = (executedMenuId != -1);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002695 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002696 /* No menu was selected by the mouse */
2697 /* if the function was called by TrackPopupMenu, continue
2698 with the menu tracking. If not, stop it */
2699 else
2700 fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
2701
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002702 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002703
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002704 case WM_MOUSEMOVE:
Alexandre Julliard8da12c41999-01-17 16:55:11 +00002705 /* In win95 winelook, the selected menu item must be changed every time the
2706 mouse moves. In Win31 winelook, the mouse button has to be held down */
2707
2708 if ( (TWEAK_WineLook > WIN31_LOOK) ||
2709 ( (msg.wParam & MK_LBUTTON) ||
2710 ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
2711
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002712 fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
Alexandre Julliard8da12c41999-01-17 16:55:11 +00002713
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002714 } /* switch(msg.message) - mouse */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002715 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002716 else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002717 {
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002718 fRemove = TRUE; /* Keyboard messages are always removed */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002719 switch(msg.message)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002720 {
2721 case WM_KEYDOWN:
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002722 switch(msg.wParam)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002723 {
2724 case VK_HOME:
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002725 case VK_END:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002726 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
Rein Klazes80c924f1999-12-12 19:40:46 +00002727 NO_SELECTED_ITEM, FALSE, 0 );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002728 /* fall through */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002729 case VK_UP:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002730 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002731 (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002732 break;
2733
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002734 case VK_DOWN: /* If on menu bar, pull-down the menu */
2735
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002736 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2737 if (!(menu->wFlags & MF_POPUP))
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002738 mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002739 else /* otherwise try to move selection */
2740 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002741 break;
2742
2743 case VK_LEFT:
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002744 MENU_KeyLeft( &mt, wFlags );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002745 break;
2746
2747 case VK_RIGHT:
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002748 MENU_KeyRight( &mt, wFlags );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002749 break;
2750
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002751 case VK_ESCAPE:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002752 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002753 break;
2754
2755 default:
2756 break;
2757 }
2758 break; /* WM_KEYDOWN */
2759
2760 case WM_SYSKEYDOWN:
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002761 switch(msg.wParam)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002762 {
2763 case VK_MENU:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002764 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002765 break;
2766
2767 }
2768 break; /* WM_SYSKEYDOWN */
2769
2770 case WM_CHAR:
2771 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002772 UINT pos;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002773
Norman Stevensa83d0651998-10-12 07:25:35 +00002774 if (msg.wParam == '\r' || msg.wParam == ' ')
2775 {
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002776 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
Karl Lessard13409b31999-09-28 16:24:58 +00002777 fEndMenu = (executedMenuId != -1);
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002778
Norman Stevensa83d0651998-10-12 07:25:35 +00002779 break;
2780 }
2781
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002782 /* Hack to avoid control chars. */
2783 /* We will find a better way real soon... */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002784 if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002785
2786 pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002787 LOWORD(msg.wParam), FALSE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002788 if (pos == (UINT)-2) fEndMenu = TRUE;
2789 else if (pos == (UINT)-1) MessageBeep(0);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002790 else
2791 {
Rein Klazes80c924f1999-12-12 19:40:46 +00002792 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
2793 TRUE, 0 );
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002794 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
Karl Lessard13409b31999-09-28 16:24:58 +00002795 fEndMenu = (executedMenuId != -1);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002796 }
2797 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002798 break;
2799 } /* switch(msg.message) - kbd */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002800 }
2801 else
2802 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002803 DispatchMessageA( &msg );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002804 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002805
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002806 if (!fEndMenu) fRemove = TRUE;
2807
2808 /* finally remove message from the queue */
2809
2810 if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00002811 PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002812 else mt.trackFlags &= ~TF_SKIPREMOVE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002813 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002814
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002815 ReleaseCapture();
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00002816
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002817 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hTopMenu );
2818
Alexandre Julliarda3960291999-02-26 11:11:13 +00002819 if( IsWindow( mt.hOwnerWnd ) )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002820 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002821 MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
2822
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002823 if (menu && menu->wFlags & MF_POPUP)
2824 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002825 ShowWindow( menu->hWnd, SW_HIDE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002826 uSubPWndLevel = 0;
2827 }
Rein Klazes80c924f1999-12-12 19:40:46 +00002828 MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
Dennis Björklund4352c7a1999-09-19 18:28:35 +00002829 SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002830 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002831
Pascal Lessard2eb0a301999-09-03 16:38:52 +00002832 /* Reset the variable for hiding menu */
2833 menu->bTimeToHide = FALSE;
2834
Juergen Schmied371c4201999-10-13 12:27:44 +00002835 /* The return value is only used by TrackPopupMenu */
2836 return ((executedMenuId != -1) ? executedMenuId : 0);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002837}
2838
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002839/***********************************************************************
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002840 * MENU_InitTracking
2841 */
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002842static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002843{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002844 TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00002845
Alexandre Julliarda3960291999-02-26 11:11:13 +00002846 HideCaret(0);
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002847
2848 /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
2849 if (!(wFlags & TPM_NONOTIFY))
2850 SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
2851
Juergen Schmied78513941999-04-18 14:40:32 +00002852 SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002853
2854 if (!(wFlags & TPM_NONOTIFY))
2855 SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
2856
Juergen Schmied78513941999-04-18 14:40:32 +00002857 return TRUE;
2858}
2859/***********************************************************************
2860 * MENU_ExitTracking
2861 */
2862static BOOL MENU_ExitTracking(HWND hWnd)
2863{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002864 TRACE("hwnd=0x%04x\n", hWnd);
Juergen Schmied78513941999-04-18 14:40:32 +00002865
2866 SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
2867 ShowCaret(0);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002868 return TRUE;
2869}
2870
2871/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002872 * MENU_TrackMouseMenuBar
2873 *
2874 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2875 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002876void MENU_TrackMouseMenuBar( WND* wndPtr, INT ht, POINT pt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002877{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002878 HWND hWnd = wndPtr->hwndSelf;
2879 HMENU hMenu = (ht == HTSYSMENU) ? wndPtr->hSysMenu : wndPtr->wIDmenu;
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002880 UINT wFlags = TPM_ENTERIDLEEX | TPM_BUTTONDOWN | TPM_LEFTALIGN | TPM_LEFTBUTTON;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002881
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00002882 TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
Juergen Schmied78513941999-04-18 14:40:32 +00002883
Alexandre Julliarda3960291999-02-26 11:11:13 +00002884 if (IsMenu(hMenu))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002885 {
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002886 MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
2887 MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd, NULL );
Juergen Schmied78513941999-04-18 14:40:32 +00002888 MENU_ExitTracking(hWnd);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002889 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002890}
2891
2892
2893/***********************************************************************
2894 * MENU_TrackKbdMenuBar
2895 *
2896 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2897 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002898void MENU_TrackKbdMenuBar( WND* wndPtr, UINT wParam, INT vkey)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002899{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002900 UINT uItem = NO_SELECTED_ITEM;
2901 HMENU hTrackMenu;
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002902 UINT wFlags = TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002903
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002904 /* find window that has a menu */
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002905
Pierre Mageau891d4d21999-10-23 20:05:04 +00002906 while( wndPtr->dwStyle & WS_CHILD)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002907 if( !(wndPtr = wndPtr->parent) ) return;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002908
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002909 /* check if we have to track a system menu */
2910
2911 if( (wndPtr->dwStyle & (WS_CHILD | WS_MINIMIZE)) ||
2912 !wndPtr->wIDmenu || vkey == VK_SPACE )
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002913 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002914 if( !(wndPtr->dwStyle & WS_SYSMENU) ) return;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002915 hTrackMenu = wndPtr->hSysMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002916 uItem = 0;
2917 wParam |= HTSYSMENU; /* prevent item lookup */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002918 }
2919 else
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002920 hTrackMenu = wndPtr->wIDmenu;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002921
Alexandre Julliarda3960291999-02-26 11:11:13 +00002922 if (IsMenu( hTrackMenu ))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002923 {
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002924 MENU_InitTracking( wndPtr->hwndSelf, hTrackMenu, FALSE, wFlags );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002925
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002926 if( vkey && vkey != VK_SPACE )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002927 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002928 uItem = MENU_FindItemByKey( wndPtr->hwndSelf, hTrackMenu,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002929 vkey, (wParam & HTSYSMENU) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002930 if( uItem >= (UINT)(-2) )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002931 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002932 if( uItem == (UINT)(-1) ) MessageBeep(0);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002933 hTrackMenu = 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002934 }
2935 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002936
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002937 if( hTrackMenu )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002938 {
Rein Klazes80c924f1999-12-12 19:40:46 +00002939 MENU_SelectItem( wndPtr->hwndSelf, hTrackMenu, uItem, TRUE, 0 );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002940
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002941 if( uItem == NO_SELECTED_ITEM )
2942 MENU_MoveSelection( wndPtr->hwndSelf, hTrackMenu, ITEM_NEXT );
2943 else if( vkey )
Juergen Schmied78513941999-04-18 14:40:32 +00002944 PostMessageA( wndPtr->hwndSelf, WM_KEYDOWN, VK_DOWN, 0L );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002945
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002946 MENU_TrackMenu( hTrackMenu, wFlags, 0, 0, wndPtr->hwndSelf, NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002947 }
Juergen Schmied78513941999-04-18 14:40:32 +00002948
2949 MENU_ExitTracking (wndPtr->hwndSelf);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002950 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002951}
2952
2953
2954/**********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002955 * TrackPopupMenu16 (USER.416)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002956 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002957BOOL16 WINAPI TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
2958 INT16 nReserved, HWND16 hWnd, const RECT16 *lpRect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002959{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002960 RECT r;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002961 if (lpRect)
2962 CONV_RECT16TO32( lpRect, &r );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002963 return TrackPopupMenu( hMenu, wFlags, x, y, nReserved, hWnd,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002964 lpRect ? &r : NULL );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002965}
2966
2967
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002968/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00002969 * TrackPopupMenu (USER32.549)
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002970 *
2971 * Like the win32 API, the function return the command ID only if the
2972 * flag TPM_RETURNCMD is on.
2973 *
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002974 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002975BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
2976 INT nReserved, HWND hWnd, const RECT *lpRect )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002977{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002978 BOOL ret = FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002979
Abey Georgeb59d4bc1999-09-22 15:10:42 +00002980 MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
2981
2982 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2983 if (!(wFlags & TPM_NONOTIFY))
2984 SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
2985
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002986 if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002987 ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
Juergen Schmied78513941999-04-18 14:40:32 +00002988 MENU_ExitTracking(hWnd);
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00002989
2990 if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
2991 ret = 1;
2992
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002993 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002994}
2995
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002996/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00002997 * TrackPopupMenuEx (USER32.550)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002998 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002999BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
3000 HWND hWnd, LPTPMPARAMS lpTpm )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00003001{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003002 FIXME("not fully implemented\n" );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003003 return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003004 lpTpm ? &lpTpm->rcExclude : NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00003005}
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00003006
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003007/***********************************************************************
3008 * PopupMenuWndProc
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003009 *
3010 * NOTE: Windows has totally different (and undocumented) popup wndproc.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003011 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003012LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003013 LPARAM lParam )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003014{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003015 WND* wndPtr = WIN_FindWndPtr(hwnd);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003016 LRESULT retvalue;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003017
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003018 TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
Juergen Schmied78513941999-04-18 14:40:32 +00003019 hwnd, message, wParam, lParam);
3020
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003021 switch(message)
3022 {
3023 case WM_CREATE:
3024 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003025 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
3026 SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003027 retvalue = 0;
3028 goto END;
Alexandre Julliardf7207251994-07-23 07:57:48 +00003029 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003030
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003031 case WM_MOUSEACTIVATE: /* We don't want to be activated */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003032 retvalue = MA_NOACTIVATE;
3033 goto END;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003034
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003035 case WM_PAINT:
3036 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003037 PAINTSTRUCT ps;
3038 BeginPaint( hwnd, &ps );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003039 MENU_DrawPopupMenu( hwnd, ps.hdc,
Alexandre Julliarda3960291999-02-26 11:11:13 +00003040 (HMENU)GetWindowLongA( hwnd, 0 ) );
3041 EndPaint( hwnd, &ps );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003042 retvalue = 0;
3043 goto END;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003044 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003045 case WM_ERASEBKGND:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003046 retvalue = 1;
3047 goto END;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003048
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003049 case WM_DESTROY:
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003050
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003051 /* zero out global pointer in case resident popup window
3052 * was somehow destroyed. */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003053
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003054 if(MENU_GetTopPopupWnd() )
Alexandre Julliard54c27111998-03-29 19:44:57 +00003055 {
3056 if( hwnd == pTopPopupWnd->hwndSelf )
3057 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003058 ERR("resident popup destroyed!\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003059
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003060 MENU_DestroyTopPopupWnd();
Alexandre Julliard54c27111998-03-29 19:44:57 +00003061 uSubPWndLevel = 0;
3062 }
3063 else
3064 uSubPWndLevel--;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003065 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003066 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003067 break;
3068
3069 case WM_SHOWWINDOW:
3070
3071 if( wParam )
3072 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003073 if( !(*(HMENU*)wndPtr->wExtra) )
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003074 ERR("no menu to display\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003075 }
3076 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00003077 *(HMENU*)wndPtr->wExtra = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003078 break;
3079
3080 case MM_SETMENUHANDLE:
3081
Alexandre Julliarda3960291999-02-26 11:11:13 +00003082 *(HMENU*)wndPtr->wExtra = (HMENU)wParam;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00003083 break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003084
3085 case MM_GETMENUHANDLE:
3086
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003087 retvalue = *(HMENU*)wndPtr->wExtra;
3088 goto END;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003089
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003090 default:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003091 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
3092 goto END;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003093 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003094 retvalue = 0;
3095END:
3096 WIN_ReleaseWndPtr(wndPtr);
3097 return retvalue;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003098}
3099
3100
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00003101/***********************************************************************
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003102 * MENU_GetMenuBarHeight
3103 *
3104 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3105 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003106UINT MENU_GetMenuBarHeight( HWND hwnd, UINT menubarWidth,
3107 INT orgX, INT orgY )
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003108{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003109 HDC hdc;
3110 RECT rectBar;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003111 WND *wndPtr;
3112 LPPOPUPMENU lppop;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003113 UINT retvalue;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003114
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003115 TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
Juergen Schmied78513941999-04-18 14:40:32 +00003116 hwnd, menubarWidth, orgX, orgY );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003117
Juergen Schmied78513941999-04-18 14:40:32 +00003118 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
3119 return 0;
3120
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003121 if (!(lppop = (LPPOPUPMENU)USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu)))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003122 {
Juergen Schmied78513941999-04-18 14:40:32 +00003123 WIN_ReleaseWndPtr(wndPtr);
3124 return 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003125 }
Juergen Schmied78513941999-04-18 14:40:32 +00003126
Alexandre Julliarda3960291999-02-26 11:11:13 +00003127 hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
Juergen Schmied78513941999-04-18 14:40:32 +00003128 SelectObject( hdc, hMenuFont);
Marcus Meissnerddca3151999-05-22 11:33:23 +00003129 SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
Juergen Schmied78513941999-04-18 14:40:32 +00003130 MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003131 ReleaseDC( hwnd, hdc );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003132 retvalue = lppop->Height;
3133 WIN_ReleaseWndPtr(wndPtr);
3134 return retvalue;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003135}
3136
3137
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003138/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003139 * ChangeMenu16 (USER.153)
Alexandre Julliard401710d1993-09-04 10:09:32 +00003140 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003141BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
3142 UINT16 id, UINT16 flags )
Alexandre Julliard401710d1993-09-04 10:09:32 +00003143{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003144 TRACE("menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +00003145 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003146 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND,
3147 id, data );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003148
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003149 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
3150 /* for MF_DELETE. We should check the parameters for all others */
3151 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003152
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003153 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
3154 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE,
3155 id, data );
3156 if (flags & MF_REMOVE) return RemoveMenu16(hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003157 flags & MF_BYPOSITION ? pos : id,
3158 flags & ~MF_REMOVE );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003159 /* Default: MF_INSERT */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003160 return InsertMenu16( hMenu, pos, flags, id, data );
3161}
3162
3163
3164/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003165 * ChangeMenu32A (USER32.23)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003166 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003167BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
3168 UINT id, UINT flags )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003169{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003170 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003171 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003172 if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003173 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003174 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3175 if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003176 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003177 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003178 flags & MF_BYPOSITION ? pos : id,
3179 flags & ~MF_REMOVE );
3180 /* Default: MF_INSERT */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003181 return InsertMenuA( hMenu, pos, flags, id, data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003182}
3183
3184
3185/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003186 * ChangeMenu32W (USER32.24)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003187 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003188BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
3189 UINT id, UINT flags )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003190{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003191 TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003192 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003193 if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003194 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003195 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3196 if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003197 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003198 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003199 flags & MF_BYPOSITION ? pos : id,
3200 flags & ~MF_REMOVE );
3201 /* Default: MF_INSERT */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003202 return InsertMenuW( hMenu, pos, flags, id, data );
Alexandre Julliard401710d1993-09-04 10:09:32 +00003203}
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003204
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003205
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003206/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003207 * CheckMenuItem16 (USER.154)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003208 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003209BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003210{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003211 return (BOOL16)CheckMenuItem( hMenu, id, flags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003212}
3213
3214
3215/*******************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003216 * CheckMenuItem (USER32.46)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003217 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003218DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003219{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003220 MENUITEM *item;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003221 DWORD ret;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003222
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003223 TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003224 if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003225 ret = item->fState & MF_CHECKED;
3226 if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
3227 else item->fState &= ~MF_CHECKED;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003228 return ret;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003229}
3230
3231
3232/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003233 * EnableMenuItem16 (USER.155)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003234 */
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003235UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003236{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003237 return EnableMenuItem( hMenu, wItemID, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003238}
3239
3240
3241/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003242 * EnableMenuItem32 (USER32.170)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003243 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003244UINT WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003245{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003246 UINT oldflags;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003247 MENUITEM *item;
Pascal Lessardd814bb61999-07-31 13:02:02 +00003248 POPUPMENU *menu;
Alexandre Julliardf7207251994-07-23 07:57:48 +00003249
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003250 TRACE("(%04x, %04X, %04X) !\n",
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003251 hMenu, wItemID, wFlags);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003252
Pascal Lessardd814bb61999-07-31 13:02:02 +00003253 /* Get the Popupmenu to access the owner menu */
3254 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
3255 return (UINT)-1;
3256
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003257 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003258 return (UINT)-1;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003259
3260 oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
3261 item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
Pascal Lessardd814bb61999-07-31 13:02:02 +00003262
3263 /* In win95 if the close item in the system menu change update the close button */
3264 if (TWEAK_WineLook == WIN95_LOOK)
3265 if((item->wID == SC_CLOSE) && (oldflags != wFlags))
3266 {
3267 if (menu->hSysMenuOwner != 0)
3268 {
3269 POPUPMENU* parentMenu;
3270
3271 /* Get the parent menu to access*/
3272 if (!(parentMenu = (POPUPMENU *) USER_HEAP_LIN_ADDR(menu->hSysMenuOwner)))
3273 return (UINT)-1;
3274
3275 /* Refresh the frame to reflect the change*/
3276 SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
Stephane Lussiera833f631999-08-21 14:46:06 +00003277 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
Pascal Lessardd814bb61999-07-31 13:02:02 +00003278 }
3279 }
3280
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003281 return oldflags;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003282}
3283
3284
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003285/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003286 * GetMenuString16 (USER.161)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003287 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003288INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
3289 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003290{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003291 return GetMenuStringA( hMenu, wItemID, str, nMaxSiz, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003292}
3293
3294
3295/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003296 * GetMenuString32A (USER32.268)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003297 */
Marcus Meissnercb3c7bf2000-01-08 22:25:57 +00003298INT WINAPI GetMenuStringA(
3299 HMENU hMenu, /* [in] menuhandle */
3300 UINT wItemID, /* [in] menu item (dep. on wFlags) */
3301 LPSTR str, /* [out] outbuffer. If NULL, func returns entry length*/
3302 INT nMaxSiz, /* [in] length of buffer. if 0, func returns entry len*/
3303 UINT wFlags /* [in] MF_ flags */
3304) {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003305 MENUITEM *item;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003306
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003307 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003308 hMenu, wItemID, str, nMaxSiz, wFlags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003309 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003310 if (!IS_STRING_ITEM(item->fType)) return 0;
Marcus Meissnercb3c7bf2000-01-08 22:25:57 +00003311 if (!str || !nMaxSiz) return strlen(item->text);
3312 str[0] = '\0';
Alexandre Julliarda3960291999-02-26 11:11:13 +00003313 lstrcpynA( str, item->text, nMaxSiz );
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003314 TRACE("returning '%s'\n", str );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003315 return strlen(str);
Alexandre Julliard1f579291994-05-25 16:25:21 +00003316}
3317
3318
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003319/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003320 * GetMenuString32W (USER32.269)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003321 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003322INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
3323 LPWSTR str, INT nMaxSiz, UINT wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003324{
3325 MENUITEM *item;
3326
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003327 TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003328 hMenu, wItemID, str, nMaxSiz, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003329 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003330 if (!IS_STRING_ITEM(item->fType)) return 0;
Marcus Meissnercb3c7bf2000-01-08 22:25:57 +00003331 if (!str || !nMaxSiz) return strlen(item->text);
3332 str[0] = '\0';
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003333 lstrcpynAtoW( str, item->text, nMaxSiz );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003334 return lstrlenW(str);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003335}
3336
3337
3338/**********************************************************************
3339 * HiliteMenuItem16 (USER.162)
3340 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003341BOOL16 WINAPI HiliteMenuItem16( HWND16 hWnd, HMENU16 hMenu, UINT16 wItemID,
3342 UINT16 wHilite )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003343{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003344 return HiliteMenuItem( hWnd, hMenu, wItemID, wHilite );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003345}
3346
3347
3348/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003349 * HiliteMenuItem32 (USER32.318)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003350 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003351BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
3352 UINT wHilite )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003353{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003354 LPPOPUPMENU menu;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003355 TRACE("(%04x, %04x, %04x, %04x);\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +00003356 hWnd, hMenu, wItemID, wHilite);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003357 if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003358 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003359 if (menu->FocusedItem == wItemID) return TRUE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00003360 MENU_HideSubPopups( hWnd, hMenu, FALSE );
Rein Klazes80c924f1999-12-12 19:40:46 +00003361 MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003362 return TRUE;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003363}
3364
3365
3366/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003367 * GetMenuState16 (USER.250)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003368 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003369UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003370{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003371 return GetMenuState( hMenu, wItemID, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003372}
3373
3374
3375/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003376 * GetMenuState (USER32.267)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003377 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003378UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003379{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003380 MENUITEM *item;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003381 TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
Alexandre Julliardaca05781994-10-17 18:12:41 +00003382 hMenu, wItemID, wFlags);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003383 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
Alexandre Julliard03468f71998-02-15 19:40:49 +00003384 debug_print_menuitem (" item: ", item, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003385 if (item->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003386 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003387 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( item->hSubMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003388 if (!menu) return -1;
Alexandre Julliard829fe321998-07-26 14:27:39 +00003389 else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003390 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003391 else
Alexandre Julliard491502b1997-11-01 19:08:16 +00003392 {
Alexandre Julliard829fe321998-07-26 14:27:39 +00003393 /* We used to (from way back then) mask the result to 0xff. */
3394 /* I don't know why and it seems wrong as the documented */
3395 /* return flag MF_SEPARATOR is outside that mask. */
3396 return (item->fType | item->fState);
Alexandre Julliard491502b1997-11-01 19:08:16 +00003397 }
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003398}
3399
3400
3401/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003402 * GetMenuItemCount16 (USER.263)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003403 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003404INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003405{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003406 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003407 if (!IS_A_MENU(menu)) return -1;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003408 TRACE("(%04x) returning %d\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003409 hMenu, menu->nItems );
3410 return menu->nItems;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003411}
3412
3413
3414/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003415 * GetMenuItemCount32 (USER32.262)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003416 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003417INT WINAPI GetMenuItemCount( HMENU hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003418{
3419 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003420 if (!IS_A_MENU(menu)) return -1;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003421 TRACE("(%04x) returning %d\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003422 hMenu, menu->nItems );
3423 return menu->nItems;
3424}
3425
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003426/**********************************************************************
3427 * GetMenuItemID16 (USER.264)
3428 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003429UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003430{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003431 return (UINT16) GetMenuItemID (hMenu, nPos);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003432}
3433
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003434/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003435 * GetMenuItemID32 (USER32.263)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003436 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003437UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003438{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003439 MENUITEM * lpmi;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003440
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003441 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3442 if (lpmi->fType & MF_POPUP) return -1;
3443 return lpmi->wID;
3444
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003445}
3446
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003447/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003448 * InsertMenu16 (USER.410)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003449 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003450BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3451 UINT16 id, SEGPTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003452{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003453 UINT pos32 = (UINT)pos;
3454 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003455 if (IS_STRING_ITEM(flags) && data)
Alexandre Julliarda3960291999-02-26 11:11:13 +00003456 return InsertMenuA( hMenu, pos32, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003457 (LPSTR)PTR_SEG_TO_LIN(data) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003458 return InsertMenuA( hMenu, pos32, flags, id, (LPSTR)data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003459}
3460
3461
3462/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003463 * InsertMenu32A (USER32.322)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003464 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003465BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
3466 UINT id, LPCSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003467{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003468 MENUITEM *item;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003469
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003470 if (IS_STRING_ITEM(flags) && str)
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003471 TRACE("hMenu %04x, pos %d, flags %08x, "
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003472 "id %04x, str '%s'\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003473 hMenu, pos, flags, id, str );
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003474 else TRACE("hMenu %04x, pos %d, flags %08x, "
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003475 "id %04x, str %08lx (not a string)\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003476 hMenu, pos, flags, id, (DWORD)str );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003477
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003478 if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003479
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003480 if (!(MENU_SetItemData( item, flags, id, str )))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003481 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003482 RemoveMenu( hMenu, pos, flags );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003483 return FALSE;
3484 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003485
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003486 if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003487 ((POPUPMENU *)USER_HEAP_LIN_ADDR((HMENU16)id))->wFlags |= MF_POPUP;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003488
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003489 item->hCheckBit = item->hUnCheckBit = 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003490 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003491}
3492
3493
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003494/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003495 * InsertMenu32W (USER32.325)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003496 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003497BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
3498 UINT id, LPCWSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003499{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003500 BOOL ret;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003501
3502 if (IS_STRING_ITEM(flags) && str)
3503 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003504 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003505 ret = InsertMenuA( hMenu, pos, flags, id, newstr );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003506 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003507 return ret;
3508 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003509 else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003510}
3511
3512
3513/*******************************************************************
3514 * AppendMenu16 (USER.411)
3515 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003516BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003517{
3518 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
3519}
3520
3521
3522/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003523 * AppendMenu32A (USER32.5)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003524 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003525BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
3526 UINT id, LPCSTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003527{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003528 return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003529}
3530
3531
3532/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003533 * AppendMenu32W (USER32.6)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003534 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003535BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
3536 UINT id, LPCWSTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003537{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003538 return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003539}
3540
3541
3542/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003543 * RemoveMenu16 (USER.412)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003544 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003545BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003546{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003547 return RemoveMenu( hMenu, nPos, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003548}
3549
3550
3551/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003552 * RemoveMenu (USER32.441)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003553 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003554BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003555{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003556 LPPOPUPMENU menu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003557 MENUITEM *item;
3558
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003559 TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003560 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003561 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003562
3563 /* Remove item */
3564
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003565 MENU_FreeItemData( item );
3566
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003567 if (--menu->nItems == 0)
3568 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003569 HeapFree( SystemHeap, 0, menu->items );
3570 menu->items = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003571 }
3572 else
3573 {
3574 while(nPos < menu->nItems)
3575 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003576 *item = *(item+1);
3577 item++;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003578 nPos++;
3579 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003580 menu->items = HeapReAlloc( SystemHeap, 0, menu->items,
3581 menu->nItems * sizeof(MENUITEM) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003582 }
3583 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003584}
3585
3586
3587/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003588 * DeleteMenu16 (USER.413)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003589 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003590BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003591{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003592 return DeleteMenu( hMenu, nPos, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003593}
3594
3595
3596/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003597 * DeleteMenu32 (USER32.129)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003598 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003599BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003600{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003601 MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
3602 if (!item) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003603 if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003604 /* nPos is now the position of the item */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003605 RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003606 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003607}
3608
3609
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003610/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003611 * ModifyMenu16 (USER.414)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003612 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003613BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3614 UINT16 id, SEGPTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003615{
3616 if (IS_STRING_ITEM(flags))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003617 return ModifyMenuA( hMenu, pos, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003618 (LPSTR)PTR_SEG_TO_LIN(data) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003619 return ModifyMenuA( hMenu, pos, flags, id, (LPSTR)data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003620}
3621
3622
3623/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003624 * ModifyMenu32A (USER32.397)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003625 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003626BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
3627 UINT id, LPCSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003628{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003629 MENUITEM *item;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003630
3631 if (IS_STRING_ITEM(flags))
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003632 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003633 TRACE("%04x %d %04x %04x '%s'\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003634 hMenu, pos, flags, id, str ? str : "#NULL#" );
3635 if (!str) return FALSE;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003636 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003637 else
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003638 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003639 TRACE("%04x %d %04x %04x %08lx\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003640 hMenu, pos, flags, id, (DWORD)str );
3641 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003642
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003643 if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003644 return MENU_SetItemData( item, flags, id, str );
3645}
3646
3647
3648/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003649 * ModifyMenu32W (USER32.398)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003650 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003651BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
3652 UINT id, LPCWSTR str )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003653{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003654 BOOL ret;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003655
3656 if (IS_STRING_ITEM(flags) && str)
3657 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003658 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003659 ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003660 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003661 return ret;
3662 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003663 else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003664}
3665
3666
3667/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003668 * CreatePopupMenu16 (USER.415)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003669 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003670HMENU16 WINAPI CreatePopupMenu16(void)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003671{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003672 return CreatePopupMenu();
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003673}
3674
3675
3676/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003677 * CreatePopupMenu32 (USER32.82)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003678 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003679HMENU WINAPI CreatePopupMenu(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003680{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003681 HMENU hmenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003682 POPUPMENU *menu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003683
Alexandre Julliarda3960291999-02-26 11:11:13 +00003684 if (!(hmenu = CreateMenu())) return 0;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003685 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003686 menu->wFlags |= MF_POPUP;
Pascal Lessard2eb0a301999-09-03 16:38:52 +00003687 menu->bTimeToHide = FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003688 return hmenu;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003689}
3690
3691
3692/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003693 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003694 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003695DWORD WINAPI GetMenuCheckMarkDimensions(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003696{
Alexandre Julliardf7207251994-07-23 07:57:48 +00003697 return MAKELONG( check_bitmap_width, check_bitmap_height );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003698}
3699
3700
3701/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003702 * SetMenuItemBitmaps16 (USER.418)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003703 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003704BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
3705 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003706{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003707 return SetMenuItemBitmaps( hMenu, nPos, wFlags, hNewUnCheck, hNewCheck );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003708}
3709
3710
3711/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003712 * SetMenuItemBitmaps32 (USER32.490)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003713 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003714BOOL WINAPI SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags,
3715 HBITMAP hNewUnCheck, HBITMAP hNewCheck)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003716{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003717 MENUITEM *item;
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003718 TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003719 hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
3720 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003721
3722 if (!hNewCheck && !hNewUnCheck)
3723 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003724 item->fState &= ~MF_USECHECKBITMAPS;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003725 }
3726 else /* Install new bitmaps */
3727 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003728 item->hCheckBit = hNewCheck;
3729 item->hUnCheckBit = hNewUnCheck;
3730 item->fState |= MF_USECHECKBITMAPS;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003731 }
3732 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003733}
3734
3735
3736/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003737 * CreateMenu16 (USER.151)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003738 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003739HMENU16 WINAPI CreateMenu16(void)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003740{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003741 return CreateMenu();
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003742}
3743
3744
3745/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003746 * CreateMenu (USER32.81)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003747 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003748HMENU WINAPI CreateMenu(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003749{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003750 HMENU hMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003751 LPPOPUPMENU menu;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003752 if (!(hMenu = USER_HEAP_ALLOC( sizeof(POPUPMENU) ))) return 0;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003753 menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00003754
3755 ZeroMemory(menu, sizeof(POPUPMENU));
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003756 menu->wMagic = MENU_MAGIC;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003757 menu->FocusedItem = NO_SELECTED_ITEM;
Pascal Lessard2eb0a301999-09-03 16:38:52 +00003758 menu->bTimeToHide = FALSE;
Juergen Schmied78513941999-04-18 14:40:32 +00003759
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003760 TRACE("return %04x\n", hMenu );
Pascal Lessardd9ab1f31999-05-29 10:56:43 +00003761
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003762 return hMenu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003763}
3764
3765
3766/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003767 * DestroyMenu16 (USER.152)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003768 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003769BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003770{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003771 return DestroyMenu( hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003772}
3773
3774
3775/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003776 * DestroyMenu32 (USER32.134)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003777 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003778BOOL WINAPI DestroyMenu( HMENU hMenu )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003779{
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003780 TRACE("(%04x)\n", hMenu);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003781
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003782 /* Silently ignore attempts to destroy default system popup */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003783
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003784 if (hMenu && hMenu != MENU_DefSysPopup)
Alexandre Julliardff8331e1995-09-18 11:19:54 +00003785 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003786 LPPOPUPMENU lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003787 WND *pTPWnd = MENU_GetTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003788
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003789 if( pTPWnd && (hMenu == *(HMENU*)pTPWnd->wExtra) )
3790 *(UINT*)pTPWnd->wExtra = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003791
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003792 if (IS_A_MENU( lppop ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003793 {
3794 lppop->wMagic = 0; /* Mark it as destroyed */
3795
3796 if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003797 (!pTPWnd || (lppop->hWnd != pTPWnd->hwndSelf)))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003798 DestroyWindow( lppop->hWnd );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003799
3800 if (lppop->items) /* recursively destroy submenus */
3801 {
3802 int i;
3803 MENUITEM *item = lppop->items;
3804 for (i = lppop->nItems; i > 0; i--, item++)
3805 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003806 if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003807 MENU_FreeItemData( item );
3808 }
3809 HeapFree( SystemHeap, 0, lppop->items );
3810 }
3811 USER_HEAP_FREE( hMenu );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00003812 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003813 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00003814 else
3815 {
3816 MENU_ReleaseTopPopupWnd();
3817 return FALSE;
3818 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +00003819 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003820 return (hMenu != MENU_DefSysPopup);
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003821}
3822
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003823
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003824/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003825 * GetSystemMenu16 (USER.156)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003826 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003827HMENU16 WINAPI GetSystemMenu16( HWND16 hWnd, BOOL16 bRevert )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003828{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003829 return GetSystemMenu( hWnd, bRevert );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003830}
3831
3832
3833/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003834 * GetSystemMenu32 (USER32.291)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003835 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003836HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003837{
Alexandre Julliardb7258be1995-09-01 15:57:28 +00003838 WND *wndPtr = WIN_FindWndPtr( hWnd );
Eric Pouech562309a1999-08-21 12:59:44 +00003839 HMENU retvalue = 0;
Alexandre Julliardb7258be1995-09-01 15:57:28 +00003840
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003841 if (wndPtr)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003842 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003843 if( wndPtr->hSysMenu )
3844 {
3845 if( bRevert )
3846 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003847 DestroyMenu(wndPtr->hSysMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003848 wndPtr->hSysMenu = 0;
3849 }
3850 else
3851 {
3852 POPUPMENU *menu = (POPUPMENU*)
3853 USER_HEAP_LIN_ADDR(wndPtr->hSysMenu);
Eric Pouech562309a1999-08-21 12:59:44 +00003854 if( IS_A_MENU(menu) )
3855 {
3856 if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
3857 menu->items[0].hSubMenu = MENU_CopySysPopup();
3858 }
3859 else
3860 {
3861 WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
3862 wndPtr->hSysMenu, hWnd);
3863 wndPtr->hSysMenu = 0;
3864 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003865 }
3866 }
3867
3868 if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00003869 wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003870
3871 if( wndPtr->hSysMenu )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003872 {
Eric Pouech562309a1999-08-21 12:59:44 +00003873 POPUPMENU *menu;
3874 retvalue = GetSubMenu16(wndPtr->hSysMenu, 0);
Pascal Lessardd814bb61999-07-31 13:02:02 +00003875
3876 /* Store the dummy sysmenu handle to facilitate the refresh */
3877 /* of the close button if the SC_CLOSE item change */
Eric Pouech562309a1999-08-21 12:59:44 +00003878 menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(retvalue);
3879 if ( IS_A_MENU(menu) )
3880 menu->hSysMenuOwner = wndPtr->hSysMenu;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003881 }
3882 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003883 }
Eric Pouech562309a1999-08-21 12:59:44 +00003884 return retvalue;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003885}
3886
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003887
3888/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003889 * SetSystemMenu16 (USER.280)
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003890 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003891BOOL16 WINAPI SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003892{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003893 return SetSystemMenu( hwnd, hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003894}
3895
3896
3897/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003898 * SetSystemMenu32 (USER32.508)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003899 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003900BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003901{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003902 WND *wndPtr = WIN_FindWndPtr(hwnd);
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003903
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003904 if (wndPtr)
3905 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003906 if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003907 wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003908 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003909 return TRUE;
3910 }
3911 return FALSE;
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003912}
3913
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003914
3915/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003916 * GetMenu16 (USER.157)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003917 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003918HMENU16 WINAPI GetMenu16( HWND16 hWnd )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003919{
Richard Cohen56753621999-09-19 14:08:13 +00003920 return (HMENU16)GetMenu(hWnd);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003921}
3922
3923
3924/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003925 * GetMenu32 (USER32.257)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003926 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003927HMENU WINAPI GetMenu( HWND hWnd )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003928{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003929 HMENU retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003930 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003931 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003932 {
3933 retvalue = (HMENU)wndPtr->wIDmenu;
3934 goto END;
3935 }
3936 retvalue = 0;
3937END:
3938 WIN_ReleaseWndPtr(wndPtr);
3939 return retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003940}
3941
3942
3943/**********************************************************************
3944 * SetMenu16 (USER.158)
3945 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003946BOOL16 WINAPI SetMenu16( HWND16 hWnd, HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003947{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003948 return SetMenu( hWnd, hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003949}
3950
3951
3952/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003953 * SetMenu32 (USER32.487)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003954 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003955BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003956{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003957 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003958
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00003959 TRACE("(%04x, %04x);\n", hWnd, hMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003960
Richard Cohen56753621999-09-19 14:08:13 +00003961 if (hMenu && !IsMenu(hMenu))
3962 {
3963 WARN("hMenu is not a menu handle\n");
3964 return FALSE;
3965 }
3966
3967
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003968 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003969 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003970 if (GetCapture() == hWnd) ReleaseCapture();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003971
Alexandre Julliarda3960291999-02-26 11:11:13 +00003972 wndPtr->wIDmenu = (UINT)hMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003973 if (hMenu != 0)
3974 {
3975 LPPOPUPMENU lpmenu;
3976
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003977 if (!(lpmenu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
3978 {
3979 WIN_ReleaseWndPtr(wndPtr);
3980 return FALSE;
3981 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003982 lpmenu->hWnd = hWnd;
3983 lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
3984 lpmenu->Height = 0; /* Make sure we recalculate the size */
3985 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003986 if (IsWindowVisible(hWnd))
3987 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliard01d63461997-01-20 19:43:45 +00003988 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003989 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003990 return TRUE;
3991 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003992 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003993 return FALSE;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003994}
3995
3996
Alexandre Julliardd18872d1994-05-11 12:18:19 +00003997
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003998/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003999 * GetSubMenu16 (USER.159)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00004000 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004001HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004002{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004003 return GetSubMenu( hMenu, nPos );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004004}
4005
4006
4007/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004008 * GetSubMenu32 (USER32.288)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004009 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004010HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00004011{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00004012 MENUITEM * lpmi;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004013
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00004014 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
4015 if (!(lpmi->fType & MF_POPUP)) return 0;
4016 return lpmi->hSubMenu;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00004017}
4018
4019
4020/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004021 * DrawMenuBar16 (USER.160)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004022 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004023void WINAPI DrawMenuBar16( HWND16 hWnd )
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004024{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004025 DrawMenuBar( hWnd );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004026}
Alexandre Julliardf7207251994-07-23 07:57:48 +00004027
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004028
4029/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004030 * DrawMenuBar (USER32.161)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004031 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004032BOOL WINAPI DrawMenuBar( HWND hWnd )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004033{
4034 LPPOPUPMENU lppop;
4035 WND *wndPtr = WIN_FindWndPtr(hWnd);
4036 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && wndPtr->wIDmenu)
4037 {
4038 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00004039 if (lppop == NULL)
4040 {
4041 WIN_ReleaseWndPtr(wndPtr);
4042 return FALSE;
4043 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004044
4045 lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
Juergen Schmied78513941999-04-18 14:40:32 +00004046 lppop->hwndOwner = hWnd;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004047 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliard01d63461997-01-20 19:43:45 +00004048 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00004049 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004050 return TRUE;
4051 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00004052 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004053 return FALSE;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004054}
4055
4056
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004057/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004058 * EndMenu (USER.187) (USER32.175)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004059 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004060void WINAPI EndMenu(void)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004061{
Alex Korobka4f1ac051999-03-28 09:37:57 +00004062 /*
4063 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
4064 */
4065
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00004066 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004067}
4068
4069
4070/***********************************************************************
4071 * LookupMenuHandle (USER.217)
4072 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004073HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004074{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004075 HMENU hmenu32 = hmenu;
4076 UINT id32 = id;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004077 if (!MENU_FindItem( &hmenu32, &id32, MF_BYCOMMAND )) return 0;
4078 else return hmenu32;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004079}
4080
4081
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004082/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004083 * LoadMenu16 (USER.150)
Alexandre Julliard594997c1995-04-30 10:05:20 +00004084 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004085HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, SEGPTR name )
Alexandre Julliard594997c1995-04-30 10:05:20 +00004086{
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004087 HRSRC16 hRsrc;
4088 HGLOBAL16 handle;
4089 HMENU16 hMenu;
Alexandre Julliard594997c1995-04-30 10:05:20 +00004090
4091 if (HIWORD(name))
4092 {
4093 char *str = (char *)PTR_SEG_TO_LIN( name );
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004094 TRACE("(%04x,'%s')\n", instance, str );
Alexandre Julliard594997c1995-04-30 10:05:20 +00004095 if (str[0] == '#') name = (SEGPTR)atoi( str + 1 );
4096 }
4097 else
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004098 TRACE("(%04x,%04x)\n",instance,LOWORD(name));
Alexandre Julliard594997c1995-04-30 10:05:20 +00004099
4100 if (!name) return 0;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00004101
4102 /* check for Win32 module */
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00004103 if (HIWORD(instance))
Alexandre Julliarda3960291999-02-26 11:11:13 +00004104 return LoadMenuA(instance,PTR_SEG_TO_LIN(name));
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00004105 instance = GetExePtr( instance );
Alexandre Julliard594997c1995-04-30 10:05:20 +00004106
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004107 if (!(hRsrc = FindResource16( instance, name, RT_MENU16 ))) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004108 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
4109 hMenu = LoadMenuIndirect16(LockResource16(handle));
4110 FreeResource16( handle );
Alexandre Julliard594997c1995-04-30 10:05:20 +00004111 return hMenu;
4112}
4113
4114
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004115/*****************************************************************
4116 * LoadMenu32A (USER32.370)
4117 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004118HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004119{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004120 HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004121 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004122 return LoadMenuIndirectA( (LPCVOID)LoadResource( instance, hrsrc ));
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004123}
4124
4125
4126/*****************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004127 * LoadMenu32W (USER32.373)
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004128 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004129HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004130{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004131 HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004132 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004133 return LoadMenuIndirectW( (LPCVOID)LoadResource( instance, hrsrc ));
Alexandre Julliard18f92e71996-07-17 20:02:21 +00004134}
4135
4136
Alexandre Julliard594997c1995-04-30 10:05:20 +00004137/**********************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004138 * LoadMenuIndirect16 (USER.220)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00004139 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004140HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00004141{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00004142 HMENU16 hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004143 WORD version, offset;
4144 LPCSTR p = (LPCSTR)template;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00004145
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004146 TRACE("(%p)\n", template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004147 version = GET_WORD(p);
4148 p += sizeof(WORD);
4149 if (version)
4150 {
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004151 WARN("version must be 0 for Win16\n" );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004152 return 0;
4153 }
4154 offset = GET_WORD(p);
4155 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004156 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004157 if (!MENU_ParseResource( p, hMenu, FALSE ))
Alexandre Julliard7e56f681996-01-31 19:02:28 +00004158 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004159 DestroyMenu( hMenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004160 return 0;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00004161 }
4162 return hMenu;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004163}
4164
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004165
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004166/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004167 * LoadMenuIndirect32A (USER32.371)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004168 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004169HMENU WINAPI LoadMenuIndirectA( LPCVOID template )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004170{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00004171 HMENU16 hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004172 WORD version, offset;
4173 LPCSTR p = (LPCSTR)template;
4174
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004175 TRACE("%p\n", template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004176 version = GET_WORD(p);
4177 p += sizeof(WORD);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004178 switch (version)
4179 {
4180 case 0:
4181 offset = GET_WORD(p);
4182 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004183 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004184 if (!MENU_ParseResource( p, hMenu, TRUE ))
4185 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004186 DestroyMenu( hMenu );
Alexandre Julliard641ee761997-08-04 16:34:36 +00004187 return 0;
4188 }
4189 return hMenu;
4190 case 1:
4191 offset = GET_WORD(p);
4192 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004193 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004194 if (!MENUEX_ParseResource( p, hMenu))
4195 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004196 DestroyMenu( hMenu );
Alexandre Julliard641ee761997-08-04 16:34:36 +00004197 return 0;
4198 }
4199 return hMenu;
4200 default:
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004201 ERR("version %d not supported.\n", version);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004202 return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004203 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004204}
4205
4206
4207/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004208 * LoadMenuIndirect32W (USER32.372)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004209 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004210HMENU WINAPI LoadMenuIndirectW( LPCVOID template )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004211{
4212 /* FIXME: is there anything different between A and W? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004213 return LoadMenuIndirectA( template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004214}
4215
4216
4217/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004218 * IsMenu16 (USER.358)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004219 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004220BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004221{
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004222 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4223 return IS_A_MENU(menu);
4224}
4225
4226
4227/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004228 * IsMenu32 (USER32.346)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004229 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004230BOOL WINAPI IsMenu(HMENU hmenu)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004231{
4232 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4233 return IS_A_MENU(menu);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004234}
4235
Alexandre Julliard641ee761997-08-04 16:34:36 +00004236/**********************************************************************
4237 * GetMenuItemInfo32_common
4238 */
4239
Juergen Schmied78513941999-04-18 14:40:32 +00004240static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
4241 LPMENUITEMINFOA lpmii, BOOL unicode)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004242{
Juergen Schmied78513941999-04-18 14:40:32 +00004243 MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
4244
Alexandre Julliard03468f71998-02-15 19:40:49 +00004245 debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
Juergen Schmied78513941999-04-18 14:40:32 +00004246
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004247 if (!menu)
4248 return FALSE;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004249
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004250 if (lpmii->fMask & MIIM_TYPE) {
4251 lpmii->fType = menu->fType;
4252 switch (MENU_ITEM_TYPE(menu->fType)) {
Juergen Schmied78513941999-04-18 14:40:32 +00004253 case MF_STRING:
4254 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
4255 if (unicode) {
4256 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4257 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4258 } else {
4259 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4260 lpmii->cch = lstrlenA(menu->text);
4261 }
4262 }
4263 break;
4264 case MF_OWNERDRAW:
4265 case MF_BITMAP:
4266 lpmii->dwTypeData = menu->text;
4267 /* fall through */
4268 default:
4269 lpmii->cch = 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004270 }
Alexandre Julliard641ee761997-08-04 16:34:36 +00004271 }
Juergen Schmied78513941999-04-18 14:40:32 +00004272
4273 if (lpmii->fMask & MIIM_STRING) {
4274 if (unicode) {
4275 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4276 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4277 } else {
4278 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4279 lpmii->cch = lstrlenA(menu->text);
4280 }
Alexandre Julliard641ee761997-08-04 16:34:36 +00004281 }
Juergen Schmied78513941999-04-18 14:40:32 +00004282
4283 if (lpmii->fMask & MIIM_FTYPE)
4284 lpmii->fType = menu->fType;
4285
4286 if (lpmii->fMask & MIIM_BITMAP)
4287 lpmii->hbmpItem = menu->hbmpItem;
4288
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004289 if (lpmii->fMask & MIIM_STATE)
4290 lpmii->fState = menu->fState;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004291
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004292 if (lpmii->fMask & MIIM_ID)
4293 lpmii->wID = menu->wID;
4294
4295 if (lpmii->fMask & MIIM_SUBMENU)
4296 lpmii->hSubMenu = menu->hSubMenu;
4297
4298 if (lpmii->fMask & MIIM_CHECKMARKS) {
4299 lpmii->hbmpChecked = menu->hCheckBit;
4300 lpmii->hbmpUnchecked = menu->hUnCheckBit;
4301 }
4302 if (lpmii->fMask & MIIM_DATA)
4303 lpmii->dwItemData = menu->dwItemData;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004304
4305 return TRUE;
4306}
4307
4308/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004309 * GetMenuItemInfoA (USER32.264)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004310 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004311BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
4312 LPMENUITEMINFOA lpmii)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004313{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004314 return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004315}
4316
4317/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004318 * GetMenuItemInfoW (USER32.265)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004319 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004320BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
4321 LPMENUITEMINFOW lpmii)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004322{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004323 return GetMenuItemInfo_common (hmenu, item, bypos,
4324 (LPMENUITEMINFOA)lpmii, TRUE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004325}
4326
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004327/**********************************************************************
4328 * SetMenuItemInfo32_common
4329 */
4330
Alexandre Julliarda3960291999-02-26 11:11:13 +00004331static BOOL SetMenuItemInfo_common(MENUITEM * menu,
4332 const MENUITEMINFOA *lpmii,
4333 BOOL unicode)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004334{
4335 if (!menu) return FALSE;
4336
Juergen Schmied78513941999-04-18 14:40:32 +00004337 if (lpmii->fMask & MIIM_TYPE ) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004338 /* Get rid of old string. */
Juergen Schmied78513941999-04-18 14:40:32 +00004339 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004340 HeapFree(SystemHeap, 0, menu->text);
Juergen Schmied78513941999-04-18 14:40:32 +00004341 menu->text = NULL;
4342 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004343
Juergen Schmied78513941999-04-18 14:40:32 +00004344 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4345 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4346 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
Paul Millar39da2221999-04-11 12:08:42 +00004347
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004348 menu->text = lpmii->dwTypeData;
Juergen Schmied78513941999-04-18 14:40:32 +00004349
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004350 if (IS_STRING_ITEM(menu->fType) && menu->text) {
Juergen Schmied78513941999-04-18 14:40:32 +00004351 if (unicode)
4352 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4353 else
4354 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004355 }
4356 }
Juergen Schmied78513941999-04-18 14:40:32 +00004357
4358 if (lpmii->fMask & MIIM_FTYPE ) {
4359 /* free the string when the type is changing */
4360 if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
4361 HeapFree(SystemHeap, 0, menu->text);
4362 menu->text = NULL;
4363 }
4364 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4365 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4366 }
4367
4368 if (lpmii->fMask & MIIM_STRING ) {
4369 /* free the string when used */
4370 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4371 HeapFree(SystemHeap, 0, menu->text);
4372 if (unicode)
4373 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4374 else
4375 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
4376 }
4377 }
4378
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004379 if (lpmii->fMask & MIIM_STATE)
Juergen Schmied466a6521999-05-02 11:21:08 +00004380 {
4381 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004382 menu->fState = lpmii->fState;
Juergen Schmied466a6521999-05-02 11:21:08 +00004383 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004384
4385 if (lpmii->fMask & MIIM_ID)
4386 menu->wID = lpmii->wID;
4387
Alexandre Julliarda0d77311998-09-13 16:32:00 +00004388 if (lpmii->fMask & MIIM_SUBMENU) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004389 menu->hSubMenu = lpmii->hSubMenu;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00004390 if (menu->hSubMenu) {
4391 POPUPMENU *subMenu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)menu->hSubMenu);
4392 if (IS_A_MENU(subMenu)) {
4393 subMenu->wFlags |= MF_POPUP;
4394 menu->fType |= MF_POPUP;
4395 }
4396 else
4397 /* FIXME: Return an error ? */
4398 menu->fType &= ~MF_POPUP;
4399 }
4400 else
4401 menu->fType &= ~MF_POPUP;
4402 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004403
4404 if (lpmii->fMask & MIIM_CHECKMARKS)
4405 {
4406 menu->hCheckBit = lpmii->hbmpChecked;
4407 menu->hUnCheckBit = lpmii->hbmpUnchecked;
4408 }
4409 if (lpmii->fMask & MIIM_DATA)
4410 menu->dwItemData = lpmii->dwItemData;
4411
Alexandre Julliard03468f71998-02-15 19:40:49 +00004412 debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004413 return TRUE;
4414}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004415
4416/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004417 * SetMenuItemInfo32A (USER32.491)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004418 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004419BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
4420 const MENUITEMINFOA *lpmii)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004421{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004422 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004423 lpmii, FALSE);
4424}
4425
4426/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004427 * SetMenuItemInfo32W (USER32.492)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004428 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004429BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
4430 const MENUITEMINFOW *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004431{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004432 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4433 (const MENUITEMINFOA*)lpmii, TRUE);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004434}
4435
4436/**********************************************************************
Juergen Schmied466a6521999-05-02 11:21:08 +00004437 * SetMenuDefaultItem (USER32.489)
4438 *
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004439 */
Juergen Schmied466a6521999-05-02 11:21:08 +00004440BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004441{
Juergen Schmied466a6521999-05-02 11:21:08 +00004442 UINT i;
4443 POPUPMENU *menu;
4444 MENUITEM *item;
4445
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004446 TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
Alexandre Julliarda845b881998-06-01 10:44:35 +00004447
Juergen Schmied466a6521999-05-02 11:21:08 +00004448 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return FALSE;
Alexandre Julliarda845b881998-06-01 10:44:35 +00004449
Juergen Schmied466a6521999-05-02 11:21:08 +00004450 /* reset all default-item flags */
4451 item = menu->items;
4452 for (i = 0; i < menu->nItems; i++, item++)
4453 {
4454 item->fState &= ~MFS_DEFAULT;
4455 }
4456
4457 /* no default item */
4458 if ( -1 == uItem)
4459 {
4460 return TRUE;
4461 }
Alexandre Julliarda845b881998-06-01 10:44:35 +00004462
Juergen Schmied466a6521999-05-02 11:21:08 +00004463 item = menu->items;
4464 if ( bypos )
4465 {
4466 if ( uItem >= menu->nItems ) return FALSE;
4467 item[uItem].fState |= MFS_DEFAULT;
4468 return TRUE;
4469 }
4470 else
4471 {
4472 for (i = 0; i < menu->nItems; i++, item++)
4473 {
4474 if (item->wID == uItem)
4475 {
4476 item->fState |= MFS_DEFAULT;
4477 return TRUE;
4478 }
4479 }
4480
4481 }
4482 return FALSE;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004483}
4484
Alexandre Julliarda845b881998-06-01 10:44:35 +00004485/**********************************************************************
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00004486 * GetMenuDefaultItem (USER32.260)
Alexandre Julliarda845b881998-06-01 10:44:35 +00004487 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004488UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
Alexandre Julliarda845b881998-06-01 10:44:35 +00004489{
Juergen Schmied466a6521999-05-02 11:21:08 +00004490 POPUPMENU *menu;
4491 MENUITEM * item;
4492 UINT i = 0;
Alexandre Julliarda845b881998-06-01 10:44:35 +00004493
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004494 TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
Alexandre Julliarda845b881998-06-01 10:44:35 +00004495
Juergen Schmied466a6521999-05-02 11:21:08 +00004496 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return -1;
4497
4498 /* find default item */
4499 item = menu->items;
Juergen Schmied49251861999-05-13 18:42:03 +00004500
4501 /* empty menu */
4502 if (! item) return -1;
4503
Juergen Schmied466a6521999-05-02 11:21:08 +00004504 while ( !( item->fState & MFS_DEFAULT ) )
4505 {
4506 i++; item++;
4507 if (i >= menu->nItems ) return -1;
4508 }
4509
4510 /* default: don't return disabled items */
4511 if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
4512
4513 /* search rekursiv when needed */
4514 if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
4515 {
4516 UINT ret;
4517 ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
4518 if ( -1 != ret ) return ret;
4519
4520 /* when item not found in submenu, return the popup item */
4521 }
4522 return ( bypos ) ? i : item->wID;
4523
Alexandre Julliarda845b881998-06-01 10:44:35 +00004524}
4525
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004526/*******************************************************************
4527 * InsertMenuItem16 (USER.441)
4528 *
4529 * FIXME: untested
4530 */
4531BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
4532 const MENUITEMINFO16 *mii )
4533{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004534 MENUITEMINFOA miia;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004535
4536 miia.cbSize = sizeof(miia);
4537 miia.fMask = mii->fMask;
Alexandre Julliard77b99181997-09-14 17:17:23 +00004538 miia.dwTypeData = mii->dwTypeData;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004539 miia.fType = mii->fType;
4540 miia.fState = mii->fState;
4541 miia.wID = mii->wID;
4542 miia.hSubMenu = mii->hSubMenu;
4543 miia.hbmpChecked = mii->hbmpChecked;
4544 miia.hbmpUnchecked = mii->hbmpUnchecked;
4545 miia.dwItemData = mii->dwItemData;
4546 miia.cch = mii->cch;
4547 if (IS_STRING_ITEM(miia.fType))
4548 miia.dwTypeData = PTR_SEG_TO_LIN(miia.dwTypeData);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004549 return InsertMenuItemA( hmenu, pos, byposition, &miia );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004550}
4551
4552
4553/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004554 * InsertMenuItem32A (USER32.323)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004555 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004556BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
4557 const MENUITEMINFOA *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004558{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004559 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00004560 return SetMenuItemInfo_common(item, lpmii, FALSE);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004561}
4562
4563
4564/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004565 * InsertMenuItem32W (USER32.324)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004566 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004567BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
4568 const MENUITEMINFOW *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004569{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004570 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00004571 return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004572}
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004573
4574/**********************************************************************
4575 * CheckMenuRadioItem32 (USER32.47)
4576 */
4577
Alexandre Julliarda3960291999-02-26 11:11:13 +00004578BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
4579 UINT first, UINT last, UINT check,
4580 UINT bypos)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004581{
4582 MENUITEM *mifirst, *milast, *micheck;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004583 HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004584
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004585 TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004586 hMenu, first, last, check, bypos);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004587
4588 mifirst = MENU_FindItem (&mfirst, &first, bypos);
4589 milast = MENU_FindItem (&mlast, &last, bypos);
4590 micheck = MENU_FindItem (&mcheck, &check, bypos);
4591
4592 if (mifirst == NULL || milast == NULL || micheck == NULL ||
4593 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
4594 micheck > milast || micheck < mifirst)
4595 return FALSE;
4596
4597 while (mifirst <= milast)
4598 {
4599 if (mifirst == micheck)
4600 {
4601 mifirst->fType |= MFT_RADIOCHECK;
4602 mifirst->fState |= MFS_CHECKED;
4603 } else {
4604 mifirst->fType &= ~MFT_RADIOCHECK;
4605 mifirst->fState &= ~MFS_CHECKED;
4606 }
4607 mifirst++;
4608 }
4609
4610 return TRUE;
4611}
4612
4613/**********************************************************************
4614 * CheckMenuRadioItem16 (not a Windows API)
4615 */
4616
4617BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu,
4618 UINT16 first, UINT16 last, UINT16 check,
4619 BOOL16 bypos)
4620{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004621 return CheckMenuRadioItem (hMenu, first, last, check, bypos);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004622}
4623
4624/**********************************************************************
4625 * GetMenuItemRect32 (USER32.266)
Pascal Lessard47274231999-02-13 12:21:46 +00004626 *
4627 * ATTENTION: Here, the returned values in rect are the screen
4628 * coordinates of the item just like if the menu was
4629 * always on the upper left side of the application.
4630 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004631 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004632BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
4633 LPRECT rect)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004634{
Pascal Lessard47274231999-02-13 12:21:46 +00004635 POPUPMENU *itemMenu;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004636 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004637 HWND referenceHwnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004638
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004639 TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004640
4641 item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
Pascal Lessard47274231999-02-13 12:21:46 +00004642 referenceHwnd = hwnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004643
Pascal Lessard47274231999-02-13 12:21:46 +00004644 if(!hwnd)
4645 {
4646 itemMenu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
4647 if (itemMenu == NULL)
4648 return FALSE;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004649
Marcus Meissnerac593bb1999-03-17 15:18:28 +00004650 if(itemMenu->hWnd == 0)
Pascal Lessard47274231999-02-13 12:21:46 +00004651 return FALSE;
4652 referenceHwnd = itemMenu->hWnd;
4653 }
4654
4655 if ((rect == NULL) || (item == NULL))
4656 return FALSE;
4657
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004658 *rect = item->rect;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004659
Alexandre Julliarda3960291999-02-26 11:11:13 +00004660 MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
Pascal Lessard47274231999-02-13 12:21:46 +00004661
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004662 return TRUE;
4663}
4664
4665/**********************************************************************
4666 * GetMenuItemRect16 (USER.665)
4667 */
4668
4669BOOL16 WINAPI GetMenuItemRect16 (HWND16 hwnd, HMENU16 hMenu, UINT16 uItem,
4670 LPRECT16 rect)
4671{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004672 RECT r32;
4673 BOOL res;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004674
4675 if (!rect) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004676 res = GetMenuItemRect (hwnd, hMenu, uItem, &r32);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004677 CONV_RECT32TO16 (&r32, rect);
4678 return res;
4679}
Paul Quinn1beaae51998-12-15 15:38:36 +00004680
4681/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004682 * SetMenuInfo
4683 *
4684 * FIXME
4685 * MIM_APPLYTOSUBMENUS
4686 * actually use the items to draw the menu
4687 */
4688BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
4689{
4690 POPUPMENU *menu;
4691
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004692 TRACE("(0x%04x %p)\n", hMenu, lpmi);
Juergen Schmied78513941999-04-18 14:40:32 +00004693
4694 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)USER_HEAP_LIN_ADDR(hMenu)))
4695 {
4696
4697 if (lpmi->fMask & MIM_BACKGROUND)
4698 menu->hbrBack = lpmi->hbrBack;
4699
4700 if (lpmi->fMask & MIM_HELPID)
4701 menu->dwContextHelpID = lpmi->dwContextHelpID;
4702
4703 if (lpmi->fMask & MIM_MAXHEIGHT)
4704 menu->cyMax = lpmi->cyMax;
4705
4706 if (lpmi->fMask & MIM_MENUDATA)
4707 menu->dwMenuData = lpmi->dwMenuData;
4708
4709 if (lpmi->fMask & MIM_STYLE)
4710 menu->dwStyle = lpmi->dwStyle;
4711
4712 return TRUE;
4713 }
4714 return FALSE;
4715}
4716
4717/**********************************************************************
4718 * GetMenuInfo
4719 *
4720 * NOTES
4721 * win98/NT5.0
4722 *
4723 */
4724BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
4725{ POPUPMENU *menu;
4726
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004727 TRACE("(0x%04x %p)\n", hMenu, lpmi);
Juergen Schmied78513941999-04-18 14:40:32 +00004728
4729 if (lpmi && (menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4730 {
4731
4732 if (lpmi->fMask & MIM_BACKGROUND)
4733 lpmi->hbrBack = menu->hbrBack;
4734
4735 if (lpmi->fMask & MIM_HELPID)
4736 lpmi->dwContextHelpID = menu->dwContextHelpID;
4737
4738 if (lpmi->fMask & MIM_MAXHEIGHT)
4739 lpmi->cyMax = menu->cyMax;
4740
4741 if (lpmi->fMask & MIM_MENUDATA)
4742 lpmi->dwMenuData = menu->dwMenuData;
4743
4744 if (lpmi->fMask & MIM_STYLE)
4745 lpmi->dwStyle = menu->dwStyle;
4746
4747 return TRUE;
4748 }
4749 return FALSE;
4750}
4751
4752/**********************************************************************
Paul Quinn1beaae51998-12-15 15:38:36 +00004753 * SetMenuContextHelpId16 (USER.384)
4754 */
Juergen Schmied78513941999-04-18 14:40:32 +00004755BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
Paul Quinn1beaae51998-12-15 15:38:36 +00004756{
Juergen Schmied78513941999-04-18 14:40:32 +00004757 return SetMenuContextHelpId( hMenu, dwContextHelpID );
Paul Quinn1beaae51998-12-15 15:38:36 +00004758}
4759
4760
4761/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004762 * SetMenuContextHelpId (USER32.488)
Paul Quinn1beaae51998-12-15 15:38:36 +00004763 */
Juergen Schmied78513941999-04-18 14:40:32 +00004764BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
Paul Quinn1beaae51998-12-15 15:38:36 +00004765{
Juergen Schmied78513941999-04-18 14:40:32 +00004766 LPPOPUPMENU menu;
4767
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004768 TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
Juergen Schmied78513941999-04-18 14:40:32 +00004769
4770 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4771 {
4772 menu->dwContextHelpID = dwContextHelpID;
4773 return TRUE;
4774 }
4775 return FALSE;
Paul Quinn1beaae51998-12-15 15:38:36 +00004776}
4777
4778/**********************************************************************
4779 * GetMenuContextHelpId16 (USER.385)
4780 */
4781DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
4782{
Juergen Schmied78513941999-04-18 14:40:32 +00004783 return GetMenuContextHelpId( hMenu );
Paul Quinn1beaae51998-12-15 15:38:36 +00004784}
4785
4786/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004787 * GetMenuContextHelpId (USER32.488)
Paul Quinn1beaae51998-12-15 15:38:36 +00004788 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004789DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
Paul Quinn1beaae51998-12-15 15:38:36 +00004790{
Juergen Schmied78513941999-04-18 14:40:32 +00004791 LPPOPUPMENU menu;
4792
Alexandre Julliard9fe7a251999-05-14 08:17:14 +00004793 TRACE("(0x%04x)\n", hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00004794
4795 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4796 {
4797 return menu->dwContextHelpID;
4798 }
4799 return 0;
Paul Quinn1beaae51998-12-15 15:38:36 +00004800}
Eric Pouech0c62bf01999-09-13 15:11:35 +00004801
4802/**********************************************************************
4803 * MenuItemFromPoint (USER32.387)
4804 */
4805UINT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen)
4806{
4807 FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
4808 hWnd, hMenu, ptScreen.x, ptScreen.y);
4809 return 0;
4810}