blob: 19748d5bb9a3e0b046ce58e3bae00706a1568df7 [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 Julliarddba420a1994-02-02 06:48:31 +000023#include "sysmetrics.h"
Alexandre Julliard2ace16a1996-04-28 15:09:19 +000024#include "task.h"
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000025#include "heap.h"
Francois Boisvert197a8e11999-02-13 09:10:17 +000026#include "menu.h"
Alexandre Julliardc6c09441997-01-12 18:32:19 +000027#include "nonclient.h"
Alexandre Julliard1f579291994-05-25 16:25:21 +000028#include "user.h"
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000029#include "message.h"
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +000030#include "resource.h"
Alexandre Julliardd37eb361997-07-20 16:23:21 +000031#include "tweak.h"
Marcus Meissnerd5e7c791998-12-09 11:06:00 +000032
Alexandre Julliardaca05781994-10-17 18:12:41 +000033#include "debug.h"
34
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000035DEFAULT_DEBUG_CHANNEL(menu)
36
Alexandre Julliardd37eb361997-07-20 16:23:21 +000037
Alexandre Julliard7ff1c411997-05-25 13:58:18 +000038/* internal popup menu window messages */
39
40#define MM_SETMENUHANDLE (WM_USER + 0)
41#define MM_GETMENUHANDLE (WM_USER + 1)
42
Alexandre Julliard2d93d001996-05-21 15:01:41 +000043/* Menu item structure */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000044typedef struct {
45 /* ----------- MENUITEMINFO Stuff ----------- */
Juergen Schmied78513941999-04-18 14:40:32 +000046 UINT fType; /* Item type. */
Alexandre Julliarda3960291999-02-26 11:11:13 +000047 UINT fState; /* Item state. */
48 UINT wID; /* Item id. */
49 HMENU hSubMenu; /* Pop-up menu. */
Juergen Schmied78513941999-04-18 14:40:32 +000050 HBITMAP hCheckBit; /* Bitmap when checked. */
Alexandre Julliarda3960291999-02-26 11:11:13 +000051 HBITMAP hUnCheckBit; /* Bitmap when unchecked. */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000052 LPSTR text; /* Item text or bitmap handle. */
53 DWORD dwItemData; /* Application defined. */
Juergen Schmied78513941999-04-18 14:40:32 +000054 DWORD dwTypeData; /* depends on fMask */
55 HBITMAP hbmpItem; /* bitmap in win98 style menus */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000056 /* ----------- Wine stuff ----------- */
Juergen Schmied78513941999-04-18 14:40:32 +000057 RECT rect; /* Item area (relative to menu window) */
58 UINT xTab; /* X position of text after Tab */
Alexandre Julliard2d93d001996-05-21 15:01:41 +000059} MENUITEM;
60
61/* Popup menu structure */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000062typedef struct {
Alexandre Julliard2d93d001996-05-21 15:01:41 +000063 WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
64 WORD wMagic; /* Magic number */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000065 HQUEUE16 hTaskQ; /* Task queue for this menu */
Alexandre Julliard2d93d001996-05-21 15:01:41 +000066 WORD Width; /* Width of the whole menu */
67 WORD Height; /* Height of the whole menu */
68 WORD nItems; /* Number of items in the menu */
Juergen Schmied78513941999-04-18 14:40:32 +000069 HWND hWnd; /* Window containing the menu */
70 MENUITEM *items; /* Array of menu items */
71 UINT FocusedItem; /* Currently focused item */
Alexandre Julliarda845b881998-06-01 10:44:35 +000072 WORD defitem; /* default item position. Unused (except for set/get)*/
Juergen Schmied78513941999-04-18 14:40:32 +000073 HWND hwndOwner; /* window receiving the messages for ownerdraw */
74 /* ------------ MENUINFO members ------ */
75 DWORD dwStyle; /* Extended mennu style */
76 UINT cyMax; /* max hight of the whole menu, 0 is screen hight */
77 HBRUSH hbrBack; /* brush for menu background */
78 DWORD dwContextHelpID;
79 DWORD dwMenuData; /* application defined value */
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;
162
Alexandre Julliarda3960291999-02-26 11:11:13 +0000163static HMENU MENU_DefSysPopup = 0; /* Default system menu popup */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000164
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000165/* Use global popup window because there's no way 2 menus can
166 * be tracked at the same time. */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000167
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000168static WND* pTopPopupWnd = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000169static UINT uSubPWndLevel = 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000170
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000171 /* Flag set by EndMenu() to force an exit from menu tracking */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000172static BOOL fEndMenu = FALSE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000173
174
175/***********************************************************************
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000176 * debug_print_menuitem
177 *
178 * Print a menuitem in readable form.
179 */
180
Alexandre Julliard03468f71998-02-15 19:40:49 +0000181#define debug_print_menuitem(pre, mp, post) \
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000182 if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000183
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000184#define MENUOUT(text) \
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000185 dsprintf(menu, "%s%s", (count++ ? "," : ""), (text))
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000186
187#define MENUFLAG(bit,text) \
188 do { \
189 if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
190 } while (0)
191
Alexandre Julliard03468f71998-02-15 19:40:49 +0000192static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
193 const char *postfix)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000194{
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000195 dbg_decl_str(menu, 256);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000196
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 Julliarda11d7b11998-03-01 20:05:02 +0000200 dsprintf(menu, "{ ID=0x%x", mp->wID);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000201 if (flags & MF_POPUP)
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000202 dsprintf(menu, ", Sub=0x%x", mp->hSubMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000203 if (flags) {
204 int count = 0;
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000205 dsprintf(menu, ", 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");
224 MENUFLAG(MFT_RIGHTJUSTIFY, "right");
225
226 if (flags)
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000227 dsprintf(menu, "+0x%x", flags);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000228 }
229 flags = mp->fState;
230 if (flags) {
231 int count = 0;
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000232 dsprintf(menu, ", State=");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000233 MENUFLAG(MFS_GRAYED, "grey");
234 MENUFLAG(MFS_DISABLED, "dis");
235 MENUFLAG(MFS_CHECKED, "check");
236 MENUFLAG(MFS_HILITE, "hi");
237 MENUFLAG(MF_USECHECKBITMAPS, "usebit");
238 MENUFLAG(MF_MOUSESELECT, "mouse");
239 if (flags)
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000240 dsprintf(menu, "+0x%x", flags);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000241 }
242 if (mp->hCheckBit)
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000243 dsprintf(menu, ", Chk=0x%x", mp->hCheckBit);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000244 if (mp->hUnCheckBit)
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000245 dsprintf(menu, ", Unc=0x%x", mp->hUnCheckBit);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000246
247 if (typ == MFT_STRING) {
248 if (mp->text)
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000249 dsprintf(menu, ", Text=\"%s\"", mp->text);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000250 else
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000251 dsprintf(menu, ", Text=Null");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000252 } else if (mp->text == NULL)
253 /* Nothing */ ;
254 else
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000255 dsprintf(menu, ", Text=%p", mp->text);
Juergen Schmied7abca951999-04-11 17:02:30 +0000256 if (mp->dwItemData)
257 dsprintf(menu, ", ItemData=0x%08lx", mp->dwItemData);
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000258 dsprintf(menu, " }");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000259 } else {
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000260 dsprintf(menu, "NULL");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000261 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000262
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000263 TRACE(menu, "%s %s %s\n", prefix, dbg_str(menu), postfix);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000264}
265
266#undef MENUOUT
267#undef MENUFLAG
268
269/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000270 * MENU_CopySysPopup
271 *
272 * Return the default system menu.
273 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000274static HMENU MENU_CopySysPopup(void)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000275{
Bertho Stultiensd1895a71999-04-25 18:31:35 +0000276 HMENU hMenu = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000277
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000278 if( hMenu ) {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000279 POPUPMENU* menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
280 menu->wFlags |= MF_SYSMENU | MF_POPUP;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000281 }
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000282 else {
283 hMenu = 0;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000284 ERR(menu, "Unable to load default system menu\n" );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000285 }
286
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000287 TRACE(menu, "returning %x.\n", hMenu );
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000288
289 return hMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000290}
291
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000292/***********************************************************************
293 * MENU_GetTopPopupWnd()
294 *
295 * Return the locked pointer pTopPopupWnd.
296 */
297WND *MENU_GetTopPopupWnd()
298{
299 return WIN_LockWndPtr(pTopPopupWnd);
300}
301/***********************************************************************
302 * MENU_ReleaseTopPopupWnd()
303 *
304 * Realease the locked pointer pTopPopupWnd.
305 */
306void MENU_ReleaseTopPopupWnd()
307{
308 WIN_ReleaseWndPtr(pTopPopupWnd);
309}
310/***********************************************************************
311 * MENU_DestroyTopPopupWnd()
312 *
313 * Destroy the locked pointer pTopPopupWnd.
314 */
315void MENU_DestroyTopPopupWnd()
316{
317 WND *tmpWnd = pTopPopupWnd;
318 pTopPopupWnd = NULL;
319 WIN_ReleaseWndPtr(tmpWnd);
320}
321
322
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000323
324/**********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000325 * MENU_GetSysMenu
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000326 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000327 * Create a copy of the system menu. System menu in Windows is
328 * a special menu-bar with the single entry - system menu popup.
329 * This popup is presented to the outside world as a "system menu".
330 * However, the real system menu handle is sometimes seen in the
331 * WM_MENUSELECT paramemters (and Word 6 likes it this way).
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000332 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000333HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu )
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000334{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000335 HMENU hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000336
Alexandre Julliarda3960291999-02-26 11:11:13 +0000337 if ((hMenu = CreateMenu()))
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000338 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000339 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hMenu);
340 menu->wFlags = MF_SYSMENU;
341 menu->hWnd = hWnd;
342
Alexandre Julliarda3960291999-02-26 11:11:13 +0000343 if (hPopupMenu == (HMENU)(-1))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000344 hPopupMenu = MENU_CopySysPopup();
345 else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
346
347 if (hPopupMenu)
348 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000349 InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000350
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000351 menu->items[0].fType = MF_SYSMENU | MF_POPUP;
352 menu->items[0].fState = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000353 menu = (POPUPMENU*) USER_HEAP_LIN_ADDR(hPopupMenu);
354 menu->wFlags |= MF_SYSMENU;
355
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000356 TRACE(menu,"GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000357 return hMenu;
358 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000359 DestroyMenu( hMenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000360 }
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000361 ERR(menu, "failed to load system menu!\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000362 return 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000363}
364
365
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000366/***********************************************************************
367 * MENU_Init
368 *
369 * Menus initialisation.
370 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000371BOOL MENU_Init()
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000372{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000373 HBITMAP hBitmap;
Juergen Schmied78513941999-04-18 14:40:32 +0000374 NONCLIENTMETRICSA ncm;
375
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000376 static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
377 0x55, 0, 0xAA, 0,
378 0x55, 0, 0xAA, 0,
379 0x55, 0, 0xAA, 0 };
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000380
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000381 /* Load menu bitmaps */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000382 hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
383 hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
384 hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
Francois Boisvert8b391741999-02-09 14:09:55 +0000385 /* Load system buttons bitmaps */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000386 hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
387 hBmpMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
388 hBmpMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
389 hBmpMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
390 hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
391 hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000392
393 if (hStdCheck)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000394 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000395 BITMAP bm;
396 GetObjectA( hStdCheck, sizeof(bm), &bm );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000397 check_bitmap_width = bm.bmWidth;
398 check_bitmap_height = bm.bmHeight;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000399 } else
400 return FALSE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000401
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000402 /* Assume that radio checks have the same size as regular check. */
403 if (!hStdRadioCheck)
404 return FALSE;
405
406 if (hStdMnArrow)
Juergen Schmied78513941999-04-18 14:40:32 +0000407 {
408 BITMAP bm;
409 GetObjectA( hStdMnArrow, sizeof(bm), &bm );
410 arrow_bitmap_width = bm.bmWidth;
411 arrow_bitmap_height = bm.bmHeight;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000412 } else
Juergen Schmied78513941999-04-18 14:40:32 +0000413 return FALSE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000414
Juergen Schmied78513941999-04-18 14:40:32 +0000415 if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
416 return FALSE;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000417
Juergen Schmied78513941999-04-18 14:40:32 +0000418 if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
419 return FALSE;
420
421 DeleteObject( hBitmap );
422 if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
423 return FALSE;
424
425 ncm.cbSize = sizeof (NONCLIENTMETRICSA);
426 if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
427 return FALSE;
428
429 if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
430 return FALSE;
431
432 return TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000433}
434
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000435/***********************************************************************
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000436 * MENU_InitSysMenuPopup
437 *
438 * Grey the appropriate items in System menu.
439 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000440static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000441{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000442 BOOL gray;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000443
444 gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000445 EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000446 gray = ((style & WS_MAXIMIZE) != 0);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000447 EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000448 gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000449 EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000450 gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000451 EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000452 gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
Alexandre Julliarda3960291999-02-26 11:11:13 +0000453 EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000454 gray = (clsStyle & CS_NOCLOSE) != 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000455 EnableMenuItem( hmenu, SC_CLOSE, (gray ? MF_GRAYED : MF_ENABLED) );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000456}
457
458
Alexandre Julliard641ee761997-08-04 16:34:36 +0000459/******************************************************************************
460 *
461 * UINT32 MENU_GetStartOfNextColumn(
462 * HMENU32 hMenu )
463 *
464 *****************************************************************************/
465
Alexandre Julliarda3960291999-02-26 11:11:13 +0000466static UINT MENU_GetStartOfNextColumn(
467 HMENU hMenu )
Alexandre Julliard641ee761997-08-04 16:34:36 +0000468{
469 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000470 UINT i = menu->FocusedItem + 1;
Alexandre Julliard641ee761997-08-04 16:34:36 +0000471
472 if(!menu)
473 return NO_SELECTED_ITEM;
474
475 if( i == NO_SELECTED_ITEM )
476 return i;
477
478 for( ; i < menu->nItems; ++i ) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000479 if (menu->items[i].fType & MF_MENUBARBREAK)
Alexandre Julliard641ee761997-08-04 16:34:36 +0000480 return i;
481 }
482
483 return NO_SELECTED_ITEM;
484}
485
486
487/******************************************************************************
488 *
489 * UINT32 MENU_GetStartOfPrevColumn(
490 * HMENU32 hMenu )
491 *
492 *****************************************************************************/
493
Alexandre Julliarda3960291999-02-26 11:11:13 +0000494static UINT MENU_GetStartOfPrevColumn(
495 HMENU hMenu )
Alexandre Julliard641ee761997-08-04 16:34:36 +0000496{
497 POPUPMENU const *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000498 UINT i;
Alexandre Julliard641ee761997-08-04 16:34:36 +0000499
500 if( !menu )
501 return NO_SELECTED_ITEM;
502
503 if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
504 return NO_SELECTED_ITEM;
505
506 /* Find the start of the column */
507
508 for(i = menu->FocusedItem; i != 0 &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000509 !(menu->items[i].fType & MF_MENUBARBREAK);
Alexandre Julliard641ee761997-08-04 16:34:36 +0000510 --i); /* empty */
511
512 if(i == 0)
513 return NO_SELECTED_ITEM;
514
515 for(--i; i != 0; --i) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000516 if (menu->items[i].fType & MF_MENUBARBREAK)
Alexandre Julliard641ee761997-08-04 16:34:36 +0000517 break;
518 }
519
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000520 TRACE(menu, "ret %d.\n", i );
Alexandre Julliard641ee761997-08-04 16:34:36 +0000521
522 return i;
523}
524
525
526
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000527/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000528 * MENU_FindItem
529 *
530 * Find a menu item. Return a pointer on the item, and modifies *hmenu
531 * in case the item was in a sub-menu.
532 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000533static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000534{
535 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000536 UINT i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000537
Juergen Schmied78513941999-04-18 14:40:32 +0000538 if (((*hmenu)==0xffff) || (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(*hmenu)))) return NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000539 if (wFlags & MF_BYPOSITION)
540 {
541 if (*nPos >= menu->nItems) return NULL;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000542 return &menu->items[*nPos];
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000543 }
544 else
545 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000546 MENUITEM *item = menu->items;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000547 for (i = 0; i < menu->nItems; i++, item++)
548 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000549 if (item->wID == *nPos)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000550 {
551 *nPos = i;
552 return item;
553 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000554 else if (item->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000555 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000556 HMENU hsubmenu = item->hSubMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000557 MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
558 if (subitem)
559 {
560 *hmenu = hsubmenu;
561 return subitem;
562 }
563 }
564 }
565 }
566 return NULL;
567}
568
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000569/***********************************************************************
570 * MENU_FreeItemData
571 */
572static void MENU_FreeItemData( MENUITEM* item )
573{
574 /* delete text */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000575 if (IS_STRING_ITEM(item->fType) && item->text)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000576 HeapFree( SystemHeap, 0, item->text );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000577}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000578
579/***********************************************************************
580 * MENU_FindItemByCoords
581 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000582 * Find the item at the specified coordinates (screen coords). Does
583 * not work for child windows and therefore should not be called for
584 * an arbitrary system menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000585 */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000586static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000587 POINT pt, UINT *pos )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000588{
589 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000590 UINT i;
Marcus Meissnerac593bb1999-03-17 15:18:28 +0000591 RECT wrect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000592
Marcus Meissnerac593bb1999-03-17 15:18:28 +0000593 if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
594 pt.x -= wrect.left;pt.y -= wrect.top;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000595 item = menu->items;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000596 for (i = 0; i < menu->nItems; i++, item++)
597 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000598 if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
599 (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000600 {
601 if (pos) *pos = i;
602 return item;
603 }
604 }
605 return NULL;
606}
607
608
609/***********************************************************************
610 * MENU_FindItemByKey
611 *
612 * Find the menu item selected by a key press.
613 * Return item id, -1 if none, -2 if we should close the menu.
614 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000615static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
616 UINT key, BOOL forceMenuChar )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000617{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000618 TRACE(menu,"\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000619
Alexandre Julliarda3960291999-02-26 11:11:13 +0000620 if (!IsMenu( hmenu ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000621 {
622 WND* w = WIN_FindWndPtr(hwndOwner);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000623 hmenu = GetSubMenu(w->hSysMenu, 0);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000624 WIN_ReleaseWndPtr(w);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000625 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000626
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000627 if (hmenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000628 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000629 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
630 MENUITEM *item = menu->items;
631 LONG menuchar;
632
633 if( !forceMenuChar )
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000634 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000635 UINT i;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000636
637 key = toupper(key);
638 for (i = 0; i < menu->nItems; i++, item++)
639 {
Alexandre Julliarda11d7b11998-03-01 20:05:02 +0000640 if (item->text && (IS_STRING_ITEM(item->fType)))
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000641 {
Norman Stevensa83d0651998-10-12 07:25:35 +0000642 char *p = item->text - 2;
643 do
644 {
645 p = strchr (p + 2, '&');
646 }
647 while (p != NULL && p [1] == '&');
648 if (p && (toupper(p[1]) == key)) return i;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000649 }
650 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000651 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000652 menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000653 MAKEWPARAM( key, menu->wFlags ), hmenu );
654 if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000655 if (HIWORD(menuchar) == 1) return (UINT)(-2);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000656 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000657 return (UINT)(-1);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000658}
Francois Boisvert8b391741999-02-09 14:09:55 +0000659/***********************************************************************
660 * MENU_LoadMagicItem
661 *
662 * Load the bitmap associated with the magic menu item and its style
663 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000664
Juergen Schmied78513941999-04-18 14:40:32 +0000665static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
Francois Boisvert8b391741999-02-09 14:09:55 +0000666{
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000667 /*
668 * Magic menu item id's section
669 * These magic id's are used by windows to insert "standard" mdi
670 * buttons (minimize,restore,close) on menu. Under windows,
671 * these magic id's make sure the right things appear when those
672 * bitmap buttons are pressed/selected/released.
673 */
Francois Boisvert8b391741999-02-09 14:09:55 +0000674
675 switch(id)
Juergen Schmied78513941999-04-18 14:40:32 +0000676 { case HBMMENU_SYSTEM:
677 return (dwItemData) ?
678 (HBITMAP)dwItemData :
679 (hilite ? hBmpMinimizeD : hBmpMinimize);
680 case HBMMENU_MBAR_RESTORE:
681 return (hilite ? hBmpMaximizeD: hBmpMaximize);
682 case HBMMENU_MBAR_MINIMIZE:
683 return (hilite ? hBmpMinimizeD : hBmpMinimize);
684 case HBMMENU_MBAR_CLOSE:
685 return (hilite ? hBmpCloseD : hBmpClose);
686 case HBMMENU_CALLBACK:
687 case HBMMENU_MBAR_CLOSE_D:
688 case HBMMENU_MBAR_MINIMIZE_D:
689 case HBMMENU_POPUP_CLOSE:
690 case HBMMENU_POPUP_RESTORE:
691 case HBMMENU_POPUP_MAXIMIZE:
692 case HBMMENU_POPUP_MINIMIZE:
693 default:
694 FIXME(menu,"Magic 0x%08x not implemented\n", id);
695 return 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000696 }
697
698}
Alexandre Julliardf7207251994-07-23 07:57:48 +0000699
700/***********************************************************************
701 * MENU_CalcItemSize
702 *
703 * Calculate the size of the menu item and store it in lpitem->rect.
704 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000705static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
706 INT orgX, INT orgY, BOOL menuBar )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000707{
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000708 char *p;
709
Juergen Schmied78513941999-04-18 14:40:32 +0000710 TRACE(menu, "dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000711 debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
712 (menuBar ? " (MenuBar)" : ""));
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000713
Alexandre Julliarda3960291999-02-26 11:11:13 +0000714 SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000715
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000716 if (lpitem->fType & MF_OWNERDRAW)
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000717 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000718 MEASUREITEMSTRUCT mis;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000719 mis.CtlType = ODT_MENU;
Juergen Schmied7abca951999-04-11 17:02:30 +0000720 mis.CtlID = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000721 mis.itemID = lpitem->wID;
Juergen Schmied7abca951999-04-11 17:02:30 +0000722 mis.itemData = (DWORD)lpitem->dwItemData;
723 mis.itemHeight = 0;
724 mis.itemWidth = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000725 SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000726 lpitem->rect.bottom += mis.itemHeight;
727 lpitem->rect.right += mis.itemWidth;
Juergen Schmied78513941999-04-18 14:40:32 +0000728 TRACE(menu, "id=%04x size=%dx%d\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000729 lpitem->wID, mis.itemWidth, mis.itemHeight);
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000730 return;
Alexandre Julliardfa68b751995-04-03 16:55:37 +0000731 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000732
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000733 if (lpitem->fType & MF_SEPARATOR)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000734 {
735 lpitem->rect.bottom += SEPARATOR_HEIGHT;
736 return;
737 }
738
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000739 if (!menuBar)
740 {
741 lpitem->rect.right += 2 * check_bitmap_width;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000742 if (lpitem->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000743 lpitem->rect.right += arrow_bitmap_width;
744 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000745
Juergen Schmied78513941999-04-18 14:40:32 +0000746 if (IS_BITMAP_ITEM(lpitem->fType))
Alexandre Julliardf7207251994-07-23 07:57:48 +0000747 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000748 BITMAP bm;
Juergen Schmied78513941999-04-18 14:40:32 +0000749 HBITMAP resBmp = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +0000750
Juergen Schmied78513941999-04-18 14:40:32 +0000751 // Check if there is a magic menu item associated with this item
752 if((LOWORD((int)lpitem->text))<12)
753 {
754 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
755 lpitem->dwItemData);
Francois Boisvert8b391741999-02-09 14:09:55 +0000756 }
757 else
Alexandre Julliarda3960291999-02-26 11:11:13 +0000758 resBmp = (HBITMAP)lpitem->text;
Francois Boisvert8b391741999-02-09 14:09:55 +0000759
Alexandre Julliarda3960291999-02-26 11:11:13 +0000760 if (GetObjectA(resBmp, sizeof(bm), &bm ))
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000761 {
762 lpitem->rect.right += bm.bmWidth;
763 lpitem->rect.bottom += bm.bmHeight;
Francois Boisvert8b391741999-02-09 14:09:55 +0000764
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000765 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000766 }
767
Juergen Schmied78513941999-04-18 14:40:32 +0000768
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000769 /* If we get here, then it must be a text item */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000770 if (IS_STRING_ITEM( lpitem->fType ))
Juergen Schmied78513941999-04-18 14:40:32 +0000771 { SIZE size;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000772
Juergen Schmied78513941999-04-18 14:40:32 +0000773 GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
774
775 lpitem->rect.right += size.cx;
776 if (TWEAK_WineLook == WIN31_LOOK)
777 lpitem->rect.bottom += MAX( size.cy, SYSMETRICS_CYMENU );
778 else
779 lpitem->rect.bottom += MAX (size.cy, sysMetrics[SM_CYMENU]- 1);
780 lpitem->xTab = 0;
781
782 if (menuBar)
783 {
784 lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
785 }
786 else if ((p = strchr( lpitem->text, '\t' )) != NULL)
787 {
788 /* Item contains a tab (only meaningful in popup menus) */
789 GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
790 lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
791 lpitem->rect.right += MENU_TAB_SPACE;
792 }
793 else
794 {
795 if (strchr( lpitem->text, '\b' ))
796 lpitem->rect.right += MENU_TAB_SPACE;
797 lpitem->xTab = lpitem->rect.right - check_bitmap_width
798 - arrow_bitmap_width;
799 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000800 }
Juergen Schmied78513941999-04-18 14:40:32 +0000801 TRACE(menu,"(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
Alexandre Julliardf7207251994-07-23 07:57:48 +0000802}
803
804
805/***********************************************************************
806 * MENU_PopupMenuCalcSize
807 *
808 * Calculate the size of a popup menu.
809 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000810static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000811{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000812 MENUITEM *lpitem;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000813 HDC hdc;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000814 int start, i;
815 int orgX, orgY, maxX, maxTab, maxTabWidth;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000816
Alexandre Julliardf7207251994-07-23 07:57:48 +0000817 lppop->Width = lppop->Height = 0;
818 if (lppop->nItems == 0) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000819 hdc = GetDC( 0 );
Juergen Schmied78513941999-04-18 14:40:32 +0000820
821 SelectObject( hdc, hMenuFont);
822
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000823 start = 0;
824 maxX = SYSMETRICS_CXBORDER;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000825 while (start < lppop->nItems)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000826 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000827 lpitem = &lppop->items[start];
Alexandre Julliardf7207251994-07-23 07:57:48 +0000828 orgX = maxX;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000829 orgY = SYSMETRICS_CYBORDER;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000830
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000831 maxTab = maxTabWidth = 0;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000832
833 /* Parse items until column break or end of menu */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000834 for (i = start; i < lppop->nItems; i++, lpitem++)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000835 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000836 if ((i != start) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000837 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000838
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000839 if (TWEAK_WineLook > WIN31_LOOK)
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000840 ++orgY;
841
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000842 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
Pascal Lessard47274231999-02-13 12:21:46 +0000843
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000844 if (lpitem->fType & MF_MENUBARBREAK) orgX++;
Alexandre Julliard902da691995-11-05 14:39:02 +0000845 maxX = MAX( maxX, lpitem->rect.right );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000846 orgY = lpitem->rect.bottom;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000847 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000848 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000849 maxTab = MAX( maxTab, lpitem->xTab );
850 maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000851 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000852 }
853
854 /* Finish the column (set all items to the largest width found) */
Alexandre Julliard902da691995-11-05 14:39:02 +0000855 maxX = MAX( maxX, maxTab + maxTabWidth );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000856 for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000857 {
858 lpitem->rect.right = maxX;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000859 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000860 lpitem->xTab = maxTab;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000861 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000862 lppop->Height = MAX( lppop->Height, orgY );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000863 }
864
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000865 if(TWEAK_WineLook > WIN31_LOOK)
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000866 lppop->Height++;
867
Alexandre Julliardf7207251994-07-23 07:57:48 +0000868 lppop->Width = maxX;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000869 ReleaseDC( 0, hdc );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000870}
871
872
873/***********************************************************************
874 * MENU_MenuBarCalcSize
875 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000876 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000877 * height is off by 1 pixel which causes lengthy window relocations when
878 * active document window is maximized/restored.
879 *
Alexandre Julliardf7207251994-07-23 07:57:48 +0000880 * Calculate the size of the menu bar.
881 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000882static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
883 LPPOPUPMENU lppop, HWND hwndOwner )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000884{
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000885 MENUITEM *lpitem;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000886 int start, i, orgX, orgY, maxY, helpPos;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000887
888 if ((lprect == NULL) || (lppop == NULL)) return;
889 if (lppop->nItems == 0) return;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000890 TRACE(menu,"left=%d top=%d right=%d bottom=%d\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000891 lprect->left, lprect->top, lprect->right, lprect->bottom);
Alexandre Julliardf7207251994-07-23 07:57:48 +0000892 lppop->Width = lprect->right - lprect->left;
893 lppop->Height = 0;
894 maxY = lprect->top;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000895 start = 0;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000896 helpPos = -1;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000897 while (start < lppop->nItems)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000898 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000899 lpitem = &lppop->items[start];
Alexandre Julliardf7207251994-07-23 07:57:48 +0000900 orgX = lprect->left;
901 orgY = maxY;
902
903 /* Parse items until line break or end of menu */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000904 for (i = start; i < lppop->nItems; i++, lpitem++)
Alexandre Julliardf7207251994-07-23 07:57:48 +0000905 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000906 if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000907 if ((i != start) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000908 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000909
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000910 TRACE(menu, "calling MENU_CalcItemSize org=(%d, %d)\n",
911 orgX, orgY );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000912 debug_print_menuitem (" item: ", lpitem, "");
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000913 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
Pascal Lessard47274231999-02-13 12:21:46 +0000914
Alexandre Julliardf7207251994-07-23 07:57:48 +0000915 if (lpitem->rect.right > lprect->right)
916 {
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000917 if (i != start) break;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000918 else lpitem->rect.right = lprect->right;
919 }
Alexandre Julliard902da691995-11-05 14:39:02 +0000920 maxY = MAX( maxY, lpitem->rect.bottom );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000921 orgX = lpitem->rect.right;
922 }
923
924 /* Finish the line (set all items to the largest height found) */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000925 while (start < i) lppop->items[start++].rect.bottom = maxY;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000926 }
927
928 lprect->bottom = maxY;
929 lppop->Height = lprect->bottom - lprect->top;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000930
931 /* Flush right all items between the MF_HELP and the last item */
932 /* (if several lines, only move the last line) */
933 if (helpPos != -1)
934 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000935 lpitem = &lppop->items[lppop->nItems-1];
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000936 orgY = lpitem->rect.top;
937 orgX = lprect->right;
938 for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
939 {
940 if (lpitem->rect.top != orgY) break; /* Other line */
941 if (lpitem->rect.right >= orgX) break; /* Too far right already */
942 lpitem->rect.left += orgX - lpitem->rect.right;
943 lpitem->rect.right = orgX;
944 orgX = lpitem->rect.left;
945 }
946 }
Alexandre Julliardf7207251994-07-23 07:57:48 +0000947}
948
Alexandre Julliardf7207251994-07-23 07:57:48 +0000949/***********************************************************************
950 * MENU_DrawMenuItem
951 *
952 * Draw a single menu item.
953 */
Juergen Schmied78513941999-04-18 14:40:32 +0000954static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000955 UINT height, BOOL menuBar, UINT odaction )
Alexandre Julliardf7207251994-07-23 07:57:48 +0000956{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000957 RECT rect;
Alexandre Julliardf7207251994-07-23 07:57:48 +0000958
Alexandre Julliard03468f71998-02-15 19:40:49 +0000959 debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000960
961 if (lpitem->fType & MF_SYSMENU)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000962 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000963 if( !IsIconic(hwnd) ) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000964 if (TWEAK_WineLook > WIN31_LOOK)
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000965 NC_DrawSysButton95( hwnd, hdc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000966 lpitem->fState &
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000967 (MF_HILITE | MF_MOUSESELECT) );
968 else
969 NC_DrawSysButton( hwnd, hdc,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000970 lpitem->fState &
Alexandre Julliardd37eb361997-07-20 16:23:21 +0000971 (MF_HILITE | MF_MOUSESELECT) );
972 }
973
Alexandre Julliard7ff1c411997-05-25 13:58:18 +0000974 return;
975 }
976
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000977 if (lpitem->fType & MF_OWNERDRAW)
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000978 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000979 DRAWITEMSTRUCT dis;
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000980
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000981 dis.CtlType = ODT_MENU;
Juergen Schmied7abca951999-04-11 17:02:30 +0000982 dis.CtlID = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000983 dis.itemID = lpitem->wID;
Juergen Schmied7abca951999-04-11 17:02:30 +0000984 dis.itemData = (DWORD)lpitem->dwItemData;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000985 dis.itemState = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000986 if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
987 if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
988 if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000989 dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
Juergen Schmied78513941999-04-18 14:40:32 +0000990 dis.hwndItem = hmenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000991 dis.hDC = hdc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000992 dis.rcItem = lpitem->rect;
Juergen Schmied78513941999-04-18 14:40:32 +0000993 TRACE(menu, "Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
994 "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
995 dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
996 dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
997 dis.rcItem.bottom);
998 SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000999 return;
Alexandre Julliardfa68b751995-04-03 16:55:37 +00001000 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001001
Juergen Schmied78513941999-04-18 14:40:32 +00001002 TRACE(menu, "rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
1003 lpitem->rect.right,lpitem->rect.bottom);
1004
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001005 if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
Juergen Schmied78513941999-04-18 14:40:32 +00001006
Alexandre Julliardf7207251994-07-23 07:57:48 +00001007 rect = lpitem->rect;
1008
Juergen Schmied78513941999-04-18 14:40:32 +00001009 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
1010 if ((menuBar) && (TWEAK_WineLook==WIN98_LOOK))
1011 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
1012 else
1013 FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001014 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001015 FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001016
Alexandre Julliarda3960291999-02-26 11:11:13 +00001017 SetBkMode( hdc, TRANSPARENT );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001018
Juergen Schmied78513941999-04-18 14:40:32 +00001019 /* vertical separator */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001020 if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
Alexandre Julliardf7207251994-07-23 07:57:48 +00001021 {
Juergen Schmied78513941999-04-18 14:40:32 +00001022 if (TWEAK_WineLook > WIN31_LOOK)
1023 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001024 RECT rc = rect;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001025 rc.top = 3;
1026 rc.bottom = height - 3;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001027 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001028 }
Juergen Schmied78513941999-04-18 14:40:32 +00001029 else
1030 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001031 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1032 MoveTo16( hdc, rect.left, 0 );
1033 LineTo( hdc, rect.left, height );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001034 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001035 }
Juergen Schmied78513941999-04-18 14:40:32 +00001036
1037 /* horizontal separator */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001038 if (lpitem->fType & MF_SEPARATOR)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001039 {
Juergen Schmied78513941999-04-18 14:40:32 +00001040 if (TWEAK_WineLook > WIN31_LOOK)
1041 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001042 RECT rc = rect;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001043 rc.left++;
1044 rc.right--;
1045 rc.top += SEPARATOR_HEIGHT / 2;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001046 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001047 }
Juergen Schmied78513941999-04-18 14:40:32 +00001048 else
1049 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001050 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1051 MoveTo16( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2 );
1052 LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001053 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001054 return;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001055 }
1056
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001057 /* Setup colors */
1058
Juergen Schmied78513941999-04-18 14:40:32 +00001059 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001060 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001061 if (lpitem->fState & MF_GRAYED)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001062 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001063 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001064 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
1065 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001066 }
1067 else
1068 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001069 if (lpitem->fState & MF_GRAYED)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001070 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001071 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001072 SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
1073 SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001074 }
1075
Juergen Schmied78513941999-04-18 14:40:32 +00001076 /* helper lines for debugging */
1077/* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1078 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1079 MoveTo16( hdc, rect.left, (rect.top + rect.bottom)/2 );
1080 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1081*/
1082
Alexandre Julliardf7207251994-07-23 07:57:48 +00001083 if (!menuBar)
1084 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001085 INT y = rect.top + rect.bottom;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001086
1087 /* Draw the check mark
1088 *
Huw D M Davies2d617be1998-12-08 09:14:09 +00001089 * FIXME:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001090 * Custom checkmark bitmaps are monochrome but not always 1bpp.
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001091 */
Alexandre Julliardf7207251994-07-23 07:57:48 +00001092
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001093 if (lpitem->fState & MF_CHECKED)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001094 {
Juergen Schmied78513941999-04-18 14:40:32 +00001095 HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
1096 ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001097 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001098
Alexandre Julliarda3960291999-02-26 11:11:13 +00001099 SelectObject( hdcMem, bm );
Juergen Schmied78513941999-04-18 14:40:32 +00001100 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001101 check_bitmap_width, check_bitmap_height,
1102 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001103 DeleteDC( hdcMem );
Juergen Schmied78513941999-04-18 14:40:32 +00001104 }
1105 else if (lpitem->hUnCheckBit)
1106 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001107 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001108
Alexandre Julliarda3960291999-02-26 11:11:13 +00001109 SelectObject( hdcMem, lpitem->hUnCheckBit );
Juergen Schmied78513941999-04-18 14:40:32 +00001110 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001111 check_bitmap_width, check_bitmap_height,
1112 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001113 DeleteDC( hdcMem );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001114 }
Juergen Schmied78513941999-04-18 14:40:32 +00001115
Alexandre Julliardf7207251994-07-23 07:57:48 +00001116 /* Draw the popup-menu arrow */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001117 if (lpitem->fType & MF_POPUP)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001118 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001119 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001120
Alexandre Julliarda3960291999-02-26 11:11:13 +00001121 SelectObject( hdcMem, hStdMnArrow );
Juergen Schmied78513941999-04-18 14:40:32 +00001122 BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001123 (y - arrow_bitmap_height) / 2,
1124 arrow_bitmap_width, arrow_bitmap_height,
1125 hdcMem, 0, 0, SRCCOPY );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001126 DeleteDC( hdcMem );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001127 }
1128
1129 rect.left += check_bitmap_width;
1130 rect.right -= arrow_bitmap_width;
1131 }
1132
Juergen Schmied78513941999-04-18 14:40:32 +00001133 /* Draw the item text or bitmap */
1134 if (IS_BITMAP_ITEM(lpitem->fType))
1135 { int top;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001136
Alexandre Julliarda3960291999-02-26 11:11:13 +00001137 HBITMAP resBmp = 0;
Francois Boisvert8b391741999-02-09 14:09:55 +00001138
Alexandre Julliarda3960291999-02-26 11:11:13 +00001139 HDC hdcMem = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +00001140
Juergen Schmied78513941999-04-18 14:40:32 +00001141 // Check if there is a magic menu item associated with this item
1142 // and load the appropriate bitmap
1143 if((LOWORD((int)lpitem->text)) < 12)
1144 {
1145 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
1146 lpitem->dwItemData);
Francois Boisvert8b391741999-02-09 14:09:55 +00001147 }
1148 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001149 resBmp = (HBITMAP)lpitem->text;
Juergen Schmied78513941999-04-18 14:40:32 +00001150
1151 if (resBmp)
1152 {
1153 BITMAP bm;
1154 GetObjectA( resBmp, sizeof(bm), &bm );
1155
1156 SelectObject(hdcMem,resBmp );
1157
1158 /* handle fontsize > bitmap_height */
1159 top = ((rect.bottom-rect.top)>bm.bmHeight) ?
1160 rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
1161
1162 BitBlt( hdc, rect.left, top, rect.right - rect.left,
Huw D M Davies2d617be1998-12-08 09:14:09 +00001163 rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
Juergen Schmied78513941999-04-18 14:40:32 +00001164 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001165 DeleteDC( hdcMem );
Juergen Schmied78513941999-04-18 14:40:32 +00001166
Alexandre Julliardf7207251994-07-23 07:57:48 +00001167 return;
Francois Boisvert8b391741999-02-09 14:09:55 +00001168
Alexandre Julliardf7207251994-07-23 07:57:48 +00001169 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001170 /* No bitmap - process text if present */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001171 else if (IS_STRING_ITEM(lpitem->fType))
Alexandre Julliardf7207251994-07-23 07:57:48 +00001172 {
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001173 register int i;
Juergen Schmied78513941999-04-18 14:40:32 +00001174 UINT uFormat = (menuBar) ?
1175 DT_CENTER | DT_VCENTER | DT_SINGLELINE :
1176 DT_LEFT | DT_VCENTER | DT_SINGLELINE;
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001177
Alexandre Julliardf7207251994-07-23 07:57:48 +00001178 if (menuBar)
1179 {
1180 rect.left += MENU_BAR_ITEMS_SPACE / 2;
1181 rect.right -= MENU_BAR_ITEMS_SPACE / 2;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001182 i = strlen( lpitem->text );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001183 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001184 else
Alexandre Julliardf7207251994-07-23 07:57:48 +00001185 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001186 for (i = 0; lpitem->text[i]; i++)
1187 if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
1188 break;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001189 }
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001190
Juergen Schmied78513941999-04-18 14:40:32 +00001191 if((TWEAK_WineLook == WIN31_LOOK) || !(lpitem->fState & MF_GRAYED))
1192 {
1193 DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001194 }
Juergen Schmied78513941999-04-18 14:40:32 +00001195 else
1196 { if (!(lpitem->fState & MF_HILITE))
1197 {
Alexandre Julliard641ee761997-08-04 16:34:36 +00001198 ++rect.left;
1199 ++rect.top;
1200 ++rect.right;
1201 ++rect.bottom;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001202 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
Juergen Schmied78513941999-04-18 14:40:32 +00001203 DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001204 --rect.left;
1205 --rect.top;
1206 --rect.right;
1207 --rect.bottom;
1208 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001209 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
Juergen Schmied78513941999-04-18 14:40:32 +00001210 DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001211 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001212
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001213 if (lpitem->text[i]) /* There's a tab or flush-right char */
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001214 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001215 if (lpitem->text[i] == '\t')
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001216 {
1217 rect.left = lpitem->xTab;
Juergen Schmied78513941999-04-18 14:40:32 +00001218 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001219 }
Juergen Schmied78513941999-04-18 14:40:32 +00001220 else DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001221 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001222 }
1223}
1224
1225
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001226/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001227 * MENU_DrawPopupMenu
1228 *
1229 * Paint a popup menu.
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001230 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001231static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001232{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001233 HBRUSH hPrevBrush = 0;
1234 RECT rect;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001235
Juergen Schmied78513941999-04-18 14:40:32 +00001236 TRACE(menu,"wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
1237
Alexandre Julliarda3960291999-02-26 11:11:13 +00001238 GetClientRect( hwnd, &rect );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001239
Alex Korobka44a1b591999-04-01 12:03:52 +00001240 if(TWEAK_WineLook == WIN31_LOOK)
1241 {
Alexandre Julliard641ee761997-08-04 16:34:36 +00001242 rect.bottom -= POPUP_YSHADE * SYSMETRICS_CYBORDER;
1243 rect.right -= POPUP_XSHADE * SYSMETRICS_CXBORDER;
Alex Korobka44a1b591999-04-01 12:03:52 +00001244 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001245
Juergen Schmied78513941999-04-18 14:40:32 +00001246 if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
1247 && (SelectObject( hdc, hMenuFont)))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001248 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001249 HPEN hPrevPen;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001250
Alexandre Julliarda3960291999-02-26 11:11:13 +00001251 Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001252
Alexandre Julliarda3960291999-02-26 11:11:13 +00001253 hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001254 if( hPrevPen )
1255 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001256 INT ropPrev, i;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001257 POPUPMENU *menu;
1258
1259 /* draw 3-d shade */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001260 if(TWEAK_WineLook == WIN31_LOOK) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001261 SelectObject( hdc, hShadeBrush );
1262 SetBkMode( hdc, TRANSPARENT );
1263 ropPrev = SetROP2( hdc, R2_MASKPEN );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001264
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001265 i = rect.right; /* why SetBrushOrg() doesn't? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001266 PatBlt( hdc, i & 0xfffffffe,
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001267 rect.top + POPUP_YSHADE*SYSMETRICS_CYBORDER,
1268 i%2 + POPUP_XSHADE*SYSMETRICS_CXBORDER,
1269 rect.bottom - rect.top, 0x00a000c9 );
1270 i = rect.bottom;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001271 PatBlt( hdc, rect.left + POPUP_XSHADE*SYSMETRICS_CXBORDER,
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001272 i & 0xfffffffe,rect.right - rect.left,
1273 i%2 + POPUP_YSHADE*SYSMETRICS_CYBORDER, 0x00a000c9 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001274 SelectObject( hdc, hPrevPen );
1275 SelectObject( hdc, hPrevBrush );
1276 SetROP2( hdc, ropPrev );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001277 }
1278 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001279 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001280
1281 /* draw menu items */
1282
1283 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
1284 if (menu && menu->nItems)
1285 {
1286 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001287 UINT u;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001288
1289 for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
Juergen Schmied78513941999-04-18 14:40:32 +00001290 MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
1291 menu->Height, FALSE, ODA_DRAWENTIRE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001292
1293 }
Juergen Schmied78513941999-04-18 14:40:32 +00001294 } else
1295 {
1296 SelectObject( hdc, hPrevBrush );
1297 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001298 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001299}
1300
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001301/***********************************************************************
1302 * MENU_DrawMenuBar
1303 *
1304 * Paint a menu bar. Returns the height of the menu bar.
Juergen Schmied78513941999-04-18 14:40:32 +00001305 * called from [windows/nonclient.c]
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001306 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001307UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
1308 BOOL suppress_draw)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001309{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001310 LPPOPUPMENU lppop;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001311 UINT i,retvalue;
Juergen Schmied78513941999-04-18 14:40:32 +00001312 HFONT hfontOld = 0;
1313
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001314 WND *wndPtr = WIN_FindWndPtr( hwnd );
1315
Juergen Schmied78513941999-04-18 14:40:32 +00001316 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR( (HMENU)wndPtr->wIDmenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001317 if (lppop == NULL || lprect == NULL)
1318 {
1319 retvalue = SYSMETRICS_CYMENU;
1320 goto END;
1321 }
Juergen Schmied78513941999-04-18 14:40:32 +00001322
1323 TRACE(menu,"(%04x, %p, %p)\n", hDC, lprect, lppop);
1324
1325 hfontOld = SelectObject( hDC, hMenuFont);
1326
1327 if (lppop->Height == 0)
1328 MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
1329
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001330 lprect->bottom = lprect->top + lppop->Height;
Juergen Schmied78513941999-04-18 14:40:32 +00001331
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001332 if (suppress_draw)
1333 {
1334 retvalue = lppop->Height;
1335 goto END;
1336 }
Juergen Schmied78513941999-04-18 14:40:32 +00001337
Alexandre Julliarda3960291999-02-26 11:11:13 +00001338 FillRect(hDC, lprect, GetSysColorBrush(COLOR_MENU) );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001339
Juergen Schmied78513941999-04-18 14:40:32 +00001340 if (TWEAK_WineLook == WIN31_LOOK)
1341 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001342 SelectObject( hDC, GetSysColorPen(COLOR_WINDOWFRAME) );
1343 MoveTo16( hDC, lprect->left, lprect->bottom );
1344 LineTo( hDC, lprect->right, lprect->bottom );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001345 }
Juergen Schmied78513941999-04-18 14:40:32 +00001346 else
1347 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001348 SelectObject( hDC, GetSysColorPen(COLOR_3DFACE));
1349 MoveTo16( hDC, lprect->left, lprect->bottom );
1350 LineTo( hDC, lprect->right, lprect->bottom );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001351 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001352
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001353 if (lppop->nItems == 0)
1354 {
1355 retvalue = SYSMETRICS_CYMENU;
1356 goto END;
1357 }
Juergen Schmied78513941999-04-18 14:40:32 +00001358
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001359 for (i = 0; i < lppop->nItems; i++)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001360 {
Juergen Schmied78513941999-04-18 14:40:32 +00001361 MENU_DrawMenuItem( hwnd, (HMENU)wndPtr->wIDmenu, GetWindow(hwnd,GW_OWNER),
1362 hDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001363 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001364 retvalue = lppop->Height;
Juergen Schmied78513941999-04-18 14:40:32 +00001365
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001366END:
Juergen Schmied78513941999-04-18 14:40:32 +00001367 if (hfontOld)
1368 SelectObject (hDC, hfontOld);
1369
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001370 WIN_ReleaseWndPtr(wndPtr);
1371 return retvalue;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001372}
1373
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001374/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001375 * MENU_PatchResidentPopup
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001376 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001377BOOL MENU_PatchResidentPopup( HQUEUE16 checkQueue, WND* checkWnd )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001378{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001379 WND *pTPWnd = MENU_GetTopPopupWnd();
1380
1381 if( pTPWnd )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001382 {
1383 HTASK16 hTask = 0;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001384
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001385 TRACE(menu,"patching resident popup: %04x %04x [%04x %04x]\n",
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001386 checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
1387 pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001388
Alexandre Julliard77b99181997-09-14 17:17:23 +00001389 switch( checkQueue )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001390 {
Alexandre Julliard77b99181997-09-14 17:17:23 +00001391 case 0: /* checkWnd is the new popup owner */
1392 if( checkWnd )
1393 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001394 pTPWnd->owner = checkWnd;
1395 if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
Alexandre Julliard77b99181997-09-14 17:17:23 +00001396 hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
1397 }
1398 break;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001399
Alexandre Julliard77b99181997-09-14 17:17:23 +00001400 case 0xFFFF: /* checkWnd is destroyed */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001401 if( pTPWnd->owner == checkWnd )
1402 pTPWnd->owner = NULL;
1403 MENU_ReleaseTopPopupWnd();
Alexandre Julliard77b99181997-09-14 17:17:23 +00001404 return TRUE;
1405
1406 default: /* checkQueue is exiting */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001407 if( pTPWnd->hmemTaskQ == checkQueue )
Alexandre Julliard77b99181997-09-14 17:17:23 +00001408 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001409 hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
Alexandre Julliard77b99181997-09-14 17:17:23 +00001410 hTask = TASK_GetNextTask( hTask );
1411 }
1412 break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001413 }
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001414
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001415 if( hTask )
1416 {
1417 TDB* task = (TDB*)GlobalLock16( hTask );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001418 if( task )
1419 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001420 pTPWnd->hInstance = task->hInstance;
1421 pTPWnd->hmemTaskQ = task->hQueue;
1422 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001423 return TRUE;
1424 }
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001425 else WARN(menu,"failed to patch resident popup.\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001426 }
1427 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001428 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001429 return FALSE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001430}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001431
1432/***********************************************************************
1433 * MENU_ShowPopup
1434 *
1435 * Display a popup menu.
1436 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001437static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
1438 INT x, INT y, INT xanchor, INT yanchor )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001439{
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001440 POPUPMENU *menu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001441 WND *wndOwner = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001442
Juergen Schmied78513941999-04-18 14:40:32 +00001443 TRACE(menu,"owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
1444 hwndOwner, hmenu, id, x, y, xanchor, yanchor);
1445
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001446 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001447 if (menu->FocusedItem != NO_SELECTED_ITEM)
1448 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001449 menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001450 menu->FocusedItem = NO_SELECTED_ITEM;
1451 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001452
Juergen Schmied78513941999-04-18 14:40:32 +00001453 /* store the owner for DrawItem*/
1454 menu->hwndOwner = hwndOwner;
1455
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001456 if( (wndOwner = WIN_FindWndPtr( hwndOwner )) )
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001457 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001458 UINT width, height;
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001459
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001460 MENU_PopupMenuCalcSize( menu, hwndOwner );
1461
1462 /* adjust popup menu pos so that it fits within the desktop */
1463
1464 width = menu->Width + SYSMETRICS_CXBORDER;
1465 height = menu->Height + SYSMETRICS_CYBORDER;
1466
1467 if( x + width > SYSMETRICS_CXSCREEN )
1468 {
1469 if( xanchor )
1470 x -= width - xanchor;
1471 if( x + width > SYSMETRICS_CXSCREEN)
1472 x = SYSMETRICS_CXSCREEN - width;
1473 }
1474 if( x < 0 ) x = 0;
1475
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001476 if( y + height > SYSMETRICS_CYSCREEN )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001477 {
1478 if( yanchor )
1479 y -= height + yanchor;
1480 if( y + height > SYSMETRICS_CYSCREEN )
1481 y = SYSMETRICS_CYSCREEN - height;
1482 }
1483 if( y < 0 ) y = 0;
Alexandre Julliard0e270f41996-08-24 18:26:35 +00001484
Alex Korobka44a1b591999-04-01 12:03:52 +00001485 if( TWEAK_WineLook == WIN31_LOOK )
1486 {
1487 width += POPUP_XSHADE * SYSMETRICS_CXBORDER; /* add space for shading */
1488 height += POPUP_YSHADE * SYSMETRICS_CYBORDER;
1489 }
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001490
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001491 /* NOTE: In Windows, top menu popup is not owned. */
1492 if (!pTopPopupWnd) /* create top level popup menu window */
1493 {
1494 assert( uSubPWndLevel == 0 );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001495
Alexandre Julliarda3960291999-02-26 11:11:13 +00001496 pTopPopupWnd = WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001497 WS_POPUP, x, y, width, height,
1498 hwndOwner, 0, wndOwner->hInstance,
1499 (LPVOID)hmenu ));
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001500 if (!pTopPopupWnd)
1501 {
1502 WIN_ReleaseWndPtr(wndOwner);
1503 return FALSE;
1504 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001505 menu->hWnd = pTopPopupWnd->hwndSelf;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001506 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001507 }
1508 else
1509 if( uSubPWndLevel )
1510 {
1511 /* create a new window for the submenu */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001512
Alexandre Julliarda3960291999-02-26 11:11:13 +00001513 menu->hWnd = CreateWindowA( POPUPMENU_CLASS_ATOM, NULL,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001514 WS_POPUP, x, y, width, height,
Juergen Schmied78513941999-04-18 14:40:32 +00001515 hwndOwner, 0, wndOwner->hInstance,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001516 (LPVOID)hmenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001517 if( !menu->hWnd )
1518 {
1519 WIN_ReleaseWndPtr(wndOwner);
1520 return FALSE;
1521 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001522 }
1523 else /* top level popup menu window already exists */
1524 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001525 WND *pTPWnd = MENU_GetTopPopupWnd();
1526 menu->hWnd = pTPWnd->hwndSelf;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001527
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001528 MENU_PatchResidentPopup( 0, wndOwner );
Juergen Schmied78513941999-04-18 14:40:32 +00001529 SendMessageA( pTPWnd->hwndSelf, MM_SETMENUHANDLE, (WPARAM16)hmenu, 0L);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001530
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001531 /* adjust its size */
1532
Alexandre Julliarda3960291999-02-26 11:11:13 +00001533 SetWindowPos( menu->hWnd, 0, x, y, width, height,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001534 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001535 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001536 }
1537
1538 uSubPWndLevel++; /* menu level counter */
1539
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001540 /* Display the window */
1541
Alexandre Julliarda3960291999-02-26 11:11:13 +00001542 SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001543 SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001544 UpdateWindow( menu->hWnd );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001545 WIN_ReleaseWndPtr(wndOwner);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001546 return TRUE;
1547 }
1548 return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001549}
1550
1551
1552/***********************************************************************
1553 * MENU_SelectItem
1554 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001555static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
1556 BOOL sendMenuSelect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001557{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001558 LPPOPUPMENU lppop;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001559 HDC hdc;
Alexandre Julliardf7207251994-07-23 07:57:48 +00001560
Juergen Schmied78513941999-04-18 14:40:32 +00001561 TRACE(menu, "owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
1562
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001563 lppop = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001564 if (!lppop->nItems) return;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001565
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001566 if ((wIndex != NO_SELECTED_ITEM) &&
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001567 (lppop->items[wIndex].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001568 wIndex = NO_SELECTED_ITEM;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001569
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001570 if (lppop->FocusedItem == wIndex) return;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001571 if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
1572 else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
Alexandre Julliardf7207251994-07-23 07:57:48 +00001573
Juergen Schmied78513941999-04-18 14:40:32 +00001574 SelectObject( hdc, hMenuFont);
1575
Alexandre Julliardf7207251994-07-23 07:57:48 +00001576 /* Clear previous highlighted item */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001577 if (lppop->FocusedItem != NO_SELECTED_ITEM)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001578 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001579 lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
Juergen Schmied78513941999-04-18 14:40:32 +00001580 MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001581 lppop->Height, !(lppop->wFlags & MF_POPUP),
1582 ODA_SELECT );
Alexandre Julliardf7207251994-07-23 07:57:48 +00001583 }
1584
1585 /* Highlight new item (if any) */
1586 lppop->FocusedItem = wIndex;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001587 if (lppop->FocusedItem != NO_SELECTED_ITEM)
Alexandre Julliardf7207251994-07-23 07:57:48 +00001588 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001589 lppop->items[lppop->FocusedItem].fState |= MF_HILITE;
Juergen Schmied78513941999-04-18 14:40:32 +00001590 MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc, &lppop->items[lppop->FocusedItem],
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001591 lppop->Height, !(lppop->wFlags & MF_POPUP),
1592 ODA_SELECT );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001593 if (sendMenuSelect)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001594 {
1595 MENUITEM *ip = &lppop->items[lppop->FocusedItem];
Juergen Schmied78513941999-04-18 14:40:32 +00001596 SendMessageA( hwndOwner, WM_MENUSELECT,
1597 MAKELONG(ip->wID,ip->fType | (ip->fState | MF_MOUSESELECT)), hmenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001598 }
Alexandre Julliardf7207251994-07-23 07:57:48 +00001599 }
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001600 else if (sendMenuSelect) {
Juergen Schmied78513941999-04-18 14:40:32 +00001601 SendMessageA( hwndOwner, WM_MENUSELECT,
1602 MAKELONG( hmenu, lppop->wFlags | MF_MOUSESELECT), hmenu );
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001603 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001604 ReleaseDC( lppop->hWnd, hdc );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001605}
1606
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001607
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001608/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001609 * MENU_MoveSelection
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001610 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001611 * Moves currently selected item according to the offset parameter.
1612 * If there is no selection then it should select the last item if
1613 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001614 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001615static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001616{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001617 INT i;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001618 POPUPMENU *menu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001619
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001620 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001621 if (!menu->items) return;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001622
1623 if ( menu->FocusedItem != NO_SELECTED_ITEM )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001624 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001625 if( menu->nItems == 1 ) return; else
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001626 for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
1627 ; i += offset)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001628 if (!(menu->items[i].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001629 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001630 MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001631 return;
1632 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001633 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001634
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001635 for ( i = (offset > 0) ? 0 : menu->nItems - 1;
1636 i >= 0 && i < menu->nItems ; i += offset)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001637 if (!(menu->items[i].fType & MF_SEPARATOR))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001638 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001639 MENU_SelectItem( hwndOwner, hmenu, i, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001640 return;
1641 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001642}
1643
1644
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001645/**********************************************************************
1646 * MENU_SetItemData
1647 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001648 * Set an item flags, id and text ptr. Called by InsertMenu() and
1649 * ModifyMenu().
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001650 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001651static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001652 LPCSTR str )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001653{
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001654 LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001655
Alexandre Julliard03468f71998-02-15 19:40:49 +00001656 debug_print_menuitem("MENU_SetItemData from: ", item, "");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001657
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001658 if (IS_STRING_ITEM(flags))
1659 {
Alexandre Julliard491502b1997-11-01 19:08:16 +00001660 if (!str || !*str)
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001661 {
1662 flags |= MF_SEPARATOR;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001663 item->text = NULL;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001664 }
1665 else
1666 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001667 LPSTR text;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001668 /* Item beginning with a backspace is a help item */
1669 if (*str == '\b')
1670 {
1671 flags |= MF_HELP;
1672 str++;
1673 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001674 if (!(text = HEAP_strdupA( SystemHeap, 0, str ))) return FALSE;
1675 item->text = text;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001676 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001677 }
Juergen Schmied78513941999-04-18 14:40:32 +00001678 else if (IS_BITMAP_ITEM(flags))
1679 item->text = (LPSTR)(HBITMAP)LOWORD(str);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001680 else item->text = NULL;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001681
Alexandre Julliarda845b881998-06-01 10:44:35 +00001682 if (flags & MF_OWNERDRAW)
1683 item->dwItemData = (DWORD)str;
1684 else
1685 item->dwItemData = 0;
1686
Alexandre Julliard02e90081998-01-04 17:49:09 +00001687 if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00001688 DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001689
1690 if (flags & MF_POPUP)
1691 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001692 POPUPMENU *menu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)id);
1693 if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001694 else
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001695 {
1696 item->wID = 0;
1697 item->hSubMenu = 0;
1698 item->fType = 0;
1699 item->fState = 0;
1700 return FALSE;
1701 }
Alexandre Julliard02e90081998-01-04 17:49:09 +00001702 }
1703
1704 item->wID = id;
1705 if (flags & MF_POPUP)
1706 item->hSubMenu = id;
1707
1708 if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
1709 flags |= MF_POPUP; /* keep popup */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001710
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001711 item->fType = flags & TYPE_MASK;
1712 item->fState = (flags & STATE_MASK) &
1713 ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001714
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001715
1716 /* Don't call SetRectEmpty here! */
1717
1718
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001719 if (prevText) HeapFree( SystemHeap, 0, prevText );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001720
Alexandre Julliard03468f71998-02-15 19:40:49 +00001721 debug_print_menuitem("MENU_SetItemData to : ", item, "");
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001722 return TRUE;
1723}
1724
1725
1726/**********************************************************************
1727 * MENU_InsertItem
1728 *
1729 * Insert a new item into a menu.
1730 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001731static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001732{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001733 MENUITEM *newItems;
1734 POPUPMENU *menu;
1735
1736 if (!(menu = (POPUPMENU *)USER_HEAP_LIN_ADDR(hMenu)))
1737 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001738 WARN(menu, "%04x not a menu handle\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001739 hMenu );
1740 return NULL;
1741 }
1742
1743 /* Find where to insert new item */
1744
1745 if ((flags & MF_BYPOSITION) &&
Alexandre Julliarda3960291999-02-26 11:11:13 +00001746 ((pos == (UINT)-1) || (pos == menu->nItems)))
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001747 {
1748 /* Special case: append to menu */
1749 /* Some programs specify the menu length to do that */
1750 pos = menu->nItems;
1751 }
1752 else
1753 {
1754 if (!MENU_FindItem( &hMenu, &pos, flags ))
1755 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001756 WARN(menu, "item %x not found\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001757 pos );
1758 return NULL;
1759 }
1760 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
1761 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001762 WARN(menu,"%04x not a menu handle\n",
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001763 hMenu);
1764 return NULL;
1765 }
1766 }
1767
1768 /* Create new items array */
1769
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001770 newItems = HeapAlloc( SystemHeap, 0, sizeof(MENUITEM) * (menu->nItems+1) );
1771 if (!newItems)
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001772 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001773 WARN(menu, "allocation failed\n" );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001774 return NULL;
1775 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001776 if (menu->nItems > 0)
1777 {
1778 /* Copy the old array into the new */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001779 if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
1780 if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001781 (menu->nItems-pos)*sizeof(MENUITEM) );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001782 HeapFree( SystemHeap, 0, menu->items );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001783 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001784 menu->items = newItems;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001785 menu->nItems++;
Alexandre Julliard0c126c71996-02-18 18:44:41 +00001786 memset( &newItems[pos], 0, sizeof(*newItems) );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001787 return &newItems[pos];
1788}
1789
1790
1791/**********************************************************************
1792 * MENU_ParseResource
1793 *
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001794 * Parse a standard menu resource and add items to the menu.
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001795 * Return a pointer to the end of the resource.
1796 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001797static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001798{
1799 WORD flags, id = 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001800 LPCSTR str;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001801
1802 do
1803 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001804 flags = GET_WORD(res);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001805 res += sizeof(WORD);
1806 if (!(flags & MF_POPUP))
1807 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001808 id = GET_WORD(res);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001809 res += sizeof(WORD);
1810 }
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001811 if (!IS_STRING_ITEM(flags))
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001812 ERR(menu, "not a string item %04x\n", flags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001813 str = res;
1814 if (!unicode) res += strlen(str) + 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001815 else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001816 if (flags & MF_POPUP)
1817 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001818 HMENU hSubMenu = CreatePopupMenu();
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001819 if (!hSubMenu) return NULL;
1820 if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
1821 return NULL;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001822 if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
1823 else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001824 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001825 else /* Not a popup */
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001826 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001827 if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1828 else AppendMenuW( hMenu, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001829 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00001830 }
1831 } while (!(flags & MF_END));
1832 return res;
1833}
1834
1835
Alexandre Julliard641ee761997-08-04 16:34:36 +00001836/**********************************************************************
1837 * MENUEX_ParseResource
1838 *
1839 * Parse an extended menu resource and add items to the menu.
1840 * Return a pointer to the end of the resource.
1841 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001842static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
Alexandre Julliard641ee761997-08-04 16:34:36 +00001843{
Alexandre Julliard641ee761997-08-04 16:34:36 +00001844 WORD resinfo;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001845 do {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001846 MENUITEMINFOW mii;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001847
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001848 mii.cbSize = sizeof(mii);
1849 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
1850 mii.fType = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001851 res += sizeof(DWORD);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001852 mii.fState = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001853 res += sizeof(DWORD);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001854 mii.wID = GET_DWORD(res);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001855 res += sizeof(DWORD);
1856 resinfo = GET_WORD(res); /* FIXME: for 16-bit apps this is a byte. */
1857 res += sizeof(WORD);
1858 /* Align the text on a word boundary. */
1859 res += (~((int)res - 1)) & 1;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001860 mii.dwTypeData = (LPWSTR) res;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001861 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001862 /* Align the following fields on a dword boundary. */
1863 res += (~((int)res - 1)) & 3;
1864
1865 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1866 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001867 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
1868 0, mii.dwTypeData);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001869 TRACE(menu, "Menu item: [%08x,%08x,%04x,%04x,%s]\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001870 mii.fType, mii.fState, mii.wID, resinfo, newstr);
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001871 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard641ee761997-08-04 16:34:36 +00001872 }
1873
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001874 if (resinfo & 1) { /* Pop-up? */
Marcus Meissnerde43ef41999-02-28 19:56:59 +00001875 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
Alexandre Julliard641ee761997-08-04 16:34:36 +00001876 res += sizeof(DWORD);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001877 mii.hSubMenu = CreatePopupMenu();
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001878 if (!mii.hSubMenu)
1879 return NULL;
1880 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001881 DestroyMenu(mii.hSubMenu);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001882 return NULL;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001883 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001884 mii.fMask |= MIIM_SUBMENU;
1885 mii.fType |= MF_POPUP;
Alexandre Julliard641ee761997-08-04 16:34:36 +00001886 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001887 InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
Alexandre Julliard641ee761997-08-04 16:34:36 +00001888 } while (!(resinfo & MF_END));
1889 return res;
1890}
1891
1892
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001893/***********************************************************************
1894 * MENU_GetSubPopup
1895 *
1896 * Return the handle of the selected sub-popup menu (if any).
1897 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001898static HMENU MENU_GetSubPopup( HMENU hmenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001899{
1900 POPUPMENU *menu;
1901 MENUITEM *item;
1902
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001903 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001904
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001905 if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001906
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001907 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001908 if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
1909 return item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001910 return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001911}
1912
1913
1914/***********************************************************************
1915 * MENU_HideSubPopups
1916 *
1917 * Hide the sub-popup menus of this menu.
1918 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001919static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
1920 BOOL sendMenuSelect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001921{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001922 POPUPMENU *menu = (POPUPMENU*) USER_HEAP_LIN_ADDR( hmenu );;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001923
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001924 if (menu && uSubPWndLevel)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001925 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001926 HMENU hsubmenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001927 POPUPMENU *submenu;
1928 MENUITEM *item;
1929
1930 if (menu->FocusedItem != NO_SELECTED_ITEM)
1931 {
1932 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001933 if (!(item->fType & MF_POPUP) ||
1934 !(item->fState & MF_MOUSESELECT)) return;
1935 item->fState &= ~MF_MOUSESELECT;
1936 hsubmenu = item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001937 } else return;
1938
1939 submenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hsubmenu );
1940 MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
1941 MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect );
1942
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001943 if (submenu->hWnd == MENU_GetTopPopupWnd()->hwndSelf )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001944 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001945 ShowWindow( submenu->hWnd, SW_HIDE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001946 uSubPWndLevel = 0;
1947 }
1948 else
1949 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001950 DestroyWindow( submenu->hWnd );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001951 submenu->hWnd = 0;
1952 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001953 MENU_ReleaseTopPopupWnd();
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001954 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001955}
1956
1957
1958/***********************************************************************
1959 * MENU_ShowSubPopup
1960 *
1961 * Display the sub-menu of the selected item of this menu.
1962 * Return the handle of the submenu, or hmenu if no submenu to display.
1963 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001964static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
1965 BOOL selectFirst )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001966{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001967 RECT rect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001968 POPUPMENU *menu;
1969 MENUITEM *item;
1970 WND *wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001971 HDC hdc;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001972
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001973 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return hmenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00001974
1975 if (!(wndPtr = WIN_FindWndPtr( menu->hWnd )) ||
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001976 (menu->FocusedItem == NO_SELECTED_ITEM))
1977 {
1978 WIN_ReleaseWndPtr(wndPtr);
1979 return hmenu;
1980 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +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) ||
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001984 (item->fState & (MF_GRAYED | MF_DISABLED)))
1985 {
1986 WIN_ReleaseWndPtr(wndPtr);
1987 return hmenu;
1988 }
Alexandre Julliard02e90081998-01-04 17:49:09 +00001989
1990 /* message must be send before using item,
1991 because nearly everything may by changed by the application ! */
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001992
Juergen Schmied78513941999-04-18 14:40:32 +00001993 SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
Alexandre Julliard02e90081998-01-04 17:49:09 +00001994 MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
1995
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001996 item = &menu->items[menu->FocusedItem];
1997 rect = item->rect;
1998
Alexandre Julliard02e90081998-01-04 17:49:09 +00001999 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2000 if (!(item->fState & MF_HILITE))
2001 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002002 if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
2003 else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
Juergen Schmied78513941999-04-18 14:40:32 +00002004
2005 SelectObject( hdc, hMenuFont);
2006
Alexandre Julliard02e90081998-01-04 17:49:09 +00002007 item->fState |= MF_HILITE;
Juergen Schmied78513941999-04-18 14:40:32 +00002008 MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002009 ReleaseDC( menu->hWnd, hdc );
Alexandre Julliard02e90081998-01-04 17:49:09 +00002010 }
2011 if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
2012 item->rect = rect;
2013
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002014 item->fState |= MF_MOUSESELECT;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002015
2016 if (IS_SYSTEM_MENU(menu))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002017 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002018 MENU_InitSysMenuPopup(item->hSubMenu, wndPtr->dwStyle, wndPtr->class->style);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002019
2020 NC_GetSysPopupPos( wndPtr, &rect );
2021 rect.top = rect.bottom;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002022 rect.right = SYSMETRICS_CXSIZE;
2023 rect.bottom = SYSMETRICS_CYSIZE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002024 }
2025 else
2026 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002027 if (menu->wFlags & MF_POPUP)
2028 {
2029 rect.left = wndPtr->rectWindow.left + item->rect.right-arrow_bitmap_width;
2030 rect.top = wndPtr->rectWindow.top + item->rect.top;
2031 rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
2032 rect.bottom = item->rect.top - item->rect.bottom;
2033 }
2034 else
2035 {
2036 rect.left = wndPtr->rectWindow.left + item->rect.left;
2037 rect.top = wndPtr->rectWindow.top + item->rect.bottom;
2038 rect.right = item->rect.right - item->rect.left;
2039 rect.bottom = item->rect.bottom - item->rect.top;
2040 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002041 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002042
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002043 MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002044 rect.left, rect.top, rect.right, rect.bottom );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002045 if (selectFirst)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002046 MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002047 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002048 return item->hSubMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002049}
2050
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002051/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002052 * MENU_PtMenu
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002053 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002054 * Walks menu chain trying to find a menu pt maps to.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002055 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002056static HMENU MENU_PtMenu( HMENU hMenu, POINT16 pt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002057{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002058 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002059 register UINT ht = menu->FocusedItem;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002060
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002061 /* try subpopup first (if any) */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002062 ht = (ht != NO_SELECTED_ITEM &&
2063 (menu->items[ht].fType & MF_POPUP) &&
2064 (menu->items[ht].fState & MF_MOUSESELECT))
Alexandre Julliarda3960291999-02-26 11:11:13 +00002065 ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002066
2067 if( !ht ) /* check the current window (avoiding WM_HITTEST) */
2068 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002069 ht = (UINT)NC_HandleNCHitTest( menu->hWnd, pt );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002070 if( menu->wFlags & MF_POPUP )
Alexandre Julliarda3960291999-02-26 11:11:13 +00002071 ht = (ht != (UINT)HTNOWHERE &&
2072 ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002073 else
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002074 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002075 WND* wndPtr = WIN_FindWndPtr(menu->hWnd);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002076
Alexandre Julliarda3960291999-02-26 11:11:13 +00002077 ht = ( ht == HTSYSMENU ) ? (UINT)(wndPtr->hSysMenu)
2078 : ( ht == HTMENU ) ? (UINT)(wndPtr->wIDmenu) : 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002079 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002080 }
2081 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002082 return (HMENU)ht;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002083}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002084/***********************************************************************
2085 * MENU_ExecFocusedItem
2086 *
2087 * Execute a menu item (for instance when user pressed Enter).
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002088 * Return the wID of the executed item. Otherwise, zero indicating
2089 * that no menu item wase executed;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002090 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002091static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002092{
2093 MENUITEM *item;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002094 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hMenu );
2095 if (!menu || !menu->nItems ||
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002096 (menu->FocusedItem == NO_SELECTED_ITEM)) return 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002097
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002098 item = &menu->items[menu->FocusedItem];
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002099
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002100 TRACE(menu, "%08x %08x %08x\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002101 hMenu, item->wID, item->hSubMenu);
2102
2103 if (!(item->fType & MF_POPUP))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002104 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002105 if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002106 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002107 if( menu->wFlags & MF_SYSMENU )
2108 {
Juergen Schmied78513941999-04-18 14:40:32 +00002109 PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002110 MAKELPARAM((INT16)pmt->pt.x, (INT16)pmt->pt.y) );
2111 }
2112 else
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002113 {
Juergen Schmied78513941999-04-18 14:40:32 +00002114 PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002115 }
2116 return item->wID;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002117 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002118 else return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002119 }
2120 else
2121 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002122 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hMenu, TRUE );
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002123 return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002124 }
2125}
2126
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002127/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002128 * MENU_SwitchTracking
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002129 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002130 * Helper function for menu navigation routines.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002131 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002132static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002133{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002134 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2135 POPUPMENU *topmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002136
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002137 if( pmt->hTopMenu != hPtMenu &&
2138 !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002139 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002140 /* both are top level menus (system and menu-bar) */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002141
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002142 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2143 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE );
2144 pmt->hTopMenu = hPtMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002145 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002146 else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
2147 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002148}
2149
2150
2151/***********************************************************************
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002152 * MENU_ButtonDown
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002153 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002154 * Return TRUE if we can go on with menu tracking.
2155 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002156static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002157{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002158 if (hPtMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002159 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002160 UINT id = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002161 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2162 MENUITEM *item;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002163
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002164 if( IS_SYSTEM_MENU(ptmenu) )
2165 item = ptmenu->items;
2166 else
2167 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002168
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002169 if( item )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002170 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002171 if( ptmenu->FocusedItem == id )
2172 {
2173 /* nothing to do with already selected non-popup */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002174 if( !(item->fType & MF_POPUP) ) return TRUE;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002175
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002176 if( item->fState & MF_MOUSESELECT )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002177 {
2178 if( ptmenu->wFlags & MF_POPUP )
2179 {
2180 /* hide selected subpopup */
2181
2182 MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, TRUE );
2183 pmt->hCurrentMenu = hPtMenu;
2184 return TRUE;
2185 }
2186 return FALSE; /* shouldn't get here */
2187 }
2188 }
2189 else MENU_SwitchTracking( pmt, hPtMenu, id );
2190
2191 /* try to display a subpopup */
2192
2193 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE );
2194 return TRUE;
2195 }
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002196 else WARN(menu, "\tunable to find clicked item!\n");
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002197 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002198 return FALSE;
2199}
2200
2201/***********************************************************************
2202 * MENU_ButtonUp
2203 *
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002204 * Return the the value of MENU_ExecFocusedItem if
2205 * the selected item was not a popup
2206 * 1 if the item was a popup
2207 * 0 otherwise.
2208 * A zero return value indicates that we can't go on with menu tracking.
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002209 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002210static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002211{
2212 if (hPtMenu)
2213 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002214 UINT id = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002215 POPUPMENU *ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2216 MENUITEM *item;
2217
2218 if( IS_SYSTEM_MENU(ptmenu) )
2219 item = ptmenu->items;
2220 else
2221 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2222
Alexandre Julliard491502b1997-11-01 19:08:16 +00002223 if( item && (ptmenu->FocusedItem == id ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002224 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002225 if( !(item->fType & MF_POPUP) )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002226 return MENU_ExecFocusedItem( pmt, hPtMenu );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002227 hPtMenu = item->hSubMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002228 if( hPtMenu == pmt->hCurrentMenu )
2229 {
2230 /* Select first item of sub-popup */
2231
2232 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, NO_SELECTED_ITEM, FALSE );
2233 MENU_MoveSelection( pmt->hOwnerWnd, hPtMenu, ITEM_NEXT );
2234 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002235 return 1;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002236 }
2237 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002238 return 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002239}
2240
2241
2242/***********************************************************************
2243 * MENU_MouseMove
2244 *
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002245 * Return TRUE if we can go on with menu tracking.
2246 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002247static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002248{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002249 UINT id = NO_SELECTED_ITEM;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002250 POPUPMENU *ptmenu = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002251
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002252 if( hPtMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002253 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002254 ptmenu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hPtMenu );
2255 if( IS_SYSTEM_MENU(ptmenu) )
2256 id = 0;
2257 else
2258 MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2259 }
2260
2261 if( id == NO_SELECTED_ITEM )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002262 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002263 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2264 NO_SELECTED_ITEM, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002265 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002266 else if( ptmenu->FocusedItem != id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002267 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002268 MENU_SwitchTracking( pmt, hPtMenu, id );
2269 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002270 }
2271 return TRUE;
2272}
2273
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002274
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002275/***********************************************************************
2276 * MENU_DoNextMenu
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002277 *
2278 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002279 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002280static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002281{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002282 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002283
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002284 if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
2285 (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
2286 {
2287 WND* wndPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002288 HMENU hNewMenu;
2289 HWND hNewWnd;
2290 UINT id = 0;
Juergen Schmied78513941999-04-18 14:40:32 +00002291 LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002292 (IS_SYSTEM_MENU(menu)) ? GetSubMenu16(pmt->hTopMenu,0) : pmt->hTopMenu );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002293
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002294 TRACE(menu,"%04x [%04x] -> %04x [%04x]\n",
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002295 (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002296
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002297 if( l == 0 )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002298 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002299 wndPtr = WIN_FindWndPtr(pmt->hOwnerWnd);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002300
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002301 hNewWnd = pmt->hOwnerWnd;
2302 if( IS_SYSTEM_MENU(menu) )
2303 {
2304 /* switch to the menu bar */
2305
2306 if( wndPtr->dwStyle & WS_CHILD || !wndPtr->wIDmenu )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002307 {
2308 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002309 return FALSE;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002310 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002311
2312 hNewMenu = wndPtr->wIDmenu;
2313 if( vk == VK_LEFT )
2314 {
2315 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hNewMenu );
2316 id = menu->nItems - 1;
2317 }
2318 }
2319 else if( wndPtr->dwStyle & WS_SYSMENU )
2320 {
2321 /* switch to the system menu */
2322 hNewMenu = wndPtr->hSysMenu;
2323 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002324 else
2325 {
2326 WIN_ReleaseWndPtr(wndPtr);
2327 return FALSE;
2328 }
2329 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002330 }
2331 else /* application returned a new menu to switch to */
2332 {
2333 hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
2334
Alexandre Julliarda3960291999-02-26 11:11:13 +00002335 if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002336 {
2337 wndPtr = WIN_FindWndPtr(hNewWnd);
2338
2339 if( wndPtr->dwStyle & WS_SYSMENU &&
2340 GetSubMenu16(wndPtr->hSysMenu, 0) == hNewMenu )
2341 {
2342 /* get the real system menu */
2343 hNewMenu = wndPtr->hSysMenu;
2344 }
2345 else if( wndPtr->dwStyle & WS_CHILD || wndPtr->wIDmenu != hNewMenu )
2346 {
2347 /* FIXME: Not sure what to do here, perhaps,
2348 * try to track hNewMenu as a popup? */
2349
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002350 TRACE(menu," -- got confused.\n");
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002351 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002352 return FALSE;
2353 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002354 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002355 }
2356 else return FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002357 }
2358
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002359 if( hNewMenu != pmt->hTopMenu )
2360 {
2361 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE );
2362 if( pmt->hCurrentMenu != pmt->hTopMenu )
2363 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2364 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002365
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002366 if( hNewWnd != pmt->hOwnerWnd )
2367 {
2368 ReleaseCapture();
2369 pmt->hOwnerWnd = hNewWnd;
2370 EVENT_Capture( pmt->hOwnerWnd, HTMENU );
2371 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002372
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002373 pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
2374 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002375
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002376 return TRUE;
2377 }
2378 return FALSE;
2379}
2380
2381/***********************************************************************
2382 * MENU_SuspendPopup
2383 *
2384 * The idea is not to show the popup if the next input message is
2385 * going to hide it anyway.
2386 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002387static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT16 uMsg )
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002388{
Juergen Schmied78513941999-04-18 14:40:32 +00002389 MSG msg;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002390
2391 msg.hwnd = pmt->hOwnerWnd;
2392
Juergen Schmied78513941999-04-18 14:40:32 +00002393 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002394 pmt->trackFlags |= TF_SKIPREMOVE;
2395
2396 switch( uMsg )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002397 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002398 case WM_KEYDOWN:
Juergen Schmied78513941999-04-18 14:40:32 +00002399 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002400 if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
2401 {
Juergen Schmied78513941999-04-18 14:40:32 +00002402 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2403 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002404 if( msg.message == WM_KEYDOWN &&
2405 (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
2406 {
2407 pmt->trackFlags |= TF_SUSPENDPOPUP;
2408 return TRUE;
2409 }
2410 }
2411 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002412 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002413
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002414 /* failures go through this */
2415 pmt->trackFlags &= ~TF_SUSPENDPOPUP;
2416 return FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002417}
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002418
2419/***********************************************************************
2420 * MENU_KeyLeft
2421 *
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002422 * Handle a VK_LEFT key event in a menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002423 */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002424static void MENU_KeyLeft( MTRACKER* pmt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002425{
2426 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002427 HMENU hmenutmp, hmenuprev;
2428 UINT prevcol;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002429
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002430 hmenuprev = hmenutmp = pmt->hTopMenu;
2431 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenutmp );
2432
Alexandre Julliard641ee761997-08-04 16:34:36 +00002433 /* Try to move 1 column left (if possible) */
2434 if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
2435 NO_SELECTED_ITEM ) {
2436
2437 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2438 prevcol, TRUE );
2439 return;
2440 }
2441
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002442 /* close topmost popup */
2443 while (hmenutmp != pmt->hCurrentMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002444 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002445 hmenuprev = hmenutmp;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002446 hmenutmp = MENU_GetSubPopup( hmenuprev );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002447 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002448
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002449 MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
2450 pmt->hCurrentMenu = hmenuprev;
2451
2452 if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002453 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002454 /* move menu bar selection if no more popups are left */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002455
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002456 if( !MENU_DoNextMenu( pmt, VK_LEFT) )
2457 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002458
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002459 if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002460 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002461 /* A sublevel menu was displayed - display the next one
2462 * unless there is another displacement coming up */
2463
2464 if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
2465 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd,
2466 pmt->hTopMenu, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002467 }
2468 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002469}
2470
2471
2472/***********************************************************************
2473 * MENU_KeyRight
2474 *
2475 * Handle a VK_RIGHT key event in a menu.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002476 */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002477static void MENU_KeyRight( MTRACKER* pmt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002478{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002479 HMENU hmenutmp;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002480 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( pmt->hTopMenu );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002481 UINT nextcol;
Alexandre Julliard641ee761997-08-04 16:34:36 +00002482
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002483 TRACE(menu, "MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
Alexandre Julliard641ee761997-08-04 16:34:36 +00002484 pmt->hCurrentMenu,
2485 ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
2486 items[0].text,
2487 pmt->hTopMenu, menu->items[0].text );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002488
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002489 if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002490 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002491 /* If already displaying a popup, try to display sub-popup */
2492
2493 hmenutmp = pmt->hCurrentMenu;
2494 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hmenutmp, TRUE );
2495
2496 /* if subpopup was displayed then we are done */
2497 if (hmenutmp != pmt->hCurrentMenu) return;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002498 }
2499
Alexandre Julliard641ee761997-08-04 16:34:36 +00002500 /* Check to see if there's another column */
2501 if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
2502 NO_SELECTED_ITEM ) {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002503 TRACE(menu, "Going to %d.\n", nextcol );
Alexandre Julliard641ee761997-08-04 16:34:36 +00002504 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2505 nextcol, TRUE );
2506 return;
2507 }
2508
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002509 if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002510 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002511 if( pmt->hCurrentMenu != pmt->hTopMenu )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002512 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002513 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2514 hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
2515 } else hmenutmp = 0;
2516
2517 /* try to move to the next item */
2518 if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
2519 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
2520
2521 if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2522 if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
2523 pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd,
2524 pmt->hTopMenu, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002525 }
2526}
2527
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002528/***********************************************************************
2529 * MENU_TrackMenu
2530 *
2531 * Menu tracking code.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002532 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002533static INT MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y,
2534 HWND hwnd, const RECT *lprect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002535{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002536 MSG msg;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002537 POPUPMENU *menu;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002538 BOOL fRemove;
2539 INT executedMenuId = 0;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +00002540 MTRACKER mt;
2541
2542 mt.trackFlags = 0;
2543 mt.hCurrentMenu = hmenu;
2544 mt.hTopMenu = hmenu;
2545 mt.hOwnerWnd = hwnd;
2546 mt.pt.x = x;
2547 mt.pt.y = y;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002548
Juergen Schmied78513941999-04-18 14:40:32 +00002549 TRACE(menu,"hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00002550 hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
2551 (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
Juergen Schmied78513941999-04-18 14:40:32 +00002552
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002553 fEndMenu = FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002554 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu ))) return FALSE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002555
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002556 if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002557
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002558 EVENT_Capture( mt.hOwnerWnd, HTMENU );
2559
2560 while (!fEndMenu)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002561 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002562 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2563 msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
2564
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002565 /* we have to keep the message in the queue until it's
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002566 * clear that menu loop is not over yet. */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002567
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002568 if (!MSG_InternalGetMessage( &msg, msg.hwnd, mt.hOwnerWnd,
2569 MSGF_MENU, PM_NOREMOVE, TRUE )) break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002570
Alexandre Julliarda3960291999-02-26 11:11:13 +00002571 TranslateMessage( &msg );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002572 mt.pt = msg.pt;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +00002573
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002574 fRemove = FALSE;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002575 if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002576 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002577 /* Find a menu for this mouse event */
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002578 POINT16 pt16;
2579 CONV_POINT32TO16( &msg.pt, &pt16 );
2580 hmenu = MENU_PtMenu( mt.hTopMenu, pt16 );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002581
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002582 switch(msg.message)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002583 {
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002584 /* no WM_NC... messages in captured state */
2585
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002586 case WM_RBUTTONDBLCLK:
2587 case WM_RBUTTONDOWN:
2588 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2589 /* fall through */
2590 case WM_LBUTTONDBLCLK:
2591 case WM_LBUTTONDOWN:
2592 fEndMenu |= !MENU_ButtonDown( &mt, hmenu );
2593 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002594
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002595 case WM_RBUTTONUP:
2596 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2597 /* fall through */
2598 case WM_LBUTTONUP:
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002599 /* Check if a menu was selected by the mouse */
2600 if (hmenu)
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002601 {
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002602 executedMenuId = MENU_ButtonUp( &mt, hmenu );
2603
2604 /* the executedMenuId higher than one means that it contains
2605 the id of the selected item so we have to put the fEndMenu to TRUE.
2606 Otherwise, it contains a continue
2607 flag returned by MENU_ButtonUp indicating if we can continue with
2608 menu tracking or not*/
2609 fEndMenu = ((executedMenuId > 1) ? TRUE : FALSE);
2610
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002611 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002612 /* No menu was selected by the mouse */
2613 /* if the function was called by TrackPopupMenu, continue
2614 with the menu tracking. If not, stop it */
2615 else
2616 fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
2617
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002618 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002619
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002620 case WM_MOUSEMOVE:
Alexandre Julliard8da12c41999-01-17 16:55:11 +00002621 /* In win95 winelook, the selected menu item must be changed every time the
2622 mouse moves. In Win31 winelook, the mouse button has to be held down */
2623
2624 if ( (TWEAK_WineLook > WIN31_LOOK) ||
2625 ( (msg.wParam & MK_LBUTTON) ||
2626 ((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON))) )
2627
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002628 fEndMenu |= !MENU_MouseMove( &mt, hmenu );
Alexandre Julliard8da12c41999-01-17 16:55:11 +00002629
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002630 } /* switch(msg.message) - mouse */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002631 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002632 else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002633 {
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002634 fRemove = TRUE; /* Keyboard messages are always removed */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002635 switch(msg.message)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002636 {
2637 case WM_KEYDOWN:
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002638 switch(msg.wParam)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002639 {
2640 case VK_HOME:
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002641 case VK_END:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002642 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
2643 NO_SELECTED_ITEM, FALSE );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002644 /* fall through */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002645 case VK_UP:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002646 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002647 (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002648 break;
2649
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002650 case VK_DOWN: /* If on menu bar, pull-down the menu */
2651
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002652 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hCurrentMenu );
2653 if (!(menu->wFlags & MF_POPUP))
2654 mt.hCurrentMenu = MENU_ShowSubPopup( mt.hOwnerWnd, mt.hTopMenu, TRUE );
2655 else /* otherwise try to move selection */
2656 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002657 break;
2658
2659 case VK_LEFT:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002660 MENU_KeyLeft( &mt );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002661 break;
2662
2663 case VK_RIGHT:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002664 MENU_KeyRight( &mt );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002665 break;
2666
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002667 case VK_ESCAPE:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002668 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002669 break;
2670
2671 default:
2672 break;
2673 }
2674 break; /* WM_KEYDOWN */
2675
2676 case WM_SYSKEYDOWN:
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002677 switch(msg.wParam)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002678 {
2679 case VK_MENU:
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002680 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002681 break;
2682
2683 }
2684 break; /* WM_SYSKEYDOWN */
2685
2686 case WM_CHAR:
2687 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002688 UINT pos;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002689
Norman Stevensa83d0651998-10-12 07:25:35 +00002690 if (msg.wParam == '\r' || msg.wParam == ' ')
2691 {
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002692 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu);
2693 fEndMenu = ((executedMenuId != 0) ? TRUE:FALSE);
2694
Norman Stevensa83d0651998-10-12 07:25:35 +00002695 break;
2696 }
2697
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002698 /* Hack to avoid control chars. */
2699 /* We will find a better way real soon... */
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002700 if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002701
2702 pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002703 LOWORD(msg.wParam), FALSE );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002704 if (pos == (UINT)-2) fEndMenu = TRUE;
2705 else if (pos == (UINT)-1) MessageBeep(0);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002706 else
2707 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002708 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos, TRUE );
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002709 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu);
2710 fEndMenu = ((executedMenuId != 0) ? TRUE:FALSE);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002711 }
2712 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002713 break;
2714 } /* switch(msg.message) - kbd */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002715 }
2716 else
2717 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002718 DispatchMessageA( &msg );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002719 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002720
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002721 if (!fEndMenu) fRemove = TRUE;
2722
2723 /* finally remove message from the queue */
2724
2725 if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00002726 PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002727 else mt.trackFlags &= ~TF_SKIPREMOVE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002728 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +00002729
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002730 ReleaseCapture();
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00002731
Alexandre Julliarda3960291999-02-26 11:11:13 +00002732 if( IsWindow( mt.hOwnerWnd ) )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002733 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002734 MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
2735
2736 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( mt.hTopMenu );
2737 if (menu && menu->wFlags & MF_POPUP)
2738 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002739 ShowWindow( menu->hWnd, SW_HIDE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002740 uSubPWndLevel = 0;
2741 }
2742 MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE );
Juergen Schmied78513941999-04-18 14:40:32 +00002743 SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0), 0xffff );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002744 }
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002745
2746 /* returning the id of the selected menu.
2747 The return value is only used by TrackPopupMenu */
2748 return executedMenuId;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002749}
2750
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002751/***********************************************************************
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002752 * MENU_InitTracking
2753 */
Juergen Schmied78513941999-04-18 14:40:32 +00002754static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002755{
Juergen Schmied78513941999-04-18 14:40:32 +00002756
2757 TRACE(menu, "hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
2758
Alexandre Julliarda3960291999-02-26 11:11:13 +00002759 HideCaret(0);
Juergen Schmied78513941999-04-18 14:40:32 +00002760 SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
2761 SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
2762 SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
2763 return TRUE;
2764}
2765/***********************************************************************
2766 * MENU_ExitTracking
2767 */
2768static BOOL MENU_ExitTracking(HWND hWnd)
2769{
2770 TRACE(menu, "hwnd=0x%04x\n", hWnd);
2771
2772 SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
2773 ShowCaret(0);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002774 return TRUE;
2775}
2776
2777/***********************************************************************
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002778 * MENU_TrackMouseMenuBar
2779 *
2780 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2781 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002782void MENU_TrackMouseMenuBar( WND* wndPtr, INT ht, POINT pt )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002783{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002784 HWND hWnd = wndPtr->hwndSelf;
2785 HMENU hMenu = (ht == HTSYSMENU) ? wndPtr->hSysMenu : wndPtr->wIDmenu;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002786
Juergen Schmied78513941999-04-18 14:40:32 +00002787 TRACE(menu,"pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
2788
Alexandre Julliarda3960291999-02-26 11:11:13 +00002789 if (IsMenu(hMenu))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002790 {
Juergen Schmied78513941999-04-18 14:40:32 +00002791 MENU_InitTracking( hWnd, hMenu, FALSE );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002792 MENU_TrackMenu( hMenu, TPM_ENTERIDLEEX | TPM_BUTTONDOWN |
2793 TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, hWnd, NULL );
Juergen Schmied78513941999-04-18 14:40:32 +00002794 MENU_ExitTracking(hWnd);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002795 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002796}
2797
2798
2799/***********************************************************************
2800 * MENU_TrackKbdMenuBar
2801 *
2802 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2803 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002804void MENU_TrackKbdMenuBar( WND* wndPtr, UINT wParam, INT vkey)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002805{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002806 UINT uItem = NO_SELECTED_ITEM;
2807 HMENU hTrackMenu;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002808
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002809 /* find window that has a menu */
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002810
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002811 while( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwStyle & WS_SYSMENU) )
2812 if( !(wndPtr = wndPtr->parent) ) return;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002813
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002814 /* check if we have to track a system menu */
2815
2816 if( (wndPtr->dwStyle & (WS_CHILD | WS_MINIMIZE)) ||
2817 !wndPtr->wIDmenu || vkey == VK_SPACE )
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002818 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002819 if( !(wndPtr->dwStyle & WS_SYSMENU) ) return;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002820 hTrackMenu = wndPtr->hSysMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002821 uItem = 0;
2822 wParam |= HTSYSMENU; /* prevent item lookup */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002823 }
2824 else
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002825 hTrackMenu = wndPtr->wIDmenu;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002826
Alexandre Julliarda3960291999-02-26 11:11:13 +00002827 if (IsMenu( hTrackMenu ))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002828 {
Juergen Schmied78513941999-04-18 14:40:32 +00002829 MENU_InitTracking( wndPtr->hwndSelf, hTrackMenu, FALSE );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002830
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002831 if( vkey && vkey != VK_SPACE )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002832 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002833 uItem = MENU_FindItemByKey( wndPtr->hwndSelf, hTrackMenu,
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002834 vkey, (wParam & HTSYSMENU) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002835 if( uItem >= (UINT)(-2) )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002836 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002837 if( uItem == (UINT)(-1) ) MessageBeep(0);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002838 hTrackMenu = 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002839 }
2840 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002841
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002842 if( hTrackMenu )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002843 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002844 MENU_SelectItem( wndPtr->hwndSelf, hTrackMenu, uItem, TRUE );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002845
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002846 if( uItem == NO_SELECTED_ITEM )
2847 MENU_MoveSelection( wndPtr->hwndSelf, hTrackMenu, ITEM_NEXT );
2848 else if( vkey )
Juergen Schmied78513941999-04-18 14:40:32 +00002849 PostMessageA( wndPtr->hwndSelf, WM_KEYDOWN, VK_DOWN, 0L );
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002850
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002851 MENU_TrackMenu( hTrackMenu, TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON,
2852 0, 0, wndPtr->hwndSelf, NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002853 }
Juergen Schmied78513941999-04-18 14:40:32 +00002854
2855 MENU_ExitTracking (wndPtr->hwndSelf);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002856 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002857}
2858
2859
2860/**********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002861 * TrackPopupMenu16 (USER.416)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002862 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002863BOOL16 WINAPI TrackPopupMenu16( HMENU16 hMenu, UINT16 wFlags, INT16 x, INT16 y,
2864 INT16 nReserved, HWND16 hWnd, const RECT16 *lpRect )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002865{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002866 RECT r;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002867 if (lpRect)
2868 CONV_RECT16TO32( lpRect, &r );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002869 return TrackPopupMenu( hMenu, wFlags, x, y, nReserved, hWnd,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002870 lpRect ? &r : NULL );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002871}
2872
2873
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002874/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00002875 * TrackPopupMenu (USER32.549)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002876 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002877BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
2878 INT nReserved, HWND hWnd, const RECT *lpRect )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002879{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002880 BOOL ret = FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002881
Juergen Schmied78513941999-04-18 14:40:32 +00002882 MENU_InitTracking(hWnd, hMenu, TRUE);
2883 SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002884 if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
Francois Boisvert85dd9fc1999-02-17 12:50:11 +00002885 ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd, lpRect );
Juergen Schmied78513941999-04-18 14:40:32 +00002886 MENU_ExitTracking(hWnd);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002887 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002888}
2889
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002890/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00002891 * TrackPopupMenuEx (USER32.550)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002892 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002893BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
2894 HWND hWnd, LPTPMPARAMS lpTpm )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002895{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002896 FIXME(menu, "not fully implemented\n" );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002897 return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002898 lpTpm ? &lpTpm->rcExclude : NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00002899}
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002900
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002901/***********************************************************************
2902 * PopupMenuWndProc
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002903 *
2904 * NOTE: Windows has totally different (and undocumented) popup wndproc.
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002905 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002906LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002907 LPARAM lParam )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002908{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002909 WND* wndPtr = WIN_FindWndPtr(hwnd);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002910 LRESULT retvalue;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002911
Juergen Schmied78513941999-04-18 14:40:32 +00002912 TRACE(menu,"hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
2913 hwnd, message, wParam, lParam);
2914
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002915 switch(message)
2916 {
2917 case WM_CREATE:
2918 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002919 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
2920 SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002921 retvalue = 0;
2922 goto END;
Alexandre Julliardf7207251994-07-23 07:57:48 +00002923 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +00002924
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002925 case WM_MOUSEACTIVATE: /* We don't want to be activated */
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002926 retvalue = MA_NOACTIVATE;
2927 goto END;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00002928
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002929 case WM_PAINT:
2930 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002931 PAINTSTRUCT ps;
2932 BeginPaint( hwnd, &ps );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002933 MENU_DrawPopupMenu( hwnd, ps.hdc,
Alexandre Julliarda3960291999-02-26 11:11:13 +00002934 (HMENU)GetWindowLongA( hwnd, 0 ) );
2935 EndPaint( hwnd, &ps );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002936 retvalue = 0;
2937 goto END;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002938 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002939 case WM_ERASEBKGND:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002940 retvalue = 1;
2941 goto END;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00002942
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00002943 case WM_DESTROY:
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00002944
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002945 /* zero out global pointer in case resident popup window
2946 * was somehow destroyed. */
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00002947
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002948 if(MENU_GetTopPopupWnd() )
Alexandre Julliard54c27111998-03-29 19:44:57 +00002949 {
2950 if( hwnd == pTopPopupWnd->hwndSelf )
2951 {
2952 ERR(menu, "resident popup destroyed!\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002953
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002954 MENU_DestroyTopPopupWnd();
Alexandre Julliard54c27111998-03-29 19:44:57 +00002955 uSubPWndLevel = 0;
2956 }
2957 else
2958 uSubPWndLevel--;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002959 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002960 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002961 break;
2962
2963 case WM_SHOWWINDOW:
2964
2965 if( wParam )
2966 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002967 if( !(*(HMENU*)wndPtr->wExtra) )
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00002968 ERR(menu,"no menu to display\n");
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002969 }
2970 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00002971 *(HMENU*)wndPtr->wExtra = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002972 break;
2973
2974 case MM_SETMENUHANDLE:
2975
Alexandre Julliarda3960291999-02-26 11:11:13 +00002976 *(HMENU*)wndPtr->wExtra = (HMENU)wParam;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00002977 break;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002978
2979 case MM_GETMENUHANDLE:
2980
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002981 retvalue = *(HMENU*)wndPtr->wExtra;
2982 goto END;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00002983
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002984 default:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002985 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
2986 goto END;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00002987 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00002988 retvalue = 0;
2989END:
2990 WIN_ReleaseWndPtr(wndPtr);
2991 return retvalue;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002992}
2993
2994
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00002995/***********************************************************************
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00002996 * MENU_GetMenuBarHeight
2997 *
2998 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
2999 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003000UINT MENU_GetMenuBarHeight( HWND hwnd, UINT menubarWidth,
3001 INT orgX, INT orgY )
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003002{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003003 HDC hdc;
3004 RECT rectBar;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003005 WND *wndPtr;
3006 LPPOPUPMENU lppop;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003007 UINT retvalue;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003008
Juergen Schmied78513941999-04-18 14:40:32 +00003009 TRACE(menu, "HWND 0x%x, width %d, at (%d, %d).\n",
3010 hwnd, menubarWidth, orgX, orgY );
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003011
Juergen Schmied78513941999-04-18 14:40:32 +00003012 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
3013 return 0;
3014
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003015 if (!(lppop = (LPPOPUPMENU)USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu)))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003016 {
Juergen Schmied78513941999-04-18 14:40:32 +00003017 WIN_ReleaseWndPtr(wndPtr);
3018 return 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003019 }
Juergen Schmied78513941999-04-18 14:40:32 +00003020
Alexandre Julliarda3960291999-02-26 11:11:13 +00003021 hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
Juergen Schmied78513941999-04-18 14:40:32 +00003022 SelectObject( hdc, hMenuFont);
Alexandre Julliarda3960291999-02-26 11:11:13 +00003023 SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+SYSMETRICS_CYMENU);
Juergen Schmied78513941999-04-18 14:40:32 +00003024 MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003025 ReleaseDC( hwnd, hdc );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003026 retvalue = lppop->Height;
3027 WIN_ReleaseWndPtr(wndPtr);
3028 return retvalue;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +00003029}
3030
3031
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003032/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003033 * ChangeMenu16 (USER.153)
Alexandre Julliard401710d1993-09-04 10:09:32 +00003034 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003035BOOL16 WINAPI ChangeMenu16( HMENU16 hMenu, UINT16 pos, SEGPTR data,
3036 UINT16 id, UINT16 flags )
Alexandre Julliard401710d1993-09-04 10:09:32 +00003037{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003038 TRACE(menu,"menu=%04x pos=%d data=%08lx id=%04x flags=%04x\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +00003039 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003040 if (flags & MF_APPEND) return AppendMenu16( hMenu, flags & ~MF_APPEND,
3041 id, data );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003042
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003043 /* FIXME: Word passes the item id in 'pos' and 0 or 0xffff as id */
3044 /* for MF_DELETE. We should check the parameters for all others */
3045 /* MF_* actions also (anybody got a doc on ChangeMenu?). */
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003046
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003047 if (flags & MF_DELETE) return DeleteMenu16(hMenu, pos, flags & ~MF_DELETE);
3048 if (flags & MF_CHANGE) return ModifyMenu16(hMenu, pos, flags & ~MF_CHANGE,
3049 id, data );
3050 if (flags & MF_REMOVE) return RemoveMenu16(hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003051 flags & MF_BYPOSITION ? pos : id,
3052 flags & ~MF_REMOVE );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003053 /* Default: MF_INSERT */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003054 return InsertMenu16( hMenu, pos, flags, id, data );
3055}
3056
3057
3058/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003059 * ChangeMenu32A (USER32.23)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003060 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003061BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
3062 UINT id, UINT flags )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003063{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003064 TRACE(menu,"menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003065 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003066 if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003067 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003068 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3069 if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003070 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003071 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003072 flags & MF_BYPOSITION ? pos : id,
3073 flags & ~MF_REMOVE );
3074 /* Default: MF_INSERT */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003075 return InsertMenuA( hMenu, pos, flags, id, data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003076}
3077
3078
3079/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003080 * ChangeMenu32W (USER32.24)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003081 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003082BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
3083 UINT id, UINT flags )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003084{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003085 TRACE(menu,"menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003086 hMenu, pos, (DWORD)data, id, flags );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003087 if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003088 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003089 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3090 if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003091 id, data );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003092 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003093 flags & MF_BYPOSITION ? pos : id,
3094 flags & ~MF_REMOVE );
3095 /* Default: MF_INSERT */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003096 return InsertMenuW( hMenu, pos, flags, id, data );
Alexandre Julliard401710d1993-09-04 10:09:32 +00003097}
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003098
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003099
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003100/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003101 * CheckMenuItem16 (USER.154)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003102 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003103BOOL16 WINAPI CheckMenuItem16( HMENU16 hMenu, UINT16 id, UINT16 flags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003104{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003105 return (BOOL16)CheckMenuItem( hMenu, id, flags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003106}
3107
3108
3109/*******************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003110 * CheckMenuItem (USER32.46)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003111 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003112DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003113{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003114 MENUITEM *item;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003115 DWORD ret;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003116
Juergen Schmied78513941999-04-18 14:40:32 +00003117 TRACE(menu,"menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003118 if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003119 ret = item->fState & MF_CHECKED;
3120 if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
3121 else item->fState &= ~MF_CHECKED;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003122 return ret;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003123}
3124
3125
3126/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003127 * EnableMenuItem16 (USER.155)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003128 */
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003129UINT16 WINAPI EnableMenuItem16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003130{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003131 return EnableMenuItem( hMenu, wItemID, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003132}
3133
3134
3135/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003136 * EnableMenuItem32 (USER32.170)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003137 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003138UINT WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003139{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003140 UINT oldflags;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003141 MENUITEM *item;
Alexandre Julliardf7207251994-07-23 07:57:48 +00003142
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003143 TRACE(menu,"(%04x, %04X, %04X) !\n",
3144 hMenu, wItemID, wFlags);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003145
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003146 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003147 return (UINT)-1;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00003148
3149 oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
3150 item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
3151 return oldflags;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003152}
3153
3154
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003155/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003156 * GetMenuString16 (USER.161)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003157 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003158INT16 WINAPI GetMenuString16( HMENU16 hMenu, UINT16 wItemID,
3159 LPSTR str, INT16 nMaxSiz, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003160{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003161 return GetMenuStringA( hMenu, wItemID, str, nMaxSiz, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003162}
3163
3164
3165/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003166 * GetMenuString32A (USER32.268)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003167 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003168INT WINAPI GetMenuStringA( HMENU hMenu, UINT wItemID,
3169 LPSTR str, INT nMaxSiz, UINT wFlags )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003170{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003171 MENUITEM *item;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003172
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003173 TRACE(menu, "menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00003174 hMenu, wItemID, str, nMaxSiz, wFlags );
3175 if (!str || !nMaxSiz) return 0;
3176 str[0] = '\0';
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003177 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003178 if (!IS_STRING_ITEM(item->fType)) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003179 lstrcpynA( str, item->text, nMaxSiz );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003180 TRACE(menu, "returning '%s'\n", str );
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003181 return strlen(str);
Alexandre Julliard1f579291994-05-25 16:25:21 +00003182}
3183
3184
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003185/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003186 * GetMenuString32W (USER32.269)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003187 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003188INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
3189 LPWSTR str, INT nMaxSiz, UINT wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003190{
3191 MENUITEM *item;
3192
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003193 TRACE(menu, "menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003194 hMenu, wItemID, str, nMaxSiz, wFlags );
3195 if (!str || !nMaxSiz) return 0;
3196 str[0] = '\0';
3197 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003198 if (!IS_STRING_ITEM(item->fType)) return 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003199 lstrcpynAtoW( str, item->text, nMaxSiz );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003200 return lstrlenW(str);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003201}
3202
3203
3204/**********************************************************************
3205 * HiliteMenuItem16 (USER.162)
3206 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003207BOOL16 WINAPI HiliteMenuItem16( HWND16 hWnd, HMENU16 hMenu, UINT16 wItemID,
3208 UINT16 wHilite )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003209{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003210 return HiliteMenuItem( hWnd, hMenu, wItemID, wHilite );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003211}
3212
3213
3214/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003215 * HiliteMenuItem32 (USER32.318)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003216 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003217BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
3218 UINT wHilite )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003219{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003220 LPPOPUPMENU menu;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003221 TRACE(menu,"(%04x, %04x, %04x, %04x);\n",
Alexandre Julliard59730ae1996-03-24 16:20:51 +00003222 hWnd, hMenu, wItemID, wHilite);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003223 if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003224 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003225 if (menu->FocusedItem == wItemID) return TRUE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00003226 MENU_HideSubPopups( hWnd, hMenu, FALSE );
3227 MENU_SelectItem( hWnd, hMenu, wItemID, TRUE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003228 return TRUE;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003229}
3230
3231
3232/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003233 * GetMenuState16 (USER.250)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003234 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003235UINT16 WINAPI GetMenuState16( HMENU16 hMenu, UINT16 wItemID, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003236{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003237 return GetMenuState( hMenu, wItemID, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003238}
3239
3240
3241/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003242 * GetMenuState (USER32.267)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003243 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003244UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003245{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003246 MENUITEM *item;
Juergen Schmied78513941999-04-18 14:40:32 +00003247 TRACE(menu,"(menu=%04x, id=%04x, flags=%04x);\n",
Alexandre Julliardaca05781994-10-17 18:12:41 +00003248 hMenu, wItemID, wFlags);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003249 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
Alexandre Julliard03468f71998-02-15 19:40:49 +00003250 debug_print_menuitem (" item: ", item, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003251 if (item->fType & MF_POPUP)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003252 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003253 POPUPMENU *menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( item->hSubMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003254 if (!menu) return -1;
Alexandre Julliard829fe321998-07-26 14:27:39 +00003255 else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003256 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003257 else
Alexandre Julliard491502b1997-11-01 19:08:16 +00003258 {
Alexandre Julliard829fe321998-07-26 14:27:39 +00003259 /* We used to (from way back then) mask the result to 0xff. */
3260 /* I don't know why and it seems wrong as the documented */
3261 /* return flag MF_SEPARATOR is outside that mask. */
3262 return (item->fType | item->fState);
Alexandre Julliard491502b1997-11-01 19:08:16 +00003263 }
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00003264}
3265
3266
3267/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003268 * GetMenuItemCount16 (USER.263)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003269 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003270INT16 WINAPI GetMenuItemCount16( HMENU16 hMenu )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003271{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003272 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003273 if (!IS_A_MENU(menu)) return -1;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003274 TRACE(menu,"(%04x) returning %d\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003275 hMenu, menu->nItems );
3276 return menu->nItems;
Alexandre Julliard1f579291994-05-25 16:25:21 +00003277}
3278
3279
3280/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003281 * GetMenuItemCount32 (USER32.262)
Alexandre Julliard1f579291994-05-25 16:25:21 +00003282 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003283INT WINAPI GetMenuItemCount( HMENU hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003284{
3285 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003286 if (!IS_A_MENU(menu)) return -1;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003287 TRACE(menu,"(%04x) returning %d\n",
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003288 hMenu, menu->nItems );
3289 return menu->nItems;
3290}
3291
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003292/**********************************************************************
3293 * GetMenuItemID16 (USER.264)
3294 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003295UINT16 WINAPI GetMenuItemID16( HMENU16 hMenu, INT16 nPos )
Alexandre Julliard1f579291994-05-25 16:25:21 +00003296{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003297 return (UINT16) GetMenuItemID (hMenu, nPos);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003298}
3299
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003300/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003301 * GetMenuItemID32 (USER32.263)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003302 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003303UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003304{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003305 MENUITEM * lpmi;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003306
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003307 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3308 if (lpmi->fType & MF_POPUP) return -1;
3309 return lpmi->wID;
3310
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003311}
3312
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003313/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003314 * InsertMenu16 (USER.410)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003315 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003316BOOL16 WINAPI InsertMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3317 UINT16 id, SEGPTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003318{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003319 UINT pos32 = (UINT)pos;
3320 if ((pos == (UINT16)-1) && (flags & MF_BYPOSITION)) pos32 = (UINT)-1;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003321 if (IS_STRING_ITEM(flags) && data)
Alexandre Julliarda3960291999-02-26 11:11:13 +00003322 return InsertMenuA( hMenu, pos32, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003323 (LPSTR)PTR_SEG_TO_LIN(data) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003324 return InsertMenuA( hMenu, pos32, flags, id, (LPSTR)data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003325}
3326
3327
3328/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003329 * InsertMenu32A (USER32.322)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003330 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003331BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
3332 UINT id, LPCSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003333{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003334 MENUITEM *item;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003335
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003336 if (IS_STRING_ITEM(flags) && str)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003337 TRACE(menu, "hMenu %04x, pos %d, flags %08x, "
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003338 "id %04x, str '%s'\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003339 hMenu, pos, flags, id, str );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003340 else TRACE(menu, "hMenu %04x, pos %d, flags %08x, "
Alexandre Julliardd37eb361997-07-20 16:23:21 +00003341 "id %04x, str %08lx (not a string)\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003342 hMenu, pos, flags, id, (DWORD)str );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003343
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003344 if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003345
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003346 if (!(MENU_SetItemData( item, flags, id, str )))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003347 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003348 RemoveMenu( hMenu, pos, flags );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003349 return FALSE;
3350 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003351
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003352 if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003353 ((POPUPMENU *)USER_HEAP_LIN_ADDR((HMENU16)id))->wFlags |= MF_POPUP;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003354
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003355 item->hCheckBit = item->hUnCheckBit = 0;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003356 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003357}
3358
3359
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003360/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003361 * InsertMenu32W (USER32.325)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003362 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003363BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
3364 UINT id, LPCWSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003365{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003366 BOOL ret;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003367
3368 if (IS_STRING_ITEM(flags) && str)
3369 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003370 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003371 ret = InsertMenuA( hMenu, pos, flags, id, newstr );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003372 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003373 return ret;
3374 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003375 else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003376}
3377
3378
3379/*******************************************************************
3380 * AppendMenu16 (USER.411)
3381 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003382BOOL16 WINAPI AppendMenu16(HMENU16 hMenu, UINT16 flags, UINT16 id, SEGPTR data)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003383{
3384 return InsertMenu16( hMenu, -1, flags | MF_BYPOSITION, id, data );
3385}
3386
3387
3388/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003389 * AppendMenu32A (USER32.5)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003390 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003391BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
3392 UINT id, LPCSTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003393{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003394 return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003395}
3396
3397
3398/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003399 * AppendMenu32W (USER32.6)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003400 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003401BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
3402 UINT id, LPCWSTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003403{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003404 return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003405}
3406
3407
3408/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003409 * RemoveMenu16 (USER.412)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003410 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003411BOOL16 WINAPI RemoveMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003412{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003413 return RemoveMenu( hMenu, nPos, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003414}
3415
3416
3417/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003418 * RemoveMenu (USER32.441)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003419 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003420BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003421{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003422 LPPOPUPMENU menu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003423 MENUITEM *item;
3424
Juergen Schmied78513941999-04-18 14:40:32 +00003425 TRACE(menu,"(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003426 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003427 if (!(menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003428
3429 /* Remove item */
3430
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003431 MENU_FreeItemData( item );
3432
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003433 if (--menu->nItems == 0)
3434 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003435 HeapFree( SystemHeap, 0, menu->items );
3436 menu->items = NULL;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003437 }
3438 else
3439 {
3440 while(nPos < menu->nItems)
3441 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003442 *item = *(item+1);
3443 item++;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003444 nPos++;
3445 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003446 menu->items = HeapReAlloc( SystemHeap, 0, menu->items,
3447 menu->nItems * sizeof(MENUITEM) );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003448 }
3449 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003450}
3451
3452
3453/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003454 * DeleteMenu16 (USER.413)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003455 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003456BOOL16 WINAPI DeleteMenu16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003457{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003458 return DeleteMenu( hMenu, nPos, wFlags );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003459}
3460
3461
3462/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003463 * DeleteMenu32 (USER32.129)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003464 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003465BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003466{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003467 MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
3468 if (!item) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003469 if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003470 /* nPos is now the position of the item */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003471 RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003472 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003473}
3474
3475
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003476/*******************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003477 * ModifyMenu16 (USER.414)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003478 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003479BOOL16 WINAPI ModifyMenu16( HMENU16 hMenu, UINT16 pos, UINT16 flags,
3480 UINT16 id, SEGPTR data )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003481{
3482 if (IS_STRING_ITEM(flags))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003483 return ModifyMenuA( hMenu, pos, flags, id,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003484 (LPSTR)PTR_SEG_TO_LIN(data) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003485 return ModifyMenuA( hMenu, pos, flags, id, (LPSTR)data );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003486}
3487
3488
3489/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003490 * ModifyMenu32A (USER32.397)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003491 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003492BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
3493 UINT id, LPCSTR str )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003494{
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003495 MENUITEM *item;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003496
3497 if (IS_STRING_ITEM(flags))
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003498 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003499 TRACE(menu, "%04x %d %04x %04x '%s'\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003500 hMenu, pos, flags, id, str ? str : "#NULL#" );
3501 if (!str) return FALSE;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00003502 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003503 else
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003504 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003505 TRACE(menu, "%04x %d %04x %04x %08lx\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003506 hMenu, pos, flags, id, (DWORD)str );
3507 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003508
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003509 if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003510 return MENU_SetItemData( item, flags, id, str );
3511}
3512
3513
3514/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003515 * ModifyMenu32W (USER32.398)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003516 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003517BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
3518 UINT id, LPCWSTR str )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003519{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003520 BOOL ret;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003521
3522 if (IS_STRING_ITEM(flags) && str)
3523 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003524 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00003525 ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00003526 HeapFree( GetProcessHeap(), 0, newstr );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003527 return ret;
3528 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003529 else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003530}
3531
3532
3533/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003534 * CreatePopupMenu16 (USER.415)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003535 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003536HMENU16 WINAPI CreatePopupMenu16(void)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003537{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003538 return CreatePopupMenu();
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003539}
3540
3541
3542/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003543 * CreatePopupMenu32 (USER32.82)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003544 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003545HMENU WINAPI CreatePopupMenu(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003546{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003547 HMENU hmenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003548 POPUPMENU *menu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003549
Alexandre Julliarda3960291999-02-26 11:11:13 +00003550 if (!(hmenu = CreateMenu())) return 0;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003551 menu = (POPUPMENU *) USER_HEAP_LIN_ADDR( hmenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003552 menu->wFlags |= MF_POPUP;
3553 return hmenu;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003554}
3555
3556
3557/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003558 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003559 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003560DWORD WINAPI GetMenuCheckMarkDimensions(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003561{
Alexandre Julliardf7207251994-07-23 07:57:48 +00003562 return MAKELONG( check_bitmap_width, check_bitmap_height );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003563}
3564
3565
3566/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003567 * SetMenuItemBitmaps16 (USER.418)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003568 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003569BOOL16 WINAPI SetMenuItemBitmaps16( HMENU16 hMenu, UINT16 nPos, UINT16 wFlags,
3570 HBITMAP16 hNewUnCheck, HBITMAP16 hNewCheck)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003571{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003572 return SetMenuItemBitmaps( hMenu, nPos, wFlags, hNewUnCheck, hNewCheck );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003573}
3574
3575
3576/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003577 * SetMenuItemBitmaps32 (USER32.490)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003578 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003579BOOL WINAPI SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags,
3580 HBITMAP hNewUnCheck, HBITMAP hNewCheck)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003581{
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003582 MENUITEM *item;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003583 TRACE(menu,"(%04x, %04x, %04x, %04x, %04x)\n",
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003584 hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
3585 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003586
3587 if (!hNewCheck && !hNewUnCheck)
3588 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003589 item->fState &= ~MF_USECHECKBITMAPS;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003590 }
3591 else /* Install new bitmaps */
3592 {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003593 item->hCheckBit = hNewCheck;
3594 item->hUnCheckBit = hNewUnCheck;
3595 item->fState |= MF_USECHECKBITMAPS;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003596 }
3597 return TRUE;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003598}
3599
3600
3601/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003602 * CreateMenu16 (USER.151)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003603 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003604HMENU16 WINAPI CreateMenu16(void)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003605{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003606 return CreateMenu();
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003607}
3608
3609
3610/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003611 * CreateMenu (USER32.81)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003612 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003613HMENU WINAPI CreateMenu(void)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003614{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003615 HMENU hMenu;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003616 LPPOPUPMENU menu;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003617 if (!(hMenu = USER_HEAP_ALLOC( sizeof(POPUPMENU) ))) return 0;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00003618 menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Juergen Schmied78513941999-04-18 14:40:32 +00003619
3620 ZeroMemory(menu, sizeof(POPUPMENU));
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003621 menu->wMagic = MENU_MAGIC;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003622 menu->FocusedItem = NO_SELECTED_ITEM;
Juergen Schmied78513941999-04-18 14:40:32 +00003623
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003624 TRACE(menu, "return %04x\n", hMenu );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003625 return hMenu;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003626}
3627
3628
3629/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003630 * DestroyMenu16 (USER.152)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003631 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003632BOOL16 WINAPI DestroyMenu16( HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003633{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003634 return DestroyMenu( hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003635}
3636
3637
3638/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003639 * DestroyMenu32 (USER32.134)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003640 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003641BOOL WINAPI DestroyMenu( HMENU hMenu )
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003642{
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003643 TRACE(menu,"(%04x)\n", hMenu);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003644
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003645 /* Silently ignore attempts to destroy default system popup */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003646
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003647 if (hMenu && hMenu != MENU_DefSysPopup)
Alexandre Julliardff8331e1995-09-18 11:19:54 +00003648 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003649 LPPOPUPMENU lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003650 WND *pTPWnd = MENU_GetTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003651
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003652 if( pTPWnd && (hMenu == *(HMENU*)pTPWnd->wExtra) )
3653 *(UINT*)pTPWnd->wExtra = 0;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003654
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003655 if (IS_A_MENU( lppop ))
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003656 {
3657 lppop->wMagic = 0; /* Mark it as destroyed */
3658
3659 if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003660 (!pTPWnd || (lppop->hWnd != pTPWnd->hwndSelf)))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003661 DestroyWindow( lppop->hWnd );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003662
3663 if (lppop->items) /* recursively destroy submenus */
3664 {
3665 int i;
3666 MENUITEM *item = lppop->items;
3667 for (i = lppop->nItems; i > 0; i--, item++)
3668 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003669 if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003670 MENU_FreeItemData( item );
3671 }
3672 HeapFree( SystemHeap, 0, lppop->items );
3673 }
3674 USER_HEAP_FREE( hMenu );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00003675 MENU_ReleaseTopPopupWnd();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003676 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00003677 else
3678 {
3679 MENU_ReleaseTopPopupWnd();
3680 return FALSE;
3681 }
Alexandre Julliardff8331e1995-09-18 11:19:54 +00003682 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003683 return (hMenu != MENU_DefSysPopup);
Alexandre Julliard5f721f81994-01-04 20:14:34 +00003684}
3685
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003686
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003687/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003688 * GetSystemMenu16 (USER.156)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003689 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003690HMENU16 WINAPI GetSystemMenu16( HWND16 hWnd, BOOL16 bRevert )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003691{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003692 return GetSystemMenu( hWnd, bRevert );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003693}
3694
3695
3696/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003697 * GetSystemMenu32 (USER32.291)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003698 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003699HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003700{
Alexandre Julliardb7258be1995-09-01 15:57:28 +00003701 WND *wndPtr = WIN_FindWndPtr( hWnd );
Alexandre Julliardb7258be1995-09-01 15:57:28 +00003702
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003703 if (wndPtr)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003704 {
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003705 if( wndPtr->hSysMenu )
3706 {
3707 if( bRevert )
3708 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003709 DestroyMenu(wndPtr->hSysMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003710 wndPtr->hSysMenu = 0;
3711 }
3712 else
3713 {
3714 POPUPMENU *menu = (POPUPMENU*)
3715 USER_HEAP_LIN_ADDR(wndPtr->hSysMenu);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003716 if( menu->items[0].hSubMenu == MENU_DefSysPopup )
3717 menu->items[0].hSubMenu = MENU_CopySysPopup();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003718 }
3719 }
3720
3721 if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) )
Alexandre Julliarda3960291999-02-26 11:11:13 +00003722 wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003723
3724 if( wndPtr->hSysMenu )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003725 {
3726 HMENU retvalue = GetSubMenu16(wndPtr->hSysMenu, 0);
3727 WIN_ReleaseWndPtr(wndPtr);
3728 return retvalue;
3729 }
3730 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003731 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003732 return 0;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003733}
3734
Alexandre Julliard7e56f681996-01-31 19:02:28 +00003735
3736/*******************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003737 * SetSystemMenu16 (USER.280)
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003738 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003739BOOL16 WINAPI SetSystemMenu16( HWND16 hwnd, HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003740{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003741 return SetSystemMenu( hwnd, hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003742}
3743
3744
3745/*******************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003746 * SetSystemMenu32 (USER32.508)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003747 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003748BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003749{
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003750 WND *wndPtr = WIN_FindWndPtr(hwnd);
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003751
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003752 if (wndPtr)
3753 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003754 if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu );
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003755 wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003756 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003757 return TRUE;
3758 }
3759 return FALSE;
Alexandre Julliard1d62f6b1994-05-04 19:15:00 +00003760}
3761
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003762
3763/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003764 * GetMenu16 (USER.157)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003765 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003766HMENU16 WINAPI GetMenu16( HWND16 hWnd )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003767{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003768 HMENU16 retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003769 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003770 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003771 {
3772 retvalue = (HMENU16)wndPtr->wIDmenu;
3773 goto END;
3774}
3775 retvalue = 0;
3776END:
3777 WIN_ReleaseWndPtr(wndPtr);
3778 return retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003779}
3780
3781
3782/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003783 * GetMenu32 (USER32.257)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003784 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003785HMENU WINAPI GetMenu( HWND hWnd )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003786{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003787 HMENU retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003788 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003789 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003790 {
3791 retvalue = (HMENU)wndPtr->wIDmenu;
3792 goto END;
3793 }
3794 retvalue = 0;
3795END:
3796 WIN_ReleaseWndPtr(wndPtr);
3797 return retvalue;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003798}
3799
3800
3801/**********************************************************************
3802 * SetMenu16 (USER.158)
3803 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003804BOOL16 WINAPI SetMenu16( HWND16 hWnd, HMENU16 hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003805{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003806 return SetMenu( hWnd, hMenu );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003807}
3808
3809
3810/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003811 * SetMenu32 (USER32.487)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003812 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003813BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003814{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003815 WND * wndPtr = WIN_FindWndPtr(hWnd);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003816
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003817 TRACE(menu,"(%04x, %04x);\n", hWnd, hMenu);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003818
3819 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003820 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003821 if (GetCapture() == hWnd) ReleaseCapture();
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003822
Alexandre Julliarda3960291999-02-26 11:11:13 +00003823 wndPtr->wIDmenu = (UINT)hMenu;
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003824 if (hMenu != 0)
3825 {
3826 LPPOPUPMENU lpmenu;
3827
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003828 if (!(lpmenu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hMenu)))
3829 {
3830 WIN_ReleaseWndPtr(wndPtr);
3831 return FALSE;
3832 }
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003833 lpmenu->hWnd = hWnd;
3834 lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
3835 lpmenu->Height = 0; /* Make sure we recalculate the size */
3836 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00003837 if (IsWindowVisible(hWnd))
3838 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliard01d63461997-01-20 19:43:45 +00003839 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003840 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003841 return TRUE;
3842 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003843 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003844 return FALSE;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003845}
3846
3847
Alexandre Julliardd18872d1994-05-11 12:18:19 +00003848
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003849/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003850 * GetSubMenu16 (USER.159)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003851 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003852HMENU16 WINAPI GetSubMenu16( HMENU16 hMenu, INT16 nPos )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003853{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003854 return GetSubMenu( hMenu, nPos );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003855}
3856
3857
3858/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003859 * GetSubMenu32 (USER32.288)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003860 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003861HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003862{
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003863 MENUITEM * lpmi;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003864
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00003865 if (!(lpmi = MENU_FindItem(&hMenu,&nPos,MF_BYPOSITION))) return 0;
3866 if (!(lpmi->fType & MF_POPUP)) return 0;
3867 return lpmi->hSubMenu;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00003868}
3869
3870
3871/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003872 * DrawMenuBar16 (USER.160)
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003873 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003874void WINAPI DrawMenuBar16( HWND16 hWnd )
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003875{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003876 DrawMenuBar( hWnd );
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003877}
Alexandre Julliardf7207251994-07-23 07:57:48 +00003878
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003879
3880/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00003881 * DrawMenuBar (USER32.161)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003882 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003883BOOL WINAPI DrawMenuBar( HWND hWnd )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003884{
3885 LPPOPUPMENU lppop;
3886 WND *wndPtr = WIN_FindWndPtr(hWnd);
3887 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && wndPtr->wIDmenu)
3888 {
3889 lppop = (LPPOPUPMENU) USER_HEAP_LIN_ADDR((HMENU16)wndPtr->wIDmenu);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003890 if (lppop == NULL)
3891 {
3892 WIN_ReleaseWndPtr(wndPtr);
3893 return FALSE;
3894 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003895
3896 lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
Juergen Schmied78513941999-04-18 14:40:32 +00003897 lppop->hwndOwner = hWnd;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003898 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
Alexandre Julliard01d63461997-01-20 19:43:45 +00003899 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003900 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003901 return TRUE;
3902 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00003903 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003904 return FALSE;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003905}
3906
3907
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003908/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003909 * EndMenu (USER.187) (USER32.175)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003910 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003911void WINAPI EndMenu(void)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003912{
Alex Korobka4f1ac051999-03-28 09:37:57 +00003913 /*
3914 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
3915 */
3916
Alexandre Julliard7ff1c411997-05-25 13:58:18 +00003917 fEndMenu = TRUE;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003918}
3919
3920
3921/***********************************************************************
3922 * LookupMenuHandle (USER.217)
3923 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003924HMENU16 WINAPI LookupMenuHandle16( HMENU16 hmenu, INT16 id )
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003925{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003926 HMENU hmenu32 = hmenu;
3927 UINT id32 = id;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003928 if (!MENU_FindItem( &hmenu32, &id32, MF_BYCOMMAND )) return 0;
3929 else return hmenu32;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00003930}
3931
3932
Alexandre Julliardcdd09231994-01-12 11:12:51 +00003933/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003934 * LoadMenu16 (USER.150)
Alexandre Julliard594997c1995-04-30 10:05:20 +00003935 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003936HMENU16 WINAPI LoadMenu16( HINSTANCE16 instance, SEGPTR name )
Alexandre Julliard594997c1995-04-30 10:05:20 +00003937{
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003938 HRSRC16 hRsrc;
3939 HGLOBAL16 handle;
3940 HMENU16 hMenu;
Alexandre Julliard594997c1995-04-30 10:05:20 +00003941
3942 if (HIWORD(name))
3943 {
3944 char *str = (char *)PTR_SEG_TO_LIN( name );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003945 TRACE(menu, "(%04x,'%s')\n", instance, str );
Alexandre Julliard594997c1995-04-30 10:05:20 +00003946 if (str[0] == '#') name = (SEGPTR)atoi( str + 1 );
3947 }
3948 else
Dimitrie O. Paun05c0c8e1999-03-28 15:07:41 +00003949 TRACE(menu,"(%04x,%04x)\n",instance,LOWORD(name));
Alexandre Julliard594997c1995-04-30 10:05:20 +00003950
3951 if (!name) return 0;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00003952
3953 /* check for Win32 module */
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00003954 if (HIWORD(instance))
Alexandre Julliarda3960291999-02-26 11:11:13 +00003955 return LoadMenuA(instance,PTR_SEG_TO_LIN(name));
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00003956 instance = GetExePtr( instance );
Alexandre Julliard594997c1995-04-30 10:05:20 +00003957
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003958 if (!(hRsrc = FindResource16( instance, name, RT_MENU16 ))) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003959 if (!(handle = LoadResource16( instance, hRsrc ))) return 0;
3960 hMenu = LoadMenuIndirect16(LockResource16(handle));
3961 FreeResource16( handle );
Alexandre Julliard594997c1995-04-30 10:05:20 +00003962 return hMenu;
3963}
3964
3965
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003966/*****************************************************************
3967 * LoadMenu32A (USER32.370)
3968 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003969HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003970{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003971 HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003972 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003973 return LoadMenuIndirectA( (LPCVOID)LoadResource( instance, hrsrc ));
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003974}
3975
3976
3977/*****************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00003978 * LoadMenu32W (USER32.373)
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003979 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003980HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003981{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003982 HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003983 if (!hrsrc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003984 return LoadMenuIndirectW( (LPCVOID)LoadResource( instance, hrsrc ));
Alexandre Julliard18f92e71996-07-17 20:02:21 +00003985}
3986
3987
Alexandre Julliard594997c1995-04-30 10:05:20 +00003988/**********************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003989 * LoadMenuIndirect16 (USER.220)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003990 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00003991HMENU16 WINAPI LoadMenuIndirect16( LPCVOID template )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003992{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00003993 HMENU16 hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003994 WORD version, offset;
3995 LPCSTR p = (LPCSTR)template;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003996
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00003997 TRACE(menu,"(%p)\n", template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00003998 version = GET_WORD(p);
3999 p += sizeof(WORD);
4000 if (version)
4001 {
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004002 WARN(menu, "version must be 0 for Win16\n" );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004003 return 0;
4004 }
4005 offset = GET_WORD(p);
4006 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004007 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004008 if (!MENU_ParseResource( p, hMenu, FALSE ))
Alexandre Julliard7e56f681996-01-31 19:02:28 +00004009 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004010 DestroyMenu( hMenu );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004011 return 0;
Alexandre Julliard7e56f681996-01-31 19:02:28 +00004012 }
4013 return hMenu;
Alexandre Julliardcdd09231994-01-12 11:12:51 +00004014}
4015
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00004016
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004017/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004018 * LoadMenuIndirect32A (USER32.371)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004019 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004020HMENU WINAPI LoadMenuIndirectA( LPCVOID template )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004021{
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00004022 HMENU16 hMenu;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004023 WORD version, offset;
4024 LPCSTR p = (LPCSTR)template;
4025
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004026 TRACE(menu,"%p\n", template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004027 version = GET_WORD(p);
4028 p += sizeof(WORD);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004029 switch (version)
4030 {
4031 case 0:
4032 offset = GET_WORD(p);
4033 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004034 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004035 if (!MENU_ParseResource( p, hMenu, TRUE ))
4036 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004037 DestroyMenu( hMenu );
Alexandre Julliard641ee761997-08-04 16:34:36 +00004038 return 0;
4039 }
4040 return hMenu;
4041 case 1:
4042 offset = GET_WORD(p);
4043 p += sizeof(WORD) + offset;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004044 if (!(hMenu = CreateMenu())) return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004045 if (!MENUEX_ParseResource( p, hMenu))
4046 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004047 DestroyMenu( hMenu );
Alexandre Julliard641ee761997-08-04 16:34:36 +00004048 return 0;
4049 }
4050 return hMenu;
4051 default:
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004052 ERR(menu, "version %d not supported.\n", version);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004053 return 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004054 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004055}
4056
4057
4058/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004059 * LoadMenuIndirect32W (USER32.372)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004060 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004061HMENU WINAPI LoadMenuIndirectW( LPCVOID template )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004062{
4063 /* FIXME: is there anything different between A and W? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004064 return LoadMenuIndirectA( template );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00004065}
4066
4067
4068/**********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004069 * IsMenu16 (USER.358)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004070 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004071BOOL16 WINAPI IsMenu16( HMENU16 hmenu )
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004072{
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004073 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4074 return IS_A_MENU(menu);
4075}
4076
4077
4078/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004079 * IsMenu32 (USER32.346)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004080 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004081BOOL WINAPI IsMenu(HMENU hmenu)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004082{
4083 LPPOPUPMENU menu = (LPPOPUPMENU) USER_HEAP_LIN_ADDR(hmenu);
4084 return IS_A_MENU(menu);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004085}
4086
Alexandre Julliard641ee761997-08-04 16:34:36 +00004087/**********************************************************************
4088 * GetMenuItemInfo32_common
4089 */
4090
Juergen Schmied78513941999-04-18 14:40:32 +00004091static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
4092 LPMENUITEMINFOA lpmii, BOOL unicode)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004093{
Juergen Schmied78513941999-04-18 14:40:32 +00004094 MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
4095
Alexandre Julliard03468f71998-02-15 19:40:49 +00004096 debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
Juergen Schmied78513941999-04-18 14:40:32 +00004097
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004098 if (!menu)
4099 return FALSE;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004100
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004101 if (lpmii->fMask & MIIM_TYPE) {
4102 lpmii->fType = menu->fType;
4103 switch (MENU_ITEM_TYPE(menu->fType)) {
Juergen Schmied78513941999-04-18 14:40:32 +00004104 case MF_STRING:
4105 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
4106 if (unicode) {
4107 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4108 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4109 } else {
4110 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4111 lpmii->cch = lstrlenA(menu->text);
4112 }
4113 }
4114 break;
4115 case MF_OWNERDRAW:
4116 case MF_BITMAP:
4117 lpmii->dwTypeData = menu->text;
4118 /* fall through */
4119 default:
4120 lpmii->cch = 0;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004121 }
Alexandre Julliard641ee761997-08-04 16:34:36 +00004122 }
Juergen Schmied78513941999-04-18 14:40:32 +00004123
4124 if (lpmii->fMask & MIIM_STRING) {
4125 if (unicode) {
4126 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
4127 lpmii->cch = lstrlenW((LPWSTR)menu->text);
4128 } else {
4129 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
4130 lpmii->cch = lstrlenA(menu->text);
4131 }
Alexandre Julliard641ee761997-08-04 16:34:36 +00004132 }
Juergen Schmied78513941999-04-18 14:40:32 +00004133
4134 if (lpmii->fMask & MIIM_FTYPE)
4135 lpmii->fType = menu->fType;
4136
4137 if (lpmii->fMask & MIIM_BITMAP)
4138 lpmii->hbmpItem = menu->hbmpItem;
4139
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004140 if (lpmii->fMask & MIIM_STATE)
4141 lpmii->fState = menu->fState;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004142
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004143 if (lpmii->fMask & MIIM_ID)
4144 lpmii->wID = menu->wID;
4145
4146 if (lpmii->fMask & MIIM_SUBMENU)
4147 lpmii->hSubMenu = menu->hSubMenu;
4148
4149 if (lpmii->fMask & MIIM_CHECKMARKS) {
4150 lpmii->hbmpChecked = menu->hCheckBit;
4151 lpmii->hbmpUnchecked = menu->hUnCheckBit;
4152 }
4153 if (lpmii->fMask & MIIM_DATA)
4154 lpmii->dwItemData = menu->dwItemData;
Alexandre Julliard641ee761997-08-04 16:34:36 +00004155
4156 return TRUE;
4157}
4158
4159/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004160 * GetMenuItemInfoA (USER32.264)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004161 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004162BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
4163 LPMENUITEMINFOA lpmii)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004164{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004165 return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004166}
4167
4168/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004169 * GetMenuItemInfoW (USER32.265)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004170 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004171BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
4172 LPMENUITEMINFOW lpmii)
Alexandre Julliard641ee761997-08-04 16:34:36 +00004173{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004174 return GetMenuItemInfo_common (hmenu, item, bypos,
4175 (LPMENUITEMINFOA)lpmii, TRUE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00004176}
4177
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004178/**********************************************************************
4179 * SetMenuItemInfo32_common
4180 */
4181
Alexandre Julliarda3960291999-02-26 11:11:13 +00004182static BOOL SetMenuItemInfo_common(MENUITEM * menu,
4183 const MENUITEMINFOA *lpmii,
4184 BOOL unicode)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004185{
4186 if (!menu) return FALSE;
4187
Juergen Schmied78513941999-04-18 14:40:32 +00004188 if (lpmii->fMask & MIIM_TYPE ) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004189 /* Get rid of old string. */
Juergen Schmied78513941999-04-18 14:40:32 +00004190 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004191 HeapFree(SystemHeap, 0, menu->text);
Juergen Schmied78513941999-04-18 14:40:32 +00004192 menu->text = NULL;
4193 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004194
Juergen Schmied78513941999-04-18 14:40:32 +00004195 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4196 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4197 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
Paul Millar39da2221999-04-11 12:08:42 +00004198
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004199 menu->text = lpmii->dwTypeData;
Juergen Schmied78513941999-04-18 14:40:32 +00004200
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004201 if (IS_STRING_ITEM(menu->fType) && menu->text) {
Juergen Schmied78513941999-04-18 14:40:32 +00004202 if (unicode)
4203 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4204 else
4205 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004206 }
4207 }
Juergen Schmied78513941999-04-18 14:40:32 +00004208
4209 if (lpmii->fMask & MIIM_FTYPE ) {
4210 /* free the string when the type is changing */
4211 if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
4212 HeapFree(SystemHeap, 0, menu->text);
4213 menu->text = NULL;
4214 }
4215 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4216 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4217 }
4218
4219 if (lpmii->fMask & MIIM_STRING ) {
4220 /* free the string when used */
4221 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4222 HeapFree(SystemHeap, 0, menu->text);
4223 if (unicode)
4224 menu->text = HEAP_strdupWtoA(SystemHeap, 0, (LPWSTR) lpmii->dwTypeData);
4225 else
4226 menu->text = HEAP_strdupA(SystemHeap, 0, lpmii->dwTypeData);
4227 }
4228 }
4229
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004230 if (lpmii->fMask & MIIM_STATE)
4231 menu->fState = lpmii->fState;
4232
4233 if (lpmii->fMask & MIIM_ID)
4234 menu->wID = lpmii->wID;
4235
Alexandre Julliarda0d77311998-09-13 16:32:00 +00004236 if (lpmii->fMask & MIIM_SUBMENU) {
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004237 menu->hSubMenu = lpmii->hSubMenu;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00004238 if (menu->hSubMenu) {
4239 POPUPMENU *subMenu = (POPUPMENU *)USER_HEAP_LIN_ADDR((UINT16)menu->hSubMenu);
4240 if (IS_A_MENU(subMenu)) {
4241 subMenu->wFlags |= MF_POPUP;
4242 menu->fType |= MF_POPUP;
4243 }
4244 else
4245 /* FIXME: Return an error ? */
4246 menu->fType &= ~MF_POPUP;
4247 }
4248 else
4249 menu->fType &= ~MF_POPUP;
4250 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004251
4252 if (lpmii->fMask & MIIM_CHECKMARKS)
4253 {
4254 menu->hCheckBit = lpmii->hbmpChecked;
4255 menu->hUnCheckBit = lpmii->hbmpUnchecked;
4256 }
4257 if (lpmii->fMask & MIIM_DATA)
4258 menu->dwItemData = lpmii->dwItemData;
4259
Alexandre Julliard03468f71998-02-15 19:40:49 +00004260 debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004261 return TRUE;
4262}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004263
4264/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004265 * SetMenuItemInfo32A (USER32.491)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004266 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004267BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
4268 const MENUITEMINFOA *lpmii)
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004269{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004270 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004271 lpmii, FALSE);
4272}
4273
4274/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004275 * SetMenuItemInfo32W (USER32.492)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004276 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004277BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
4278 const MENUITEMINFOW *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004279{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004280 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4281 (const MENUITEMINFOA*)lpmii, TRUE);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004282}
4283
4284/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004285 * SetMenuDefaultItem32 (USER32.489)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004286 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004287BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT item, UINT bypos)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004288{
Alexandre Julliarda845b881998-06-01 10:44:35 +00004289 MENUITEM *menuitem = MENU_FindItem(&hmenu, &item, bypos);
4290 POPUPMENU *menu;
4291
4292 if (!menuitem) return FALSE;
4293 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu))) return FALSE;
4294
4295 menu->defitem = item; /* position */
4296
4297 debug_print_menuitem("SetMenuDefaultItem32: ", menuitem, "");
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004298 FIXME(menu, "(0x%x,%d,%d), empty stub!\n",
4299 hmenu, item, bypos);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004300 return TRUE;
4301}
4302
Alexandre Julliarda845b881998-06-01 10:44:35 +00004303/**********************************************************************
Juergen Schmiedc77fd5b1999-04-21 14:27:37 +00004304 * GetMenuDefaultItem (USER32.260)
Alexandre Julliarda845b881998-06-01 10:44:35 +00004305 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004306UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
Alexandre Julliarda845b881998-06-01 10:44:35 +00004307{
4308 POPUPMENU *menu;
4309
Eric Kohl329072d1998-10-24 10:46:10 +00004310 if (!(menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hmenu)))
4311 return -1;
Alexandre Julliarda845b881998-06-01 10:44:35 +00004312
4313 FIXME(menu, "(0x%x,%d,%d), stub!\n", hmenu, bypos, flags);
4314 if (bypos & MF_BYPOSITION)
4315 return menu->defitem;
Eric Kohl329072d1998-10-24 10:46:10 +00004316 else {
4317 FIXME (menu, "default item 0x%x\n", menu->defitem);
4318 if ((menu->defitem > 0) && (menu->defitem < menu->nItems))
4319 return menu->items[menu->defitem].wID;
4320 }
4321 return -1;
Alexandre Julliarda845b881998-06-01 10:44:35 +00004322}
4323
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004324/*******************************************************************
4325 * InsertMenuItem16 (USER.441)
4326 *
4327 * FIXME: untested
4328 */
4329BOOL16 WINAPI InsertMenuItem16( HMENU16 hmenu, UINT16 pos, BOOL16 byposition,
4330 const MENUITEMINFO16 *mii )
4331{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004332 MENUITEMINFOA miia;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004333
4334 miia.cbSize = sizeof(miia);
4335 miia.fMask = mii->fMask;
Alexandre Julliard77b99181997-09-14 17:17:23 +00004336 miia.dwTypeData = mii->dwTypeData;
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004337 miia.fType = mii->fType;
4338 miia.fState = mii->fState;
4339 miia.wID = mii->wID;
4340 miia.hSubMenu = mii->hSubMenu;
4341 miia.hbmpChecked = mii->hbmpChecked;
4342 miia.hbmpUnchecked = mii->hbmpUnchecked;
4343 miia.dwItemData = mii->dwItemData;
4344 miia.cch = mii->cch;
4345 if (IS_STRING_ITEM(miia.fType))
4346 miia.dwTypeData = PTR_SEG_TO_LIN(miia.dwTypeData);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004347 return InsertMenuItemA( hmenu, pos, byposition, &miia );
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004348}
4349
4350
4351/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004352 * InsertMenuItem32A (USER32.323)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004353 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004354BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
4355 const MENUITEMINFOA *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004356{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004357 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00004358 return SetMenuItemInfo_common(item, lpmii, FALSE);
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004359}
4360
4361
4362/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00004363 * InsertMenuItem32W (USER32.324)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004364 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004365BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
4366 const MENUITEMINFOW *lpmii)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00004367{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004368 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
Alexandre Julliarda3960291999-02-26 11:11:13 +00004369 return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
Alexandre Julliard7cc9c0c1994-06-15 15:45:11 +00004370}
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004371
4372/**********************************************************************
4373 * CheckMenuRadioItem32 (USER32.47)
4374 */
4375
Alexandre Julliarda3960291999-02-26 11:11:13 +00004376BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
4377 UINT first, UINT last, UINT check,
4378 UINT bypos)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004379{
4380 MENUITEM *mifirst, *milast, *micheck;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004381 HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004382
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00004383 TRACE(menu, "ox%x: %d-%d, check %d, bypos=%d\n",
4384 hMenu, first, last, check, bypos);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004385
4386 mifirst = MENU_FindItem (&mfirst, &first, bypos);
4387 milast = MENU_FindItem (&mlast, &last, bypos);
4388 micheck = MENU_FindItem (&mcheck, &check, bypos);
4389
4390 if (mifirst == NULL || milast == NULL || micheck == NULL ||
4391 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
4392 micheck > milast || micheck < mifirst)
4393 return FALSE;
4394
4395 while (mifirst <= milast)
4396 {
4397 if (mifirst == micheck)
4398 {
4399 mifirst->fType |= MFT_RADIOCHECK;
4400 mifirst->fState |= MFS_CHECKED;
4401 } else {
4402 mifirst->fType &= ~MFT_RADIOCHECK;
4403 mifirst->fState &= ~MFS_CHECKED;
4404 }
4405 mifirst++;
4406 }
4407
4408 return TRUE;
4409}
4410
4411/**********************************************************************
4412 * CheckMenuRadioItem16 (not a Windows API)
4413 */
4414
4415BOOL16 WINAPI CheckMenuRadioItem16(HMENU16 hMenu,
4416 UINT16 first, UINT16 last, UINT16 check,
4417 BOOL16 bypos)
4418{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004419 return CheckMenuRadioItem (hMenu, first, last, check, bypos);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004420}
4421
4422/**********************************************************************
4423 * GetMenuItemRect32 (USER32.266)
Pascal Lessard47274231999-02-13 12:21:46 +00004424 *
4425 * ATTENTION: Here, the returned values in rect are the screen
4426 * coordinates of the item just like if the menu was
4427 * always on the upper left side of the application.
4428 *
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004429 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004430BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
4431 LPRECT rect)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004432{
Pascal Lessard47274231999-02-13 12:21:46 +00004433 POPUPMENU *itemMenu;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004434 MENUITEM *item;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004435 HWND referenceHwnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004436
Pascal Lessard47274231999-02-13 12:21:46 +00004437 TRACE(menu, "(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004438
4439 item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
Pascal Lessard47274231999-02-13 12:21:46 +00004440 referenceHwnd = hwnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004441
Pascal Lessard47274231999-02-13 12:21:46 +00004442 if(!hwnd)
4443 {
4444 itemMenu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu);
4445 if (itemMenu == NULL)
4446 return FALSE;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004447
Marcus Meissnerac593bb1999-03-17 15:18:28 +00004448 if(itemMenu->hWnd == 0)
Pascal Lessard47274231999-02-13 12:21:46 +00004449 return FALSE;
4450 referenceHwnd = itemMenu->hWnd;
4451 }
4452
4453 if ((rect == NULL) || (item == NULL))
4454 return FALSE;
4455
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004456 *rect = item->rect;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004457
Alexandre Julliarda3960291999-02-26 11:11:13 +00004458 MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
Pascal Lessard47274231999-02-13 12:21:46 +00004459
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004460 return TRUE;
4461}
4462
4463/**********************************************************************
4464 * GetMenuItemRect16 (USER.665)
4465 */
4466
4467BOOL16 WINAPI GetMenuItemRect16 (HWND16 hwnd, HMENU16 hMenu, UINT16 uItem,
4468 LPRECT16 rect)
4469{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004470 RECT r32;
4471 BOOL res;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004472
4473 if (!rect) return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004474 res = GetMenuItemRect (hwnd, hMenu, uItem, &r32);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00004475 CONV_RECT32TO16 (&r32, rect);
4476 return res;
4477}
Paul Quinn1beaae51998-12-15 15:38:36 +00004478
4479/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004480 * SetMenuInfo
4481 *
4482 * FIXME
4483 * MIM_APPLYTOSUBMENUS
4484 * actually use the items to draw the menu
4485 */
4486BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
4487{
4488 POPUPMENU *menu;
4489
4490 TRACE(menu,"(0x%04x %p)\n", hMenu, lpmi);
4491
4492 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)USER_HEAP_LIN_ADDR(hMenu)))
4493 {
4494
4495 if (lpmi->fMask & MIM_BACKGROUND)
4496 menu->hbrBack = lpmi->hbrBack;
4497
4498 if (lpmi->fMask & MIM_HELPID)
4499 menu->dwContextHelpID = lpmi->dwContextHelpID;
4500
4501 if (lpmi->fMask & MIM_MAXHEIGHT)
4502 menu->cyMax = lpmi->cyMax;
4503
4504 if (lpmi->fMask & MIM_MENUDATA)
4505 menu->dwMenuData = lpmi->dwMenuData;
4506
4507 if (lpmi->fMask & MIM_STYLE)
4508 menu->dwStyle = lpmi->dwStyle;
4509
4510 return TRUE;
4511 }
4512 return FALSE;
4513}
4514
4515/**********************************************************************
4516 * GetMenuInfo
4517 *
4518 * NOTES
4519 * win98/NT5.0
4520 *
4521 */
4522BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
4523{ POPUPMENU *menu;
4524
4525 TRACE(menu,"(0x%04x %p)\n", hMenu, lpmi);
4526
4527 if (lpmi && (menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4528 {
4529
4530 if (lpmi->fMask & MIM_BACKGROUND)
4531 lpmi->hbrBack = menu->hbrBack;
4532
4533 if (lpmi->fMask & MIM_HELPID)
4534 lpmi->dwContextHelpID = menu->dwContextHelpID;
4535
4536 if (lpmi->fMask & MIM_MAXHEIGHT)
4537 lpmi->cyMax = menu->cyMax;
4538
4539 if (lpmi->fMask & MIM_MENUDATA)
4540 lpmi->dwMenuData = menu->dwMenuData;
4541
4542 if (lpmi->fMask & MIM_STYLE)
4543 lpmi->dwStyle = menu->dwStyle;
4544
4545 return TRUE;
4546 }
4547 return FALSE;
4548}
4549
4550/**********************************************************************
Paul Quinn1beaae51998-12-15 15:38:36 +00004551 * SetMenuContextHelpId16 (USER.384)
4552 */
Juergen Schmied78513941999-04-18 14:40:32 +00004553BOOL16 WINAPI SetMenuContextHelpId16( HMENU16 hMenu, DWORD dwContextHelpID)
Paul Quinn1beaae51998-12-15 15:38:36 +00004554{
Juergen Schmied78513941999-04-18 14:40:32 +00004555 return SetMenuContextHelpId( hMenu, dwContextHelpID );
Paul Quinn1beaae51998-12-15 15:38:36 +00004556}
4557
4558
4559/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004560 * SetMenuContextHelpId (USER32.488)
Paul Quinn1beaae51998-12-15 15:38:36 +00004561 */
Juergen Schmied78513941999-04-18 14:40:32 +00004562BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
Paul Quinn1beaae51998-12-15 15:38:36 +00004563{
Juergen Schmied78513941999-04-18 14:40:32 +00004564 LPPOPUPMENU menu;
4565
4566 TRACE(menu,"(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
4567
4568 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4569 {
4570 menu->dwContextHelpID = dwContextHelpID;
4571 return TRUE;
4572 }
4573 return FALSE;
Paul Quinn1beaae51998-12-15 15:38:36 +00004574}
4575
4576/**********************************************************************
4577 * GetMenuContextHelpId16 (USER.385)
4578 */
4579DWORD WINAPI GetMenuContextHelpId16( HMENU16 hMenu )
4580{
Juergen Schmied78513941999-04-18 14:40:32 +00004581 return GetMenuContextHelpId( hMenu );
Paul Quinn1beaae51998-12-15 15:38:36 +00004582}
4583
4584/**********************************************************************
Juergen Schmied78513941999-04-18 14:40:32 +00004585 * GetMenuContextHelpId (USER32.488)
Paul Quinn1beaae51998-12-15 15:38:36 +00004586 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00004587DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
Paul Quinn1beaae51998-12-15 15:38:36 +00004588{
Juergen Schmied78513941999-04-18 14:40:32 +00004589 LPPOPUPMENU menu;
4590
4591 TRACE(menu,"(0x%04x)\n", hMenu);
4592
4593 if ((menu = (POPUPMENU *) USER_HEAP_LIN_ADDR(hMenu)))
4594 {
4595 return menu->dwContextHelpID;
4596 }
4597 return 0;
Paul Quinn1beaae51998-12-15 15:38:36 +00004598}