source: trunk/src/user32/new/menu.cpp@ 2458

Last change on this file since 2458 was 2458, checked in by cbratschi, 26 years ago

menu and frame changes

File size: 134.8 KB
Line 
1/* $Id: menu.cpp,v 1.11 2000-01-16 18:17:10 cbratschi Exp $*/
2/*
3 * Menu functions
4 *
5 * Copyright 1993 Martin Ayotte
6 * Copyright 1994 Alexandre Julliard
7 * Copyright 1997 Morten Welinder
8 *
9 * Copyright 1999 Christoph Bratschi
10 *
11 * WINE version: 991212
12 *
13 * Status: ???
14 * Version: ???
15 */
16
17/*
18 * Note: the style MF_MOUSESELECT is used to mark popup items that
19 * have been selected, i.e. their popup menu is currently displayed.
20 * This is probably not the meaning this style has in MS-Windows.
21 */
22
23#include <assert.h>
24#include <ctype.h>
25#include <stdlib.h>
26#include <string.h>
27#include <os2win.h>
28#include <heapstring.h>
29#include "controls.h"
30#include "menu.h"
31
32//DEFAULT_DEBUG_CHANNEL(menu)
33
34
35/* internal popup menu window messages */
36
37#define MM_SETMENUHANDLE (WM_USER + 0)
38#define MM_GETMENUHANDLE (WM_USER + 1)
39
40/* Menu item structure */
41typedef struct {
42 /* ----------- MENUITEMINFO Stuff ----------- */
43 UINT fType; /* Item type. */
44 UINT fState; /* Item state. */
45 UINT wID; /* Item id. */
46 HMENU hSubMenu; /* Pop-up menu. */
47 HBITMAP hCheckBit; /* Bitmap when checked. */
48 HBITMAP hUnCheckBit; /* Bitmap when unchecked. */
49 LPSTR text; /* Item text or bitmap handle. */
50 DWORD dwItemData; /* Application defined. */
51 DWORD dwTypeData; /* depends on fMask */
52 HBITMAP hbmpItem; /* bitmap in win98 style menus */
53 /* ----------- Wine stuff ----------- */
54 RECT rect; /* Item area (relative to menu window) */
55 UINT xTab; /* X position of text after Tab */
56} MENUITEM;
57
58/* Popup menu structure */
59typedef struct {
60 WORD wFlags; /* Menu flags (MF_POPUP, MF_SYSMENU) */
61 WORD wMagic; /* Magic number */
62 HQUEUE hTaskQ; /* Task queue for this menu */
63 WORD Width; /* Width of the whole menu */
64 WORD Height; /* Height of the whole menu */
65 WORD nItems; /* Number of items in the menu */
66 HWND hWnd; /* Window containing the menu */
67 MENUITEM *items; /* Array of menu items */
68 UINT FocusedItem; /* Currently focused item */
69 HWND hwndOwner; /* window receiving the messages for ownerdraw */
70 BOOL bTimeToHide; /* Request hiding when receiving a second click in the top-level menu item */
71 /* ------------ MENUINFO members ------ */
72 DWORD dwStyle; /* Extended mennu style */
73 UINT cyMax; /* max hight of the whole menu, 0 is screen hight */
74 HBRUSH hbrBack; /* brush for menu background */
75 DWORD dwContextHelpID;
76 DWORD dwMenuData; /* application defined value */
77 HMENU hSysMenuOwner; /* Handle to the dummy sys menu holder */
78} POPUPMENU, *LPPOPUPMENU;
79
80/* internal flags for menu tracking */
81
82#define TF_ENDMENU 0x0001
83#define TF_SUSPENDPOPUP 0x0002
84#define TF_SKIPREMOVE 0x0004
85
86typedef struct
87{
88 UINT trackFlags;
89 HMENU hCurrentMenu; /* current submenu (can be equal to hTopMenu)*/
90 HMENU hTopMenu; /* initial menu */
91 HWND hOwnerWnd; /* where notifications are sent */
92 POINT pt;
93} MTRACKER;
94
95#define MENU_MAGIC 0x554d /* 'MU' */
96#define IS_A_MENU(pmenu) ((pmenu) && (pmenu)->wMagic == MENU_MAGIC)
97
98#define ITEM_PREV -1
99#define ITEM_NEXT 1
100
101 /* Internal MENU_TrackMenu() flags */
102#define TPM_INTERNAL 0xF0000000
103#define TPM_ENTERIDLEEX 0x80000000 /* set owner window for WM_ENTERIDLE */
104#define TPM_BUTTONDOWN 0x40000000 /* menu was clicked before tracking */
105#define TPM_POPUPMENU 0x20000000 /* menu is a popup menu */
106#define TPM_CAPTIONSYSMENU 0x10000000
107
108 /* popup menu shade thickness */
109#define POPUP_XSHADE 4
110#define POPUP_YSHADE 4
111
112 /* Space between 2 menu bar items */
113#define MENU_BAR_ITEMS_SPACE 12
114
115 /* Minimum width of a tab character */
116#define MENU_TAB_SPACE 8
117
118 /* Height of a separator item */
119#define SEPARATOR_HEIGHT 5
120
121 /* (other menu->FocusedItem values give the position of the focused item) */
122#define NO_SELECTED_ITEM 0xffff
123
124#define MENU_ITEM_TYPE(flags) \
125 ((flags) & (MF_STRING | MF_BITMAP | MF_OWNERDRAW | MF_SEPARATOR))
126
127#define IS_STRING_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_STRING)
128#define IS_BITMAP_ITEM(flags) (MENU_ITEM_TYPE ((flags)) == MF_BITMAP)
129
130#define IS_SYSTEM_MENU(menu) \
131 (!((menu)->wFlags & MF_POPUP) && (menu)->wFlags & MF_SYSMENU)
132
133#define IS_SYSTEM_POPUP(menu) \
134 ((menu)->wFlags & MF_POPUP && (menu)->wFlags & MF_SYSMENU)
135
136#define TYPE_MASK (MFT_STRING | MFT_BITMAP | MFT_OWNERDRAW | MFT_SEPARATOR | \
137 MFT_MENUBARBREAK | MFT_MENUBREAK | MFT_RADIOCHECK | \
138 MFT_RIGHTORDER | MFT_RIGHTJUSTIFY | \
139 MF_POPUP | MF_SYSMENU | MF_HELP)
140#define STATE_MASK (~TYPE_MASK)
141
142 /* Dimension of the menu bitmaps */
143static WORD check_bitmap_width = 0, check_bitmap_height = 0;
144static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0;
145
146static HBITMAP hStdRadioCheck = 0;
147static HBITMAP hStdCheck = 0;
148static HBITMAP hStdMnArrow = 0;
149
150/* Minimze/restore/close buttons to be inserted in menubar */
151static HBITMAP hBmpMinimize = 0;
152static HBITMAP hBmpMinimizeD = 0;
153static HBITMAP hBmpMaximize = 0;
154static HBITMAP hBmpMaximizeD = 0;
155static HBITMAP hBmpClose = 0;
156static HBITMAP hBmpCloseD = 0;
157
158
159static HBRUSH hShadeBrush = 0;
160static HFONT hMenuFont = 0;
161static HFONT hMenuFontBold = 0;
162
163static HMENU MENU_DefSysPopup = 0; /* Default system menu popup */
164
165/* Use global popup window because there's no way 2 menus can
166 * be tracked at the same time. */
167
168static HWND pTopPopupWnd = 0;
169static UINT uSubPWndLevel = 0;
170
171 /* Flag set by EndMenu() to force an exit from menu tracking */
172static BOOL fEndMenu = FALSE;
173
174
175/***********************************************************************
176 * debug_print_menuitem
177 *
178 * Print a menuitem in readable form.
179 */
180
181#define debug_print_menuitem(pre, mp, post) \
182 if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post)
183
184#define MENUOUT(text) \
185 DPRINTF("%s%s", (count++ ? "," : ""), (text))
186
187#define MENUFLAG(bit,text) \
188 do { \
189 if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \
190 } while (0)
191
192#if 0
193static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp,
194 const char *postfix)
195{
196 TRACE("%s ", prefix);
197 if (mp) {
198 UINT flags = mp->fType;
199 int typ = MENU_ITEM_TYPE(flags);
200 DPRINTF( "{ ID=0x%x", mp->wID);
201 if (flags & MF_POPUP)
202 DPRINTF( ", Sub=0x%x", mp->hSubMenu);
203 if (flags) {
204 int count = 0;
205 DPRINTF( ", Typ=");
206 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"); /* same as MF_HELP */
225
226 if (flags)
227 DPRINTF( "+0x%x", flags);
228 }
229 flags = mp->fState;
230 if (flags) {
231 int count = 0;
232 DPRINTF( ", State=");
233 MENUFLAG(MFS_GRAYED, "grey");
234 MENUFLAG(MFS_DEFAULT, "default");
235 MENUFLAG(MFS_DISABLED, "dis");
236 MENUFLAG(MFS_CHECKED, "check");
237 MENUFLAG(MFS_HILITE, "hi");
238 MENUFLAG(MF_USECHECKBITMAPS, "usebit");
239 MENUFLAG(MF_MOUSESELECT, "mouse");
240 if (flags)
241 DPRINTF( "+0x%x", flags);
242 }
243 if (mp->hCheckBit)
244 DPRINTF( ", Chk=0x%x", mp->hCheckBit);
245 if (mp->hUnCheckBit)
246 DPRINTF( ", Unc=0x%x", mp->hUnCheckBit);
247
248 if (typ == MFT_STRING) {
249 if (mp->text)
250 DPRINTF( ", Text=\"%s\"", mp->text);
251 else
252 DPRINTF( ", Text=Null");
253 } else if (mp->text == NULL)
254 /* Nothing */ ;
255 else
256 DPRINTF( ", Text=%p", mp->text);
257 if (mp->dwItemData)
258 DPRINTF( ", ItemData=0x%08lx", mp->dwItemData);
259 DPRINTF( " }");
260 } else {
261 DPRINTF( "NULL");
262 }
263
264 DPRINTF(" %s\n", postfix);
265}
266#endif
267
268#undef MENUOUT
269#undef MENUFLAG
270
271//#define USER_HEAP_ALLOC(size) HeapAlloc(GetProcessHeap(),0,size)
272//#define USER_HEAP_FREE(handle) HeapFree(GetProcessHeap(),0,(LPVOID)handle)
273
274HMENU getMenu(HWND hwnd)
275{
276 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
277
278 return win32wnd ? win32wnd->GetMenu():(HMENU)0;
279}
280
281VOID setMenu(HWND hwnd,HMENU hMenu)
282{
283 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
284
285 if (win32wnd) win32wnd->SetMenu(hMenu);
286}
287
288HMENU getSysMenu(HWND hwnd)
289{
290 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
291
292 return win32wnd ? win32wnd->GetSysMenu():(HMENU)0;
293}
294
295VOID setSysMenu(HWND hwnd,HMENU hMenu)
296{
297 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
298
299 win32wnd->SetSysMenu(hMenu);
300}
301
302/***********************************************************************
303 * MENU_CopySysPopup
304 *
305 * Return the default system menu.
306 */
307static HMENU MENU_CopySysPopup(void)
308{
309 HMENU hMenu = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU");
310
311 if( hMenu ) {
312 POPUPMENU* menu = (POPUPMENU*)hMenu;
313 menu->wFlags |= MF_SYSMENU | MF_POPUP;
314 SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE);
315 }
316 else {
317 hMenu = 0;
318 //ERR("Unable to load default system menu\n" );
319 }
320
321 //TRACE("returning %x.\n", hMenu );
322
323 return hMenu;
324}
325
326/***********************************************************************
327 * MENU_GetTopPopupWnd()
328 *
329 * Return the locked pointer pTopPopupWnd.
330 */
331static HWND MENU_GetTopPopupWnd()
332{
333 return pTopPopupWnd;
334}
335/***********************************************************************
336 * MENU_ReleaseTopPopupWnd()
337 *
338 * Realease the locked pointer pTopPopupWnd.
339 */
340static void MENU_ReleaseTopPopupWnd()
341{
342}
343/***********************************************************************
344 * MENU_DestroyTopPopupWnd()
345 *
346 * Destroy the locked pointer pTopPopupWnd.
347 */
348static void MENU_DestroyTopPopupWnd()
349{
350 pTopPopupWnd = NULL;
351}
352
353
354
355/**********************************************************************
356 * MENU_GetSysMenu
357 *
358 * Create a copy of the system menu. System menu in Windows is
359 * a special menu-bar with the single entry - system menu popup.
360 * This popup is presented to the outside world as a "system menu".
361 * However, the real system menu handle is sometimes seen in the
362 * WM_MENUSELECT paramemters (and Word 6 likes it this way).
363 */
364HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu )
365{
366 HMENU hMenu;
367
368 hMenu = CreateMenu();
369 if (hMenu)
370 {
371 POPUPMENU *menu = (POPUPMENU*)hMenu;
372 menu->wFlags = MF_SYSMENU;
373 menu->hWnd = hWnd;
374
375 if (hPopupMenu == (HMENU)(-1))
376 hPopupMenu = MENU_CopySysPopup();
377 else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup;
378
379 if (hPopupMenu)
380 {
381 InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, hPopupMenu, NULL );
382
383 menu->items[0].fType = MF_SYSMENU | MF_POPUP;
384 menu->items[0].fState = 0;
385 menu = (POPUPMENU*)hPopupMenu;
386 menu->wFlags |= MF_SYSMENU;
387
388 //TRACE("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu );
389 return hMenu;
390 }
391 DestroyMenu( hMenu );
392 }
393 //ERR("failed to load system menu!\n");
394 return 0;
395}
396
397
398/***********************************************************************
399 * MENU_Init
400 *
401 * Menus initialisation.
402 */
403BOOL MENU_Init()
404{
405 HBITMAP hBitmap;
406 NONCLIENTMETRICSA ncm;
407
408 static unsigned char shade_bits[16] = { 0x55, 0, 0xAA, 0,
409 0x55, 0, 0xAA, 0,
410 0x55, 0, 0xAA, 0,
411 0x55, 0, 0xAA, 0 };
412
413 /* Load menu bitmaps */
414 hStdCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECK));
415 hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_RADIOCHECK));
416 hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_MNARROW));
417 /* Load system buttons bitmaps */
418 hBmpMinimize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCE));
419 hBmpMinimizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_REDUCED));
420 hBmpMaximize = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORE));
421 hBmpMaximizeD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_RESTORED));
422 hBmpClose = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSE));
423 hBmpCloseD = LoadBitmapA(0,MAKEINTRESOURCEA(OBM_CLOSED));
424
425 if (hStdCheck)
426 {
427 BITMAP bm;
428 GetObjectA( hStdCheck, sizeof(bm), &bm );
429 check_bitmap_width = bm.bmWidth;
430 check_bitmap_height = bm.bmHeight;
431 } else
432 return FALSE;
433
434 /* Assume that radio checks have the same size as regular check. */
435 if (!hStdRadioCheck)
436 return FALSE;
437
438 if (hStdMnArrow)
439 {
440 BITMAP bm;
441 GetObjectA( hStdMnArrow, sizeof(bm), &bm );
442 arrow_bitmap_width = bm.bmWidth;
443 arrow_bitmap_height = bm.bmHeight;
444 } else
445 return FALSE;
446
447 if (! (hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits)))
448 return FALSE;
449
450 if(!(hShadeBrush = CreatePatternBrush( hBitmap )))
451 return FALSE;
452
453 DeleteObject( hBitmap );
454 if (!(MENU_DefSysPopup = MENU_CopySysPopup()))
455 return FALSE;
456
457 ncm.cbSize = sizeof (NONCLIENTMETRICSA);
458 if (!(SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSA), &ncm, 0)))
459 return FALSE;
460
461 if (!(hMenuFont = CreateFontIndirectA( &ncm.lfMenuFont )))
462 return FALSE;
463
464 ncm.lfMenuFont.lfWeight += 300;
465 if ( ncm.lfMenuFont.lfWeight > 1000)
466 ncm.lfMenuFont.lfWeight = 1000;
467
468 if (!(hMenuFontBold = CreateFontIndirectA( &ncm.lfMenuFont )))
469 return FALSE;
470
471 return TRUE;
472}
473
474/***********************************************************************
475 * MENU_InitSysMenuPopup
476 *
477 * Grey the appropriate items in System menu.
478 */
479static void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle )
480{
481 BOOL gray;
482
483 gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE));
484 EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) );
485 gray = ((style & WS_MAXIMIZE) != 0);
486 EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) );
487 gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE);
488 EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
489 gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE);
490 EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) );
491 gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE));
492 EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) );
493 gray = (clsStyle & CS_NOCLOSE) != 0;
494
495 /* The menu item must keep its state if it's disabled */
496 if(gray)
497 EnableMenuItem( hmenu, SC_CLOSE, MF_GRAYED);
498}
499
500
501/******************************************************************************
502 *
503 * UINT32 MENU_GetStartOfNextColumn(
504 * HMENU32 hMenu )
505 *
506 *****************************************************************************/
507
508static UINT MENU_GetStartOfNextColumn(
509 HMENU hMenu )
510{
511 POPUPMENU *menu = (POPUPMENU*)hMenu;
512 UINT i = menu->FocusedItem + 1;
513
514 if(!menu)
515 return NO_SELECTED_ITEM;
516
517 if( i == NO_SELECTED_ITEM )
518 return i;
519
520 for( ; i < menu->nItems; ++i ) {
521 if (menu->items[i].fType & MF_MENUBARBREAK)
522 return i;
523 }
524
525 return NO_SELECTED_ITEM;
526}
527
528
529/******************************************************************************
530 *
531 * UINT32 MENU_GetStartOfPrevColumn(
532 * HMENU32 hMenu )
533 *
534 *****************************************************************************/
535
536static UINT MENU_GetStartOfPrevColumn(
537 HMENU hMenu )
538{
539 POPUPMENU const *menu = (POPUPMENU*)hMenu;
540 UINT i;
541
542 if( !menu )
543 return NO_SELECTED_ITEM;
544
545 if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM )
546 return NO_SELECTED_ITEM;
547
548 /* Find the start of the column */
549
550 for(i = menu->FocusedItem; i != 0 &&
551 !(menu->items[i].fType & MF_MENUBARBREAK);
552 --i); /* empty */
553
554 if(i == 0)
555 return NO_SELECTED_ITEM;
556
557 for(--i; i != 0; --i) {
558 if (menu->items[i].fType & MF_MENUBARBREAK)
559 break;
560 }
561
562 //TRACE("ret %d.\n", i );
563
564 return i;
565}
566
567
568
569/***********************************************************************
570 * MENU_FindItem
571 *
572 * Find a menu item. Return a pointer on the item, and modifies *hmenu
573 * in case the item was in a sub-menu.
574 */
575static MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags )
576{
577 POPUPMENU *menu;
578 UINT i;
579
580 if (((*hmenu)==0xffff) || (!(menu = (POPUPMENU*)*hmenu))) return NULL;
581 if (wFlags & MF_BYPOSITION)
582 {
583 if (*nPos >= menu->nItems) return NULL;
584 return &menu->items[*nPos];
585 }
586 else
587 {
588 MENUITEM *item = menu->items;
589
590 for (i = 0; i < menu->nItems; i++, item++)
591 {
592 if (item->wID == *nPos)
593 {
594 *nPos = i;
595 return item;
596 }
597 else if (item->fType & MF_POPUP)
598 {
599 HMENU hsubmenu = item->hSubMenu;
600 MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags );
601 if (subitem)
602 {
603 *hmenu = hsubmenu;
604 return subitem;
605 }
606 }
607 }
608 }
609 return NULL;
610}
611
612/***********************************************************************
613 * MENU_FindSubMenu
614 *
615 * Find a Sub menu. Return the position of the submenu, and modifies
616 * *hmenu in case it is found in another sub-menu.
617 * If the submenu cannot be found, NO_SELECTED_ITEM is returned.
618 */
619UINT MENU_FindSubMenu( HMENU *hmenu, HMENU hSubTarget )
620{
621 POPUPMENU *menu;
622 UINT i;
623 MENUITEM *item;
624 if (((*hmenu)==0xffff) ||
625 (!(menu = (POPUPMENU*)*hmenu)))
626 return NO_SELECTED_ITEM;
627 item = menu->items;
628 for (i = 0; i < menu->nItems; i++, item++) {
629 if(!(item->fType & MF_POPUP)) continue;
630 if (item->hSubMenu == hSubTarget) {
631 return i;
632 }
633 else {
634 HMENU hsubmenu = item->hSubMenu;
635 UINT pos = MENU_FindSubMenu( &hsubmenu, hSubTarget );
636 if (pos != NO_SELECTED_ITEM) {
637 *hmenu = hsubmenu;
638 return pos;
639 }
640 }
641 }
642 return NO_SELECTED_ITEM;
643}
644
645/***********************************************************************
646 * MENU_FreeItemData
647 */
648static void MENU_FreeItemData( MENUITEM* item )
649{
650 /* delete text */
651 if (IS_STRING_ITEM(item->fType) && item->text)
652 HeapFree(GetProcessHeap(), 0, item->text );
653}
654
655/***********************************************************************
656 * MENU_FindItemByCoords
657 *
658 * Find the item at the specified coordinates (screen coords). Does
659 * not work for child windows and therefore should not be called for
660 * an arbitrary system menu.
661 */
662static MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu,
663 POINT pt, UINT *pos )
664{
665 MENUITEM *item;
666 UINT i;
667 RECT wrect;
668
669 if (!GetWindowRect(menu->hWnd,&wrect)) return NULL;
670 pt.x -= wrect.left;pt.y -= wrect.top;
671 item = menu->items;
672 for (i = 0; i < menu->nItems; i++, item++)
673 {
674 if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) &&
675 (pt.y >= item->rect.top) && (pt.y < item->rect.bottom))
676 {
677 if (pos) *pos = i;
678 return item;
679 }
680 }
681 return NULL;
682}
683
684
685/***********************************************************************
686 * MENU_FindItemByKey
687 *
688 * Find the menu item selected by a key press.
689 * Return item id, -1 if none, -2 if we should close the menu.
690 */
691static UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu,
692 UINT key, BOOL forceMenuChar )
693{
694 //TRACE("\tlooking for '%c' in [%04x]\n", (char)key, (UINT16)hmenu );
695
696 if (!IsMenu( hmenu ))
697 {
698 hmenu = GetSubMenu(getSysMenu(hwndOwner), 0);
699 }
700
701 if (hmenu)
702 {
703 POPUPMENU *menu = (POPUPMENU*)hmenu;
704 MENUITEM *item = menu->items;
705 LONG menuchar;
706
707 if( !forceMenuChar )
708 {
709 UINT i;
710
711 key = toupper(key);
712 for (i = 0; i < menu->nItems; i++, item++)
713 {
714 if (item->text && (IS_STRING_ITEM(item->fType)))
715 {
716 char *p = item->text - 2;
717 do
718 {
719 p = strchr (p + 2, '&');
720 }
721 while (p != NULL && p [1] == '&');
722 if (p && (toupper(p[1]) == key)) return i;
723 }
724 }
725 }
726 menuchar = SendMessageA( hwndOwner, WM_MENUCHAR,
727 MAKEWPARAM( key, menu->wFlags ), hmenu );
728 if (HIWORD(menuchar) == 2) return LOWORD(menuchar);
729 if (HIWORD(menuchar) == 1) return (UINT)(-2);
730 }
731 return (UINT)(-1);
732}
733/***********************************************************************
734 * MENU_LoadMagicItem
735 *
736 * Load the bitmap associated with the magic menu item and its style
737 */
738
739static HBITMAP MENU_LoadMagicItem(UINT id, BOOL hilite, DWORD dwItemData)
740{
741 /*
742 * Magic menu item id's section
743 * These magic id's are used by windows to insert "standard" mdi
744 * buttons (minimize,restore,close) on menu. Under windows,
745 * these magic id's make sure the right things appear when those
746 * bitmap buttons are pressed/selected/released.
747 */
748
749 switch(id & 0xffff)
750 { case HBMMENU_SYSTEM:
751 return (dwItemData) ?
752 (HBITMAP)dwItemData :
753 (hilite ? hBmpMinimizeD : hBmpMinimize);
754 case HBMMENU_MBAR_RESTORE:
755 return (hilite ? hBmpMaximizeD: hBmpMaximize);
756 case HBMMENU_MBAR_MINIMIZE:
757 return (hilite ? hBmpMinimizeD : hBmpMinimize);
758 case HBMMENU_MBAR_CLOSE:
759 return (hilite ? hBmpCloseD : hBmpClose);
760 case HBMMENU_CALLBACK:
761 case HBMMENU_MBAR_CLOSE_D:
762 case HBMMENU_MBAR_MINIMIZE_D:
763 case HBMMENU_POPUP_CLOSE:
764 case HBMMENU_POPUP_RESTORE:
765 case HBMMENU_POPUP_MAXIMIZE:
766 case HBMMENU_POPUP_MINIMIZE:
767 default:
768 //FIXME("Magic 0x%08x not implemented\n", id);
769 return 0;
770 }
771
772}
773
774/***********************************************************************
775 * MENU_CalcItemSize
776 *
777 * Calculate the size of the menu item and store it in lpitem->rect.
778 */
779static void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner,
780 INT orgX, INT orgY, BOOL menuBar )
781{
782 char *p;
783
784 //TRACE("dc=0x%04x owner=0x%04x (%d,%d)\n", hdc, hwndOwner, orgX, orgY);
785 //debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem,
786 // (menuBar ? " (MenuBar)" : ""));
787
788 SetRect( &lpitem->rect, orgX, orgY, orgX, orgY );
789
790 if (lpitem->fType & MF_OWNERDRAW)
791 {
792 MEASUREITEMSTRUCT mis;
793 mis.CtlType = ODT_MENU;
794 mis.CtlID = 0;
795 mis.itemID = lpitem->wID;
796 mis.itemData = (DWORD)lpitem->dwItemData;
797 mis.itemHeight = 0;
798 mis.itemWidth = 0;
799 SendMessageA( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis );
800 lpitem->rect.bottom += mis.itemHeight;
801 lpitem->rect.right += mis.itemWidth;
802 //TRACE("id=%04x size=%dx%d\n",
803 // lpitem->wID, mis.itemWidth, mis.itemHeight);
804 return;
805 }
806
807 if (lpitem->fType & MF_SEPARATOR)
808 {
809 lpitem->rect.bottom += SEPARATOR_HEIGHT;
810 return;
811 }
812
813 if (!menuBar)
814 {
815 lpitem->rect.right += 2 * check_bitmap_width;
816 if (lpitem->fType & MF_POPUP)
817 lpitem->rect.right += arrow_bitmap_width;
818 }
819
820 if (IS_BITMAP_ITEM(lpitem->fType))
821 {
822 BITMAP bm;
823 HBITMAP resBmp = 0;
824
825 /* Check if there is a magic menu item associated with this item */
826 if((LOWORD((int)lpitem->text))<12)
827 {
828 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fType & MF_HILITE),
829 lpitem->dwItemData);
830 }
831 else
832 resBmp = (HBITMAP)lpitem->text;
833
834 if (GetObjectA(resBmp, sizeof(bm), &bm ))
835 {
836 lpitem->rect.right += bm.bmWidth;
837 lpitem->rect.bottom += bm.bmHeight;
838
839 }
840 }
841
842
843 /* If we get here, then it must be a text item */
844 if (IS_STRING_ITEM( lpitem->fType ))
845 { SIZE size;
846
847 GetTextExtentPoint32A(hdc, lpitem->text, strlen(lpitem->text), &size);
848
849 lpitem->rect.right += size.cx;
850 lpitem->rect.bottom += MAX (size.cy, GetSystemMetrics(SM_CYMENU)-1);
851 lpitem->xTab = 0;
852
853 if (menuBar)
854 {
855 lpitem->rect.right += MENU_BAR_ITEMS_SPACE;
856 }
857 else if ((p = strchr( lpitem->text, '\t' )) != NULL)
858 {
859 /* Item contains a tab (only meaningful in popup menus) */
860 GetTextExtentPoint32A(hdc, lpitem->text, (int)(p - lpitem->text) , &size);
861 lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE + size.cx;
862 lpitem->rect.right += MENU_TAB_SPACE;
863 }
864 else
865 {
866 if (strchr( lpitem->text, '\b' ))
867 lpitem->rect.right += MENU_TAB_SPACE;
868 lpitem->xTab = lpitem->rect.right - check_bitmap_width
869 - arrow_bitmap_width;
870 }
871 }
872 //TRACE("(%d,%d)-(%d,%d)\n", lpitem->rect.left, lpitem->rect.top, lpitem->rect.right, lpitem->rect.bottom);
873}
874
875
876/***********************************************************************
877 * MENU_PopupMenuCalcSize
878 *
879 * Calculate the size of a popup menu.
880 */
881static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner )
882{
883 MENUITEM *lpitem;
884 HDC hdc;
885 int start, i;
886 int orgX, orgY, maxX, maxTab, maxTabWidth;
887
888 lppop->Width = lppop->Height = 0;
889 if (lppop->nItems == 0) return;
890 hdc = GetDC( 0 );
891
892 SelectObject( hdc, hMenuFont);
893
894 start = 0;
895 maxX = 2 ;
896
897 while (start < lppop->nItems)
898 {
899 lpitem = &lppop->items[start];
900 orgX = maxX;
901 orgY = 2;
902
903 maxTab = maxTabWidth = 0;
904
905 /* Parse items until column break or end of menu */
906 for (i = start; i < lppop->nItems; i++, lpitem++)
907 {
908 if ((i != start) &&
909 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
910
911 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE );
912
913 if (lpitem->fType & MF_MENUBARBREAK) orgX++;
914 maxX = MAX( maxX, lpitem->rect.right );
915 orgY = lpitem->rect.bottom;
916 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
917 {
918 maxTab = MAX( maxTab, lpitem->xTab );
919 maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab);
920 }
921 }
922
923 /* Finish the column (set all items to the largest width found) */
924 maxX = MAX( maxX, maxTab + maxTabWidth );
925 for (lpitem = &lppop->items[start]; start < i; start++, lpitem++)
926 {
927 lpitem->rect.right = maxX;
928 if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab)
929 lpitem->xTab = maxTab;
930
931 }
932 lppop->Height = MAX( lppop->Height, orgY );
933 }
934
935 lppop->Width = maxX;
936
937 /* space for 3d border */
938 lppop->Height += 2;
939 lppop->Width += 2;
940
941 ReleaseDC( 0, hdc );
942}
943
944
945/***********************************************************************
946 * MENU_MenuBarCalcSize
947 *
948 * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap
949 * height is off by 1 pixel which causes lengthy window relocations when
950 * active document window is maximized/restored.
951 *
952 * Calculate the size of the menu bar.
953 */
954static void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect,
955 LPPOPUPMENU lppop, HWND hwndOwner )
956{
957 MENUITEM *lpitem;
958 int start, i, orgX, orgY, maxY, helpPos;
959
960 if ((lprect == NULL) || (lppop == NULL)) return;
961 if (lppop->nItems == 0) return;
962 //TRACE("left=%d top=%d right=%d bottom=%d\n",
963 // lprect->left, lprect->top, lprect->right, lprect->bottom);
964 lppop->Width = lprect->right - lprect->left;
965 lppop->Height = 0;
966 maxY = lprect->top;
967 start = 0;
968 helpPos = -1;
969 while (start < lppop->nItems)
970 {
971 lpitem = &lppop->items[start];
972 orgX = lprect->left;
973 orgY = maxY;
974
975 /* Parse items until line break or end of menu */
976 for (i = start; i < lppop->nItems; i++, lpitem++)
977 {
978 if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i;
979 if ((i != start) &&
980 (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break;
981
982 //TRACE("calling MENU_CalcItemSize org=(%d, %d)\n",
983 // orgX, orgY );
984 //debug_print_menuitem (" item: ", lpitem, "");
985 MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE );
986
987 if (lpitem->rect.right > lprect->right)
988 {
989 if (i != start) break;
990 else lpitem->rect.right = lprect->right;
991 }
992 maxY = MAX( maxY, lpitem->rect.bottom );
993 orgX = lpitem->rect.right;
994 }
995
996 /* Finish the line (set all items to the largest height found) */
997 while (start < i) lppop->items[start++].rect.bottom = maxY;
998 }
999
1000 lprect->bottom = maxY;
1001 lppop->Height = lprect->bottom - lprect->top;
1002
1003 /* Flush right all magic items and items between the MF_HELP and */
1004 /* the last item (if several lines, only move the last line) */
1005 lpitem = &lppop->items[lppop->nItems-1];
1006 orgY = lpitem->rect.top;
1007 orgX = lprect->right;
1008 for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--)
1009 {
1010 if ( !IS_BITMAP_ITEM(lpitem->fType) && ((helpPos ==-1) ? TRUE : (helpPos>i) ))
1011 break; /* done */
1012 if (lpitem->rect.top != orgY) break; /* Other line */
1013 if (lpitem->rect.right >= orgX) break; /* Too far right already */
1014 lpitem->rect.left += orgX - lpitem->rect.right;
1015 lpitem->rect.right = orgX;
1016 orgX = lpitem->rect.left;
1017 }
1018}
1019
1020/***********************************************************************
1021 * MENU_DrawMenuItem
1022 *
1023 * Draw a single menu item.
1024 */
1025static void MENU_DrawMenuItem( HWND hwnd, HMENU hmenu, HWND hwndOwner, HDC hdc, MENUITEM *lpitem,
1026 UINT height, BOOL menuBar, UINT odaction )
1027{
1028 RECT rect;
1029
1030 //debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, "");
1031
1032 if (lpitem->fType & MF_SYSMENU) return;
1033
1034 if (lpitem->fType & MF_OWNERDRAW)
1035 {
1036 DRAWITEMSTRUCT dis;
1037
1038 dis.CtlType = ODT_MENU;
1039 dis.CtlID = 0;
1040 dis.itemID = lpitem->wID;
1041 dis.itemData = (DWORD)lpitem->dwItemData;
1042 dis.itemState = 0;
1043 if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED;
1044 if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED;
1045 if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED;
1046 dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */
1047 dis.hwndItem = hmenu;
1048 dis.hDC = hdc;
1049 dis.rcItem = lpitem->rect;
1050 //TRACE("Ownerdraw: owner=%04x itemID=%d, itemState=%d, itemAction=%d, "
1051 // "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n", hwndOwner,
1052 // dis.itemID, dis.itemState, dis.itemAction, dis.hwndItem,
1053 // dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right,
1054 // dis.rcItem.bottom);
1055 SendMessageA( hwndOwner, WM_DRAWITEM, 0, (LPARAM)&dis );
1056 return;
1057 }
1058
1059 //TRACE("rect={%d,%d,%d,%d}\n", lpitem->rect.left, lpitem->rect.top,
1060 // lpitem->rect.right,lpitem->rect.bottom);
1061
1062 if (menuBar && (lpitem->fType & MF_SEPARATOR)) return;
1063
1064 rect = lpitem->rect;
1065
1066 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)))
1067 FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) );
1068 else {
1069 //SvL: TODO: Bug in GDI32; draws black rectangle instead of menu color
1070 /// for everything except the 1st menu item
1071 RECT dummy = rect;
1072 dummy.bottom = dummy.top+1;
1073 dummy.right = dummy.right+1;
1074 FillRect( hdc, &dummy, GetSysColorBrush(COLOR_HIGHLIGHT) );
1075 FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) );
1076 }
1077
1078 SetBkMode( hdc, TRANSPARENT );
1079
1080 /* vertical separator */
1081 if (!menuBar && (lpitem->fType & MF_MENUBARBREAK))
1082 {
1083 RECT rc = rect;
1084 rc.top = 3;
1085 rc.bottom = height - 3;
1086 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT);
1087 }
1088
1089 /* horizontal separator */
1090 if (lpitem->fType & MF_SEPARATOR)
1091 {
1092 RECT rc = rect;
1093 rc.left++;
1094 rc.right--;
1095 rc.top += SEPARATOR_HEIGHT / 2;
1096 DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP);
1097 return;
1098 }
1099
1100 /* Setup colors */
1101
1102 if ((lpitem->fState & MF_HILITE) && !(IS_BITMAP_ITEM(lpitem->fType)) )
1103 {
1104 if (lpitem->fState & MF_GRAYED)
1105 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
1106 else
1107 SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
1108 SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) );
1109 }
1110 else
1111 {
1112 if (lpitem->fState & MF_GRAYED)
1113 SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
1114 else
1115 SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) );
1116 SetBkColor( hdc, GetSysColor( COLOR_MENU ) );
1117 }
1118
1119 /* helper lines for debugging */
1120/* FrameRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
1121 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1122 MoveTo( hdc, rect.left, (rect.top + rect.bottom)/2,NULL);
1123 LineTo( hdc, rect.right, (rect.top + rect.bottom)/2 );
1124*/
1125
1126 if (!menuBar)
1127 {
1128 INT y = rect.top + rect.bottom;
1129
1130 /* Draw the check mark
1131 *
1132 * FIXME:
1133 * Custom checkmark bitmaps are monochrome but not always 1bpp.
1134 */
1135
1136 if (lpitem->fState & MF_CHECKED)
1137 {
1138 HBITMAP bm = lpitem->hCheckBit ? lpitem->hCheckBit :
1139 ((lpitem->fType & MFT_RADIOCHECK) ? hStdRadioCheck : hStdCheck);
1140 HDC hdcMem = CreateCompatibleDC( hdc );
1141
1142 SelectObject( hdcMem, bm );
1143 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
1144 check_bitmap_width, check_bitmap_height,
1145 hdcMem, 0, 0, SRCCOPY );
1146 DeleteDC( hdcMem );
1147 }
1148 else if (lpitem->hUnCheckBit)
1149 {
1150 HDC hdcMem = CreateCompatibleDC( hdc );
1151
1152 SelectObject( hdcMem, lpitem->hUnCheckBit );
1153 BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2,
1154 check_bitmap_width, check_bitmap_height,
1155 hdcMem, 0, 0, SRCCOPY );
1156 DeleteDC( hdcMem );
1157 }
1158
1159 /* Draw the popup-menu arrow */
1160 if (lpitem->fType & MF_POPUP)
1161 {
1162 HDC hdcMem = CreateCompatibleDC( hdc );
1163
1164 SelectObject( hdcMem, hStdMnArrow );
1165 BitBlt( hdc, rect.right - arrow_bitmap_width - 1,
1166 (y - arrow_bitmap_height) / 2,
1167 arrow_bitmap_width, arrow_bitmap_height,
1168 hdcMem, 0, 0, SRCCOPY );
1169 DeleteDC( hdcMem );
1170 }
1171
1172 rect.left += check_bitmap_width;
1173 rect.right -= arrow_bitmap_width;
1174 }
1175
1176 /* Draw the item text or bitmap */
1177 if (IS_BITMAP_ITEM(lpitem->fType))
1178 { int top;
1179
1180 HBITMAP resBmp = 0;
1181
1182 HDC hdcMem = CreateCompatibleDC( hdc );
1183
1184 /*
1185 * Check if there is a magic menu item associated with this item
1186 * and load the appropriate bitmap
1187 */
1188 if((LOWORD((int)lpitem->text)) < 12)
1189 {
1190 resBmp = MENU_LoadMagicItem((int)lpitem->text, (lpitem->fState & MF_HILITE),
1191 lpitem->dwItemData);
1192 }
1193 else
1194 resBmp = (HBITMAP)lpitem->text;
1195
1196 if (resBmp)
1197 {
1198 BITMAP bm;
1199 GetObjectA( resBmp, sizeof(bm), &bm );
1200
1201 SelectObject(hdcMem,resBmp );
1202
1203 /* handle fontsize > bitmap_height */
1204 top = ((rect.bottom-rect.top)>bm.bmHeight) ?
1205 rect.top+(rect.bottom-rect.top-bm.bmHeight)/2 : rect.top;
1206
1207 BitBlt( hdc, rect.left, top, rect.right - rect.left,
1208 rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY );
1209 }
1210 DeleteDC( hdcMem );
1211
1212 return;
1213
1214 }
1215 /* No bitmap - process text if present */
1216 else if (IS_STRING_ITEM(lpitem->fType))
1217 {
1218 register int i;
1219 HFONT hfontOld = 0;
1220
1221 UINT uFormat = (menuBar) ?
1222 DT_CENTER | DT_VCENTER | DT_SINGLELINE :
1223 DT_LEFT | DT_VCENTER | DT_SINGLELINE;
1224
1225 if ( lpitem->fState & MFS_DEFAULT )
1226 {
1227 hfontOld = SelectObject( hdc, hMenuFontBold);
1228 }
1229
1230 if (menuBar)
1231 {
1232 rect.left += MENU_BAR_ITEMS_SPACE / 2;
1233 rect.right -= MENU_BAR_ITEMS_SPACE / 2;
1234 i = strlen( lpitem->text );
1235 }
1236 else
1237 {
1238 for (i = 0; lpitem->text[i]; i++)
1239 if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b'))
1240 break;
1241 }
1242
1243 if(lpitem->fState & MF_GRAYED)
1244 {
1245 if (!(lpitem->fState & MF_HILITE) )
1246 {
1247 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
1248 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
1249 DrawTextA( hdc, lpitem->text, i, &rect, uFormat );
1250 --rect.left; --rect.top; --rect.right; --rect.bottom;
1251 }
1252 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
1253 }
1254
1255 DrawTextA( hdc, lpitem->text, i, &rect, uFormat);
1256
1257 /* paint the shortcut text */
1258 if (lpitem->text[i]) /* There's a tab or flush-right char */
1259 {
1260 if (lpitem->text[i] == '\t')
1261 {
1262 rect.left = lpitem->xTab;
1263 uFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
1264 }
1265 else
1266 {
1267 uFormat = DT_RIGHT | DT_VCENTER | DT_SINGLELINE;
1268 }
1269
1270 if(lpitem->fState & MF_GRAYED)
1271 {
1272 if (!(lpitem->fState & MF_HILITE) )
1273 {
1274 ++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
1275 SetTextColor(hdc, RGB(0xff, 0xff, 0xff));
1276 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
1277 --rect.left; --rect.top; --rect.right; --rect.bottom;
1278 }
1279 SetTextColor(hdc, RGB(0x80, 0x80, 0x80));
1280 }
1281 DrawTextA( hdc, lpitem->text + i + 1, -1, &rect, uFormat );
1282 }
1283
1284 if (hfontOld)
1285 SelectObject (hdc, hfontOld);
1286 }
1287}
1288
1289
1290/***********************************************************************
1291 * MENU_DrawPopupMenu
1292 *
1293 * Paint a popup menu.
1294 */
1295static void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu )
1296{
1297 HBRUSH hPrevBrush = 0;
1298 RECT rect;
1299
1300 //TRACE("wnd=0x%04x dc=0x%04x menu=0x%04x\n", hwnd, hdc, hmenu);
1301
1302 GetClientRect( hwnd, &rect );
1303
1304 if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))
1305 && (SelectObject( hdc, hMenuFont)))
1306 {
1307 HPEN hPrevPen;
1308
1309 Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
1310
1311 hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) );
1312 if( hPrevPen )
1313 {
1314 INT ropPrev, i;
1315 POPUPMENU *menu;
1316
1317 /* draw 3-d shade */
1318 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT);
1319
1320 /* draw menu items */
1321
1322 menu = (POPUPMENU*)hmenu;
1323 if (menu && menu->nItems)
1324 {
1325 MENUITEM *item;
1326 UINT u;
1327
1328 for (u = menu->nItems, item = menu->items; u > 0; u--, item++)
1329 MENU_DrawMenuItem( hwnd, hmenu, menu->hwndOwner, hdc, item,
1330 menu->Height, FALSE, ODA_DRAWENTIRE );
1331
1332 }
1333 } else
1334 {
1335 SelectObject( hdc, hPrevBrush );
1336 }
1337 }
1338}
1339
1340/***********************************************************************
1341 * MENU_DrawMenuBar
1342 *
1343 * Paint a menu bar. Returns the height of the menu bar.
1344 * called from [windows/nonclient.c]
1345 */
1346UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd,
1347 BOOL suppress_draw)
1348{
1349 LPPOPUPMENU lppop;
1350 UINT i,retvalue;
1351 HFONT hfontOld = 0;
1352
1353 lppop = (LPPOPUPMENU)getMenu(hwnd);
1354 if (lppop == NULL || lprect == NULL)
1355 {
1356 retvalue = GetSystemMetrics(SM_CYMENU);
1357 goto END;
1358 }
1359
1360 //TRACE("(%04x, %p, %p)\n", hDC, lprect, lppop);
1361
1362 hfontOld = SelectObject( hDC, hMenuFont);
1363
1364 if (lppop->Height == 0)
1365 MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd);
1366
1367 lprect->bottom = lprect->top + lppop->Height;
1368
1369 if (suppress_draw)
1370 {
1371 retvalue = lppop->Height;
1372 goto END;
1373 }
1374
1375 HDC memDC;
1376 HBITMAP memBmp,oldBmp;
1377 RECT r;
1378 HFONT oldMemFont;
1379
1380 memDC = CreateCompatibleDC(hDC);
1381 r = *lprect;
1382 r.right -= r.left;
1383 r.bottom -= r.top;
1384 r.left = r.top = 0;
1385 memBmp = CreateCompatibleBitmap(hDC,r.right,r.bottom+1);
1386 oldBmp = SelectObject(memDC,memBmp);
1387 oldMemFont = SelectObject(memDC,hMenuFont);
1388
1389 FillRect(memDC,&r,GetSysColorBrush(COLOR_MENU));
1390
1391 SelectObject(memDC,GetSysColorPen(COLOR_3DFACE));
1392 MoveToEx(memDC,r.left,r.bottom,NULL);
1393 LineTo(memDC,r.right,r.bottom);
1394
1395 if (lppop->nItems == 0)
1396 {
1397 retvalue = GetSystemMetrics(SM_CYMENU);
1398 } else
1399 {
1400 for (i = 0; i < lppop->nItems; i++)
1401 {
1402 OffsetRect(&lppop->items[i].rect,-lprect->left,-lprect->top);
1403 MENU_DrawMenuItem( hwnd,getMenu(hwnd), GetWindow(hwnd,GW_OWNER),
1404 memDC, &lppop->items[i], lppop->Height, TRUE, ODA_DRAWENTIRE );
1405 OffsetRect(&lppop->items[i].rect,lprect->left,lprect->top);
1406 }
1407 retvalue = lppop->Height;
1408 }
1409
1410 BitBlt(hDC,lprect->left,lprect->top,lprect->right-lprect->left,lprect->bottom-lprect->top+1,memDC,0,0,SRCCOPY);
1411 SelectObject(memDC,oldBmp);
1412 if (oldMemFont) SelectObject(memDC,oldMemFont);
1413 DeleteObject(memBmp);
1414 DeleteDC(memDC);
1415
1416END:
1417 if (hfontOld)
1418 SelectObject (hDC, hfontOld);
1419
1420 return retvalue;
1421}
1422
1423/***********************************************************************
1424 * MENU_PatchResidentPopup
1425 */
1426BOOL MENU_PatchResidentPopup( HQUEUE checkQueue, HWND checkWnd )
1427{
1428 HWND pTPWnd = MENU_GetTopPopupWnd();
1429#if 0 //CB: todo
1430 if( pTPWnd )
1431 {
1432 HTASK hTask = 0;
1433
1434 //TRACE("patching resident popup: %04x %04x [%04x %04x]\n",
1435 // checkQueue, checkWnd ? checkWnd->hwndSelf : 0, pTPWnd->hmemTaskQ,
1436 // pTPWnd->owner ? pTPWnd->owner->hwndSelf : 0);
1437
1438 switch( checkQueue )
1439 {
1440 case 0: /* checkWnd is the new popup owner */
1441 if( checkWnd )
1442 {
1443 pTPWnd->owner = checkWnd;
1444 if( pTPWnd->hmemTaskQ != checkWnd->hmemTaskQ )
1445 hTask = QUEUE_GetQueueTask( checkWnd->hmemTaskQ );
1446 }
1447 break;
1448
1449 case 0xFFFF: /* checkWnd is destroyed */
1450 if( pTPWnd->owner == checkWnd )
1451 pTPWnd->owner = NULL;
1452 MENU_ReleaseTopPopupWnd();
1453 return TRUE;
1454
1455 default: /* checkQueue is exiting */
1456 if( pTPWnd->hmemTaskQ == checkQueue )
1457 {
1458 hTask = QUEUE_GetQueueTask( pTPWnd->hmemTaskQ );
1459 hTask = TASK_GetNextTask( hTask );
1460 }
1461 break;
1462 }
1463
1464 if( hTask )
1465 {
1466 TDB* task = (TDB*)GlobalLock( hTask );
1467 if( task )
1468 {
1469 pTPWnd->hInstance = task->hInstance;
1470 pTPWnd->hmemTaskQ = task->hQueue;
1471 MENU_ReleaseTopPopupWnd();
1472 return TRUE;
1473 }
1474 //else WARN("failed to patch resident popup.\n");
1475 }
1476 }
1477#endif
1478 MENU_ReleaseTopPopupWnd();
1479 return FALSE;
1480}
1481
1482/***********************************************************************
1483 * MENU_ShowPopup
1484 *
1485 * Display a popup menu.
1486 */
1487static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id,
1488 INT x, INT y, INT xanchor, INT yanchor )
1489{
1490 POPUPMENU *menu;
1491
1492 //TRACE("owner=0x%04x hmenu=0x%04x id=0x%04x x=0x%04x y=0x%04x xa=0x%04x ya=0x%04x\n",
1493 //hwndOwner, hmenu, id, x, y, xanchor, yanchor);
1494
1495 if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
1496 if (menu->FocusedItem != NO_SELECTED_ITEM)
1497 {
1498 menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
1499 menu->FocusedItem = NO_SELECTED_ITEM;
1500 }
1501
1502 /* store the owner for DrawItem*/
1503 menu->hwndOwner = hwndOwner;
1504
1505 if(IsWindow(hwndOwner))
1506 {
1507 UINT width, height;
1508
1509 MENU_PopupMenuCalcSize( menu, hwndOwner );
1510
1511 /* adjust popup menu pos so that it fits within the desktop */
1512
1513 width = menu->Width + GetSystemMetrics(SM_CXBORDER);
1514 height = menu->Height + GetSystemMetrics(SM_CYBORDER);
1515
1516 if( x + width > GetSystemMetrics(SM_CXSCREEN ))
1517 {
1518 if( xanchor )
1519 x -= width - xanchor;
1520 if( x + width > GetSystemMetrics(SM_CXSCREEN))
1521 x = GetSystemMetrics(SM_CXSCREEN) - width;
1522 }
1523 if( x < 0 ) x = 0;
1524
1525 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
1526 {
1527 if( yanchor )
1528 y -= height + yanchor;
1529 if( y + height > GetSystemMetrics(SM_CYSCREEN ))
1530 y = GetSystemMetrics(SM_CYSCREEN) - height;
1531 }
1532 if( y < 0 ) y = 0;
1533
1534 /* NOTE: In Windows, top menu popup is not owned. */
1535 if (!pTopPopupWnd) /* create top level popup menu window */
1536 {
1537 assert( uSubPWndLevel == 0 );
1538
1539 pTopPopupWnd = CreateWindowA( POPUPMENUCLASSNAME, NULL,
1540 WS_POPUP, x, y, width, height,
1541 hwndOwner, 0, GetWindowLongA(hwndOwner,GWL_HINSTANCE),
1542 (LPVOID)hmenu );
1543 if (!pTopPopupWnd)
1544 {
1545 return FALSE;
1546 }
1547 menu->hWnd = pTopPopupWnd;
1548 MENU_ReleaseTopPopupWnd();
1549 }
1550 else
1551 if( uSubPWndLevel )
1552 {
1553 /* create a new window for the submenu */
1554
1555 menu->hWnd = CreateWindowA( POPUPMENUCLASSNAME, NULL,
1556 WS_POPUP, x, y, width, height,
1557 hwndOwner, 0, GetWindowLongA(hwndOwner,GWL_HINSTANCE),
1558 (LPVOID)hmenu );
1559 if( !menu->hWnd )
1560 {
1561 return FALSE;
1562 }
1563 }
1564 else /* top level popup menu window already exists */
1565 {
1566 HWND pTPWnd = MENU_GetTopPopupWnd();
1567 menu->hWnd = pTPWnd;
1568
1569 MENU_PatchResidentPopup( 0, hwndOwner );
1570 SendMessageA( pTPWnd, MM_SETMENUHANDLE, (WPARAM)hmenu, 0L);
1571
1572 /* adjust its size */
1573
1574 SetWindowPos( menu->hWnd, 0, x, y, width, height,
1575 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
1576 MENU_ReleaseTopPopupWnd();
1577 }
1578
1579 uSubPWndLevel++; /* menu level counter */
1580
1581 /* Display the window */
1582
1583 SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0,
1584 SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1585 UpdateWindow( menu->hWnd );
1586 return TRUE;
1587 }
1588 return FALSE;
1589}
1590
1591
1592/***********************************************************************
1593 * MENU_SelectItem
1594 */
1595static void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex,
1596 BOOL sendMenuSelect, HMENU topmenu )
1597{
1598 LPPOPUPMENU lppop;
1599 HDC hdc;
1600
1601 //TRACE("owner=0x%04x menu=0x%04x index=0x%04x select=0x%04x\n", hwndOwner, hmenu, wIndex, sendMenuSelect);
1602
1603 lppop = (POPUPMENU*)hmenu;
1604 if (!lppop->nItems) return;
1605
1606 if (lppop->FocusedItem == wIndex) return;
1607 if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd );
1608 else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW);
1609
1610 SelectObject( hdc, hMenuFont);
1611
1612 /* Clear previous highlighted item */
1613 if (lppop->FocusedItem != NO_SELECTED_ITEM)
1614 {
1615 lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT);
1616 MENU_DrawMenuItem(lppop->hWnd, hmenu, hwndOwner, hdc,&lppop->items[lppop->FocusedItem],
1617 lppop->Height, !(lppop->wFlags & MF_POPUP),
1618 ODA_SELECT );
1619 }
1620
1621 /* Highlight new item (if any) */
1622 lppop->FocusedItem = wIndex;
1623 if (lppop->FocusedItem != NO_SELECTED_ITEM)
1624 {
1625 if(!(lppop->items[wIndex].fType & MF_SEPARATOR)) {
1626 lppop->items[wIndex].fState |= MF_HILITE;
1627 MENU_DrawMenuItem( lppop->hWnd, hmenu, hwndOwner, hdc,
1628 &lppop->items[wIndex], lppop->Height,
1629 !(lppop->wFlags & MF_POPUP), ODA_SELECT );
1630 }
1631 if (sendMenuSelect)
1632 {
1633 MENUITEM *ip = &lppop->items[lppop->FocusedItem];
1634 SendMessageA( hwndOwner, WM_MENUSELECT,
1635 MAKELONG(ip->fType & MF_POPUP ? wIndex: ip->wID,
1636 ip->fType | ip->fState | MF_MOUSESELECT |
1637 (lppop->wFlags & MF_SYSMENU)), hmenu);
1638 }
1639 }
1640 else if (sendMenuSelect) {
1641 if(topmenu){
1642 int pos;
1643 if((pos=MENU_FindSubMenu(&topmenu, hmenu))!=NO_SELECTED_ITEM){
1644 POPUPMENU *ptm = (POPUPMENU*)topmenu;
1645 MENUITEM *ip = &ptm->items[pos];
1646 SendMessageA( hwndOwner, WM_MENUSELECT, MAKELONG(pos,
1647 ip->fType | ip->fState | MF_MOUSESELECT |
1648 (ptm->wFlags & MF_SYSMENU)), topmenu);
1649 }
1650 }
1651 }
1652 ReleaseDC( lppop->hWnd, hdc );
1653}
1654
1655
1656/***********************************************************************
1657 * MENU_MoveSelection
1658 *
1659 * Moves currently selected item according to the offset parameter.
1660 * If there is no selection then it should select the last item if
1661 * offset is ITEM_PREV or the first item if offset is ITEM_NEXT.
1662 */
1663static void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset )
1664{
1665 INT i;
1666 POPUPMENU *menu;
1667
1668 //TRACE("hwnd=0x%04x hmenu=0x%04x off=0x%04x\n", hwndOwner, hmenu, offset);
1669
1670 menu = (POPUPMENU*)hmenu;
1671 if (!menu->items) return;
1672
1673 if ( menu->FocusedItem != NO_SELECTED_ITEM )
1674 {
1675 if( menu->nItems == 1 ) return; else
1676 for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems
1677 ; i += offset)
1678 if (!(menu->items[i].fType & MF_SEPARATOR))
1679 {
1680 MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
1681 return;
1682 }
1683 }
1684
1685 for ( i = (offset > 0) ? 0 : menu->nItems - 1;
1686 i >= 0 && i < menu->nItems ; i += offset)
1687 if (!(menu->items[i].fType & MF_SEPARATOR))
1688 {
1689 MENU_SelectItem( hwndOwner, hmenu, i, TRUE, 0 );
1690 return;
1691 }
1692}
1693
1694
1695/**********************************************************************
1696 * MENU_SetItemData
1697 *
1698 * Set an item flags, id and text ptr. Called by InsertMenu() and
1699 * ModifyMenu().
1700 */
1701static BOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id,
1702 LPCSTR str )
1703{
1704 LPSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL;
1705
1706 //debug_print_menuitem("MENU_SetItemData from: ", item, "");
1707
1708 if (IS_STRING_ITEM(flags))
1709 {
1710 if (!str || !*str)
1711 {
1712 flags |= MF_SEPARATOR;
1713 item->text = NULL;
1714 }
1715 else
1716 {
1717 LPSTR text;
1718 /* Item beginning with a backspace is a help item */
1719 if (*str == '\b')
1720 {
1721 flags |= MF_HELP;
1722 str++;
1723 }
1724 if (!(text = HEAP_strdupA(GetProcessHeap(), 0, str ))) return FALSE;
1725 item->text = text;
1726 }
1727 }
1728 else if (IS_BITMAP_ITEM(flags))
1729 item->text = (LPSTR)(HBITMAP)LOWORD(str);
1730 else item->text = NULL;
1731
1732 if (flags & MF_OWNERDRAW)
1733 item->dwItemData = (DWORD)str;
1734 else
1735 item->dwItemData = 0;
1736
1737 if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
1738 DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
1739
1740 if (flags & MF_POPUP)
1741 {
1742 POPUPMENU *menu = (POPUPMENU*)(UINT)id;
1743 if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
1744 else
1745 {
1746 item->wID = 0;
1747 item->hSubMenu = 0;
1748 item->fType = 0;
1749 item->fState = 0;
1750 return FALSE;
1751 }
1752 }
1753
1754 item->wID = id;
1755 if (flags & MF_POPUP)
1756 item->hSubMenu = id;
1757
1758 if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
1759 flags |= MF_POPUP; /* keep popup */
1760
1761 item->fType = flags & TYPE_MASK;
1762 item->fState = (flags & STATE_MASK) &
1763 ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
1764
1765
1766 /* Don't call SetRectEmpty here! */
1767
1768
1769 if (prevText) HeapFree(GetProcessHeap(), 0, prevText );
1770
1771 //debug_print_menuitem("MENU_SetItemData to : ", item, "");
1772 return TRUE;
1773}
1774
1775
1776/**********************************************************************
1777 * MENU_InsertItem
1778 *
1779 * Insert a new item into a menu.
1780 */
1781static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
1782{
1783 MENUITEM *newItems;
1784 POPUPMENU *menu;
1785
1786 if (!(menu = (POPUPMENU*)hMenu))
1787 {
1788 //WARN("%04x not a menu handle\n",
1789 // hMenu );
1790 return NULL;
1791 }
1792
1793 /* Find where to insert new item */
1794
1795 if ((pos==(UINT)-1) || ((flags & MF_BYPOSITION) && (pos == menu->nItems)))
1796 {
1797 /* Special case: append to menu */
1798 /* Some programs specify the menu length to do that */
1799 pos = menu->nItems;
1800 }
1801 else
1802 {
1803 if (!MENU_FindItem( &hMenu, &pos, flags ))
1804 {
1805 //WARN("item %x not found\n",
1806 // pos );
1807 return NULL;
1808 }
1809 if (!(menu = (LPPOPUPMENU)hMenu))
1810 {
1811 //WARN("%04x not a menu handle\n",
1812 // hMenu);
1813 return NULL;
1814 }
1815 }
1816
1817 /* Create new items array */
1818
1819 newItems = (MENUITEM*)HeapAlloc(GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) );
1820 if (!newItems)
1821 {
1822 //WARN("allocation failed\n" );
1823 return NULL;
1824 }
1825 if (menu->nItems > 0)
1826 {
1827 /* Copy the old array into the new */
1828 if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
1829 if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
1830 (menu->nItems-pos)*sizeof(MENUITEM) );
1831 HeapFree(GetProcessHeap(), 0, menu->items );
1832 }
1833 menu->items = newItems;
1834 menu->nItems++;
1835 memset( &newItems[pos], 0, sizeof(*newItems) );
1836 menu->Height = 0; /* force size recalculate */
1837 return &newItems[pos];
1838}
1839
1840
1841/**********************************************************************
1842 * MENU_ParseResource
1843 *
1844 * Parse a standard menu resource and add items to the menu.
1845 * Return a pointer to the end of the resource.
1846 */
1847static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
1848{
1849 WORD flags, id = 0;
1850 LPCSTR str;
1851
1852 do
1853 {
1854 flags = GET_WORD(res);
1855 res += sizeof(WORD);
1856 if (!(flags & MF_POPUP))
1857 {
1858 id = GET_WORD(res);
1859 res += sizeof(WORD);
1860 }
1861 //if (!IS_STRING_ITEM(flags))
1862 // ERR("not a string item %04x\n", flags );
1863 str = res;
1864 if (!unicode) res += strlen(str) + 1;
1865 else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
1866 if (flags & MF_POPUP)
1867 {
1868 HMENU hSubMenu = CreatePopupMenu();
1869 if (!hSubMenu) return NULL;
1870 if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
1871 return NULL;
1872 if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
1873 else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
1874 }
1875 else /* Not a popup */
1876 {
1877 if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1878 else AppendMenuW( hMenu, flags, id,
1879 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
1880 }
1881 } while (!(flags & MF_END));
1882 return res;
1883}
1884
1885
1886/**********************************************************************
1887 * MENUEX_ParseResource
1888 *
1889 * Parse an extended menu resource and add items to the menu.
1890 * Return a pointer to the end of the resource.
1891 */
1892static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
1893{
1894 WORD resinfo;
1895 do {
1896 MENUITEMINFOW mii;
1897
1898 mii.cbSize = sizeof(mii);
1899 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
1900 mii.fType = GET_DWORD(res);
1901 res += sizeof(DWORD);
1902 mii.fState = GET_DWORD(res);
1903 res += sizeof(DWORD);
1904 mii.wID = GET_DWORD(res);
1905 res += sizeof(DWORD);
1906 resinfo = GET_WORD(res);
1907 res += sizeof(WORD);
1908 /* Align the text on a word boundary. */
1909 res += (~((int)res - 1)) & 1;
1910 mii.dwTypeData = (LPWSTR) res;
1911 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
1912 /* Align the following fields on a dword boundary. */
1913 res += (~((int)res - 1)) & 3;
1914
1915 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1916 {
1917 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
1918 0, mii.dwTypeData);
1919 //TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
1920 // mii.fType, mii.fState, mii.wID, resinfo, newstr);
1921 HeapFree( GetProcessHeap(), 0, newstr );
1922 }
1923
1924 if (resinfo & 1) { /* Pop-up? */
1925 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
1926 res += sizeof(DWORD);
1927 mii.hSubMenu = CreatePopupMenu();
1928 if (!mii.hSubMenu)
1929 return NULL;
1930 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
1931 DestroyMenu(mii.hSubMenu);
1932 return NULL;
1933 }
1934 mii.fMask |= MIIM_SUBMENU;
1935 mii.fType |= MF_POPUP;
1936 }
1937 InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
1938 } while (!(resinfo & MF_END));
1939 return res;
1940}
1941
1942
1943/***********************************************************************
1944 * MENU_GetSubPopup
1945 *
1946 * Return the handle of the selected sub-popup menu (if any).
1947 */
1948static HMENU MENU_GetSubPopup( HMENU hmenu )
1949{
1950 POPUPMENU *menu;
1951 MENUITEM *item;
1952
1953 menu = (POPUPMENU*)hmenu;
1954
1955 if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
1956
1957 item = &menu->items[menu->FocusedItem];
1958 if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
1959 return item->hSubMenu;
1960 return 0;
1961}
1962
1963
1964/***********************************************************************
1965 * MENU_HideSubPopups
1966 *
1967 * Hide the sub-popup menus of this menu.
1968 */
1969static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
1970 BOOL sendMenuSelect )
1971{
1972 POPUPMENU *menu = (POPUPMENU*)hmenu;
1973
1974 //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
1975
1976 if (menu && uSubPWndLevel)
1977 {
1978 HMENU hsubmenu;
1979 POPUPMENU *submenu;
1980 MENUITEM *item;
1981
1982 if (menu->FocusedItem != NO_SELECTED_ITEM)
1983 {
1984 item = &menu->items[menu->FocusedItem];
1985 if (!(item->fType & MF_POPUP) ||
1986 !(item->fState & MF_MOUSESELECT)) return;
1987 item->fState &= ~MF_MOUSESELECT;
1988 hsubmenu = item->hSubMenu;
1989 } else return;
1990
1991 submenu = (POPUPMENU*)hsubmenu;
1992 MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
1993 MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
1994
1995 if (submenu->hWnd == MENU_GetTopPopupWnd() )
1996 {
1997 ShowWindow( submenu->hWnd, SW_HIDE );
1998 uSubPWndLevel = 0;
1999 }
2000 else
2001 {
2002 DestroyWindow( submenu->hWnd );
2003 submenu->hWnd = 0;
2004 }
2005 MENU_ReleaseTopPopupWnd();
2006 }
2007}
2008
2009
2010/***********************************************************************
2011 * MENU_ShowSubPopup
2012 *
2013 * Display the sub-menu of the selected item of this menu.
2014 * Return the handle of the submenu, or hmenu if no submenu to display.
2015 */
2016static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
2017 BOOL selectFirst, UINT wFlags,POINT *pt)
2018{
2019 RECT rect;
2020 POPUPMENU *menu;
2021 MENUITEM *item;
2022 HDC hdc;
2023
2024 //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
2025
2026 if (!(menu = (POPUPMENU*)hmenu)) return hmenu;
2027
2028 if (menu->FocusedItem == NO_SELECTED_ITEM)
2029 {
2030 return hmenu;
2031 }
2032
2033 item = &menu->items[menu->FocusedItem];
2034 if (!(item->fType & MF_POPUP) ||
2035 (item->fState & (MF_GRAYED | MF_DISABLED)))
2036 {
2037 return hmenu;
2038 }
2039
2040 /* message must be send before using item,
2041 because nearly everything may by changed by the application ! */
2042
2043 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2044 if (!(wFlags & TPM_NONOTIFY))
2045 SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
2046 MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
2047
2048 item = &menu->items[menu->FocusedItem];
2049 rect = item->rect;
2050
2051 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2052 if (!(item->fState & MF_HILITE))
2053 {
2054 if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
2055 else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
2056
2057 SelectObject( hdc, hMenuFont);
2058
2059 item->fState |= MF_HILITE;
2060 MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
2061 ReleaseDC( menu->hWnd, hdc );
2062 }
2063 if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
2064 item->rect = rect;
2065
2066 item->fState |= MF_MOUSESELECT;
2067
2068 if (IS_SYSTEM_MENU(menu))
2069 {
2070 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
2071
2072 MENU_InitSysMenuPopup(item->hSubMenu,GetWindowLongA(menu->hWnd,GWL_STYLE), GetClassLongA(menu->hWnd, GCL_STYLE));
2073
2074 if ((wFlags & TPM_CAPTIONSYSMENU) && pt)
2075 {
2076 rect.top = pt->y;
2077 rect.left = pt->x;
2078 rect.bottom = rect.right = 0;
2079 } else
2080 {
2081 if (win32wnd) win32wnd->GetSysPopupPos(&rect);
2082 rect.top = rect.bottom;
2083 rect.right = GetSystemMetrics(SM_CXSIZE);
2084 rect.bottom = GetSystemMetrics(SM_CYSIZE);
2085 }
2086 }
2087 else
2088 {
2089 if (menu->wFlags & MF_POPUP)
2090 {
2091 RECT rectWindow;
2092
2093 GetWindowRect(menu->hWnd,&rectWindow);
2094 rect.left = rectWindow.left + item->rect.right-arrow_bitmap_width;
2095 rect.top = rectWindow.top + item->rect.top;
2096 rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
2097 rect.bottom = item->rect.top - item->rect.bottom;
2098 }
2099 else
2100 {
2101 RECT rectWindow;
2102
2103 GetWindowRect(menu->hWnd,&rectWindow);
2104 rect.left = rectWindow.left + item->rect.left;
2105 rect.top = rectWindow.top + item->rect.bottom;
2106 rect.right = item->rect.right - item->rect.left;
2107 rect.bottom = item->rect.bottom - item->rect.top;
2108 }
2109 }
2110
2111 MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
2112 rect.left, rect.top, rect.right, rect.bottom );
2113 if (selectFirst)
2114 MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
2115 return item->hSubMenu;
2116}
2117
2118/***********************************************************************
2119 * MENU_PtMenu
2120 *
2121 * Walks menu chain trying to find a menu pt maps to.
2122 */
2123static HMENU MENU_PtMenu(HMENU hMenu,POINT pt,BOOL inMenuBar)
2124{
2125 POPUPMENU *menu = (POPUPMENU*)hMenu;
2126 register UINT ht = menu->FocusedItem;
2127
2128 /* try subpopup first (if any) */
2129 ht = (ht != NO_SELECTED_ITEM &&
2130 (menu->items[ht].fType & MF_POPUP) &&
2131 (menu->items[ht].fState & MF_MOUSESELECT))
2132 ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu,pt,inMenuBar) : 0;
2133
2134 if( !ht ) /* check the current window (avoiding WM_HITTEST) */
2135 {
2136 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
2137 if(win32wnd==NULL)
2138 DebugInt3();
2139
2140 ht = win32wnd->HandleNCHitTest(pt);
2141 if( menu->wFlags & MF_POPUP )
2142 ht = (ht != (UINT)HTNOWHERE &&
2143 ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
2144 else
2145 {
2146 ht = ((ht == HTSYSMENU) && !inMenuBar) ? (UINT)(getSysMenu(menu->hWnd))
2147 : ((ht == HTMENU) && inMenuBar) ? (UINT)(getMenu(menu->hWnd)) : 0;
2148 }
2149 }
2150 return (HMENU)ht;
2151}
2152
2153/***********************************************************************
2154 * MENU_ExecFocusedItem
2155 *
2156 * Execute a menu item (for instance when user pressed Enter).
2157 * Return the wID of the executed item. Otherwise, -1 indicating
2158 * that no menu item wase executed;
2159 * Have to receive the flags for the TrackPopupMenu options to avoid
2160 * sending unwanted message.
2161 *
2162 */
2163static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
2164{
2165 MENUITEM *item;
2166 POPUPMENU *menu = (POPUPMENU*)hMenu;
2167
2168 //TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
2169
2170 if (!menu || !menu->nItems ||
2171 (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
2172
2173 item = &menu->items[menu->FocusedItem];
2174
2175 //TRACE("%08x %08x %08x\n",
2176 // hMenu, item->wID, item->hSubMenu);
2177
2178 if (!(item->fType & MF_POPUP))
2179 {
2180 if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
2181 {
2182 /* If TPM_RETURNCMD is set you return the id, but
2183 do not send a message to the owner */
2184 if(!(wFlags & TPM_RETURNCMD))
2185 {
2186 if( menu->wFlags & MF_SYSMENU )
2187 PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
2188 MAKELPARAM(pmt->pt.x, pmt->pt.y) );
2189 else
2190 PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
2191 }
2192 return item->wID;
2193 }
2194 }
2195 else
2196 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags,&pmt->pt);
2197
2198 return -1;
2199}
2200
2201/***********************************************************************
2202 * MENU_SwitchTracking
2203 *
2204 * Helper function for menu navigation routines.
2205 */
2206static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
2207{
2208 POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
2209 POPUPMENU *topmenu = (POPUPMENU*)pmt->hTopMenu;
2210
2211 //TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
2212
2213 if( pmt->hTopMenu != hPtMenu &&
2214 !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
2215 {
2216 /* both are top level menus (system and menu-bar) */
2217 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2218 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
2219 pmt->hTopMenu = hPtMenu;
2220 }
2221 else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
2222 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 );
2223}
2224
2225
2226/***********************************************************************
2227 * MENU_ButtonDown
2228 *
2229 * Return TRUE if we can go on with menu tracking.
2230 */
2231static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
2232{
2233 //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
2234
2235 if (hPtMenu)
2236 {
2237 UINT id = 0;
2238 POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
2239 MENUITEM *item;
2240
2241 if( IS_SYSTEM_MENU(ptmenu) )
2242 item = ptmenu->items;
2243 else
2244 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2245
2246 if( item )
2247 {
2248 if( ptmenu->FocusedItem != id )
2249 MENU_SwitchTracking( pmt, hPtMenu, id );
2250
2251 /* If the popup menu is not already "popped" */
2252 if(!(item->fState & MF_MOUSESELECT ))
2253 {
2254 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,hPtMenu,FALSE,wFlags,&pmt->pt);
2255 }
2256
2257 return TRUE;
2258 }
2259 /* Else the click was on the menu bar, finish the tracking */
2260 }
2261 return FALSE;
2262}
2263
2264/***********************************************************************
2265 * MENU_ButtonUp
2266 *
2267 * Return the value of MENU_ExecFocusedItem if
2268 * the selected item was not a popup. Else open the popup.
2269 * A -1 return value indicates that we go on with menu tracking.
2270 *
2271 */
2272static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
2273{
2274 //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
2275
2276 if (hPtMenu)
2277 {
2278 UINT id = 0;
2279 POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
2280 MENUITEM *item;
2281
2282 if( IS_SYSTEM_MENU(ptmenu) )
2283 item = ptmenu->items;
2284 else
2285 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2286
2287 if( item && (ptmenu->FocusedItem == id ))
2288 {
2289 if( !(item->fType & MF_POPUP) )
2290 return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
2291
2292 /* If we are dealing with the top-level menu and that this */
2293 /* is a click on an already "poppped" item */
2294 /* Stop the menu tracking and close the opened submenus */
2295 if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
2296 return 0;
2297 }
2298 ptmenu->bTimeToHide = TRUE;
2299 }
2300 return -1;
2301}
2302
2303
2304/***********************************************************************
2305 * MENU_MouseMove
2306 *
2307 * Return TRUE if we can go on with menu tracking.
2308 */
2309static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
2310{
2311 UINT id = NO_SELECTED_ITEM;
2312 POPUPMENU *ptmenu = NULL;
2313
2314 if( hPtMenu )
2315 {
2316 ptmenu = (POPUPMENU*)hPtMenu;
2317 if( IS_SYSTEM_MENU(ptmenu) )
2318 id = 0;
2319 else
2320 MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2321 }
2322
2323 if( id == NO_SELECTED_ITEM )
2324 {
2325 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2326 NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
2327
2328 }
2329 else if( ptmenu->FocusedItem != id )
2330 {
2331 MENU_SwitchTracking( pmt, hPtMenu, id );
2332 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags,&pmt->pt);
2333 }
2334 return TRUE;
2335}
2336
2337
2338/***********************************************************************
2339 * MENU_DoNextMenu
2340 *
2341 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
2342 */
2343static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
2344{
2345 POPUPMENU *menu = (POPUPMENU*)pmt->hTopMenu;
2346
2347 if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
2348 (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
2349 {
2350 HMENU hNewMenu;
2351 HWND hNewWnd;
2352 UINT id = 0;
2353 LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
2354 (IS_SYSTEM_MENU(menu)) ? GetSubMenu(pmt->hTopMenu,0) : pmt->hTopMenu );
2355
2356 //TRACE("%04x [%04x] -> %04x [%04x]\n",
2357 // (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
2358
2359 if( l == 0 )
2360 {
2361 hNewWnd = pmt->hOwnerWnd;
2362 if( IS_SYSTEM_MENU(menu) )
2363 {
2364 /* switch to the menu bar */
2365
2366 if( (GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_CHILD) || !getMenu(pmt->hOwnerWnd) )
2367 {
2368 return FALSE;
2369 }
2370
2371 hNewMenu = getMenu(pmt->hOwnerWnd);
2372 if( vk == VK_LEFT )
2373 {
2374 menu = (POPUPMENU*)hNewMenu;
2375 id = menu->nItems - 1;
2376 }
2377 }
2378 else if( GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_SYSMENU )
2379 {
2380 /* switch to the system menu */
2381 hNewMenu = getSysMenu(pmt->hOwnerWnd);
2382 }
2383 else
2384 {
2385 return FALSE;
2386 }
2387 }
2388 else /* application returned a new menu to switch to */
2389 {
2390 hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
2391
2392 if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
2393 {
2394 if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_SYSMENU) &&
2395 GetSubMenu(getSysMenu(hNewWnd), 0) == hNewMenu )
2396 {
2397 /* get the real system menu */
2398 hNewMenu = getSysMenu(hNewWnd);
2399 }
2400 else if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_CHILD) || (getMenu(hNewWnd) != hNewMenu) )
2401 {
2402 /* FIXME: Not sure what to do here, perhaps,
2403 * try to track hNewMenu as a popup? */
2404
2405 //TRACE(" -- got confused.\n");
2406 return FALSE;
2407 }
2408 }
2409 else return FALSE;
2410 }
2411
2412 if( hNewMenu != pmt->hTopMenu )
2413 {
2414 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
2415 FALSE, 0 );
2416 if( pmt->hCurrentMenu != pmt->hTopMenu )
2417 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2418 }
2419
2420 if( hNewWnd != pmt->hOwnerWnd )
2421 {
2422 ReleaseCapture();
2423 pmt->hOwnerWnd = hNewWnd;
2424 SetCapture(pmt->hOwnerWnd); //SvL: Don't know if this is good enough
2425 //EVENT_Capture( pmt->hOwnerWnd, HTMENU ); //CB: todo
2426 }
2427
2428 pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
2429 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
2430
2431 return TRUE;
2432 }
2433 return FALSE;
2434}
2435
2436/***********************************************************************
2437 * MENU_SuspendPopup
2438 *
2439 * The idea is not to show the popup if the next input message is
2440 * going to hide it anyway.
2441 */
2442static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT uMsg )
2443{
2444 MSG msg;
2445
2446 msg.hwnd = pmt->hOwnerWnd;
2447
2448 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2449 pmt->trackFlags |= TF_SKIPREMOVE;
2450
2451 switch( uMsg )
2452 {
2453 case WM_KEYDOWN:
2454 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
2455 if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
2456 {
2457 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2458 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
2459 if( msg.message == WM_KEYDOWN &&
2460 (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
2461 {
2462 pmt->trackFlags |= TF_SUSPENDPOPUP;
2463 return TRUE;
2464 }
2465 }
2466 break;
2467 }
2468
2469 /* failures go through this */
2470 pmt->trackFlags &= ~TF_SUSPENDPOPUP;
2471 return FALSE;
2472}
2473
2474/***********************************************************************
2475 * MENU_KeyLeft
2476 *
2477 * Handle a VK_LEFT key event in a menu.
2478 */
2479static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags )
2480{
2481 POPUPMENU *menu;
2482 HMENU hmenutmp, hmenuprev;
2483 UINT prevcol;
2484
2485 hmenuprev = hmenutmp = pmt->hTopMenu;
2486 menu = (POPUPMENU*)hmenutmp;
2487
2488 /* Try to move 1 column left (if possible) */
2489 if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
2490 NO_SELECTED_ITEM ) {
2491
2492 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2493 prevcol, TRUE, 0 );
2494 return;
2495 }
2496
2497 /* close topmost popup */
2498 while (hmenutmp != pmt->hCurrentMenu)
2499 {
2500 hmenuprev = hmenutmp;
2501 hmenutmp = MENU_GetSubPopup( hmenuprev );
2502 }
2503
2504 MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
2505 pmt->hCurrentMenu = hmenuprev;
2506
2507 if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
2508 {
2509 /* move menu bar selection if no more popups are left */
2510
2511 if( !MENU_DoNextMenu( pmt, VK_LEFT) )
2512 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
2513
2514 if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2515 {
2516 /* A sublevel menu was displayed - display the next one
2517 * unless there is another displacement coming up */
2518
2519 if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
2520 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2521 pmt->hTopMenu, TRUE, wFlags,&pmt->pt);
2522 }
2523 }
2524}
2525
2526
2527/***********************************************************************
2528 * MENU_KeyRight
2529 *
2530 * Handle a VK_RIGHT key event in a menu.
2531 */
2532static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags )
2533{
2534 HMENU hmenutmp;
2535 POPUPMENU *menu = (POPUPMENU*)pmt->hTopMenu;
2536 UINT nextcol;
2537
2538 //TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
2539 // pmt->hCurrentMenu,
2540 // ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
2541 // items[0].text,
2542 // pmt->hTopMenu, menu->items[0].text );
2543
2544 if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
2545 {
2546 /* If already displaying a popup, try to display sub-popup */
2547
2548 hmenutmp = pmt->hCurrentMenu;
2549 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags,&pmt->pt);
2550
2551 /* if subpopup was displayed then we are done */
2552 if (hmenutmp != pmt->hCurrentMenu) return;
2553 }
2554
2555 /* Check to see if there's another column */
2556 if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
2557 NO_SELECTED_ITEM ) {
2558 //TRACE("Going to %d.\n", nextcol );
2559 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2560 nextcol, TRUE, 0 );
2561 return;
2562 }
2563
2564 if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
2565 {
2566 if( pmt->hCurrentMenu != pmt->hTopMenu )
2567 {
2568 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2569 hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
2570 } else hmenutmp = 0;
2571
2572 /* try to move to the next item */
2573 if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
2574 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
2575
2576 if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2577 if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
2578 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2579 pmt->hTopMenu, TRUE, wFlags,&pmt->pt);
2580 }
2581}
2582
2583/***********************************************************************
2584 * MENU_TrackMenu
2585 *
2586 * Menu tracking code.
2587 */
2588static INT MENU_TrackMenu(HMENU hmenu,UINT wFlags,INT x,INT y,HWND hwnd,BOOL inMenuBar,const RECT *lprect)
2589{
2590 MSG msg;
2591 POPUPMENU *menu;
2592 BOOL fRemove;
2593 INT executedMenuId = -1;
2594 MTRACKER mt;
2595 BOOL enterIdleSent = FALSE;
2596
2597 mt.trackFlags = 0;
2598 mt.hCurrentMenu = hmenu;
2599 mt.hTopMenu = hmenu;
2600 mt.hOwnerWnd = hwnd;
2601 mt.pt.x = x;
2602 mt.pt.y = y;
2603
2604 //TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
2605 // hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
2606 // (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
2607
2608 fEndMenu = FALSE;
2609 if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
2610
2611 if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu, wFlags );
2612
2613 //EVENT_Capture( mt.hOwnerWnd, HTMENU ); //CB: todo
2614 //SvL: Set keyboard & mouse event capture
2615 SetCapture(mt.hOwnerWnd);
2616
2617 while (!fEndMenu)
2618 {
2619 menu = (POPUPMENU*)mt.hCurrentMenu;
2620 msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
2621
2622 /* we have to keep the message in the queue until it's
2623 * clear that menu loop is not over yet. */
2624// if (!GetMessageA(&msg,msg.hwnd,0,0)) break;
2625 //SvL: Getting messages for only the menu delays background paints (i.e. VPBuddy logo)
2626 if (!GetMessageA(&msg,0,0,0)) break;
2627 TranslateMessage( &msg );
2628 mt.pt = msg.pt;
2629
2630 if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
2631 enterIdleSent=FALSE;
2632
2633 fRemove = FALSE;
2634 if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
2635 {
2636 /* Find a menu for this mouse event */
2637 POINT pt = msg.pt;
2638
2639 hmenu = MENU_PtMenu(mt.hTopMenu,pt,inMenuBar);
2640
2641 switch(msg.message)
2642 {
2643 /* no WM_NC... messages in captured state */
2644
2645 case WM_RBUTTONDBLCLK:
2646 case WM_RBUTTONDOWN:
2647 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2648 /* fall through */
2649 case WM_LBUTTONDBLCLK:
2650 case WM_LBUTTONDOWN:
2651 /* If the message belongs to the menu, removes it from the queue */
2652 /* Else, end menu tracking */
2653 fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
2654 fEndMenu = !fRemove;
2655 break;
2656
2657 case WM_RBUTTONUP:
2658 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2659 /* fall through */
2660 case WM_LBUTTONUP:
2661 /* Check if a menu was selected by the mouse */
2662 if (hmenu)
2663 {
2664 executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
2665
2666 /* End the loop if executedMenuId is an item ID */
2667 /* or if the job was done (executedMenuId = 0). */
2668 fEndMenu = fRemove = (executedMenuId != -1);
2669 }
2670 /* No menu was selected by the mouse */
2671 /* if the function was called by TrackPopupMenu, continue
2672 with the menu tracking. If not, stop it */
2673 else
2674 fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
2675
2676 break;
2677
2678 case WM_MOUSEMOVE:
2679 /* In win95 winelook, the selected menu item must be changed every time the
2680 mouse moves. In Win31 winelook, the mouse button has to be held down */
2681
2682 fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
2683
2684 } /* switch(msg.message) - mouse */
2685 }
2686 else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
2687 {
2688 fRemove = TRUE; /* Keyboard messages are always removed */
2689 switch(msg.message)
2690 {
2691 case WM_KEYDOWN:
2692 switch(msg.wParam)
2693 {
2694 case VK_HOME:
2695 case VK_END:
2696 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
2697 NO_SELECTED_ITEM, FALSE, 0 );
2698 /* fall through */
2699 case VK_UP:
2700 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
2701 (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
2702 break;
2703
2704 case VK_DOWN: /* If on menu bar, pull-down the menu */
2705
2706 menu = (POPUPMENU*)mt.hCurrentMenu;
2707 if (!(menu->wFlags & MF_POPUP))
2708 mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags,&mt.pt);
2709 else /* otherwise try to move selection */
2710 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
2711 break;
2712
2713 case VK_LEFT:
2714 MENU_KeyLeft( &mt, wFlags );
2715 break;
2716
2717 case VK_RIGHT:
2718 MENU_KeyRight( &mt, wFlags );
2719 break;
2720
2721 case VK_ESCAPE:
2722 fEndMenu = TRUE;
2723 break;
2724
2725 default:
2726 break;
2727 }
2728 break; /* WM_KEYDOWN */
2729
2730 case WM_SYSKEYDOWN:
2731 switch(msg.wParam)
2732 {
2733 case VK_MENU:
2734 fEndMenu = TRUE;
2735 break;
2736
2737 }
2738 break; /* WM_SYSKEYDOWN */
2739
2740 case WM_CHAR:
2741 {
2742 UINT pos;
2743
2744 if (msg.wParam == '\r' || msg.wParam == ' ')
2745 {
2746 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
2747 fEndMenu = (executedMenuId != -1);
2748
2749 break;
2750 }
2751
2752 /* Hack to avoid control chars. */
2753 /* We will find a better way real soon... */
2754 if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
2755
2756 pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
2757 LOWORD(msg.wParam), FALSE );
2758 if (pos == (UINT)-2) fEndMenu = TRUE;
2759 else if (pos == (UINT)-1) MessageBeep(0);
2760 else
2761 {
2762 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
2763 TRUE, 0 );
2764 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
2765 fEndMenu = (executedMenuId != -1);
2766 }
2767 }
2768 break;
2769 } /* switch(msg.message) - kbd */
2770 }
2771 else
2772 {
2773 DispatchMessageA( &msg );
2774 }
2775
2776 if (!fEndMenu) fRemove = TRUE;
2777
2778 /* finally remove message from the queue */
2779
2780 if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
2781 PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
2782 else mt.trackFlags &= ~TF_SKIPREMOVE;
2783 }
2784
2785 ReleaseCapture();
2786
2787 menu = (POPUPMENU*)mt.hTopMenu;
2788
2789 if( IsWindow( mt.hOwnerWnd ) )
2790 {
2791 MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
2792
2793 if (menu && menu->wFlags & MF_POPUP)
2794 {
2795 ShowWindow( menu->hWnd, SW_HIDE );
2796 uSubPWndLevel = 0;
2797 }
2798 MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
2799 SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
2800 }
2801
2802 /* Reset the variable for hiding menu */
2803 menu->bTimeToHide = FALSE;
2804
2805 /* The return value is only used by TrackPopupMenu */
2806 return ((executedMenuId != -1) ? executedMenuId : 0);
2807}
2808
2809/***********************************************************************
2810 * MENU_InitTracking
2811 */
2812static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
2813{
2814 //TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
2815
2816 HideCaret(0);
2817
2818 /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
2819 if (!(wFlags & TPM_NONOTIFY))
2820 SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
2821
2822 SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
2823
2824 if (!(wFlags & TPM_NONOTIFY))
2825 SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
2826
2827 return TRUE;
2828}
2829/***********************************************************************
2830 * MENU_ExitTracking
2831 */
2832static BOOL MENU_ExitTracking(HWND hWnd)
2833{
2834 //TRACE("hwnd=0x%04x\n", hWnd);
2835
2836 SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
2837 ShowCaret(0);
2838 return TRUE;
2839}
2840
2841/***********************************************************************
2842 * MENU_TrackMouseMenuBar
2843 *
2844 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2845 */
2846void MENU_TrackMouseMenuBar( HWND hWnd, INT ht, POINT pt )
2847{
2848 HMENU hMenu = (ht == 0) ? getMenu(hWnd):getSysMenu(hWnd);
2849 UINT wFlags = TPM_ENTERIDLEEX | TPM_BUTTONDOWN | TPM_LEFTALIGN | TPM_LEFTBUTTON;
2850
2851 //TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
2852
2853 if (IsMenu(hMenu))
2854 {
2855 if (ht == HTCAPTION) wFlags |= TPM_CAPTIONSYSMENU;
2856 if (IsIconic(hWnd)) wFlags |= TPM_BOTTOMALIGN; //CB: todo: for minimized windows
2857
2858 MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
2859 MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd,ht == 0, NULL );
2860 MENU_ExitTracking(hWnd);
2861 }
2862}
2863
2864
2865/***********************************************************************
2866 * MENU_TrackKbdMenuBar
2867 *
2868 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2869 */
2870void MENU_TrackKbdMenuBar( HWND hWnd, UINT wParam, INT vkey)
2871{
2872 UINT uItem = NO_SELECTED_ITEM;
2873 HMENU hTrackMenu;
2874 UINT wFlags = TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON;
2875
2876 /* find window that has a menu */
2877
2878 while(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD)
2879 if( !(hWnd = GetParent(hWnd)) ) return;
2880
2881 /* check if we have to track a system menu */
2882
2883 if( (GetWindowLongA(hWnd,GWL_STYLE) & (WS_CHILD | WS_MINIMIZE)) ||
2884 !getMenu(hWnd) || vkey == VK_SPACE )
2885 {
2886 if( !(GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) ) return;
2887 hTrackMenu = getSysMenu(hWnd);
2888 uItem = 0;
2889 wParam |= HTSYSMENU; /* prevent item lookup */
2890 }
2891 else
2892 hTrackMenu = getMenu(hWnd);
2893
2894 if (IsMenu( hTrackMenu ))
2895 {
2896 MENU_InitTracking( hWnd, hTrackMenu, FALSE, wFlags );
2897
2898 if( vkey && vkey != VK_SPACE )
2899 {
2900 uItem = MENU_FindItemByKey( hWnd, hTrackMenu,
2901 vkey, (wParam & HTSYSMENU) );
2902 if( uItem >= (UINT)(-2) )
2903 {
2904 if( uItem == (UINT)(-1) ) MessageBeep(0);
2905 hTrackMenu = 0;
2906 }
2907 }
2908
2909 if( hTrackMenu )
2910 {
2911 MENU_SelectItem( hWnd, hTrackMenu, uItem, TRUE, 0 );
2912
2913 if( uItem == NO_SELECTED_ITEM )
2914 MENU_MoveSelection( hWnd, hTrackMenu, ITEM_NEXT );
2915 else if( vkey )
2916 PostMessageA( hWnd, WM_KEYDOWN, VK_DOWN, 0L );
2917
2918 MENU_TrackMenu( hTrackMenu, wFlags, 0, 0, hWnd,TRUE, NULL );
2919 }
2920
2921 MENU_ExitTracking (hWnd);
2922 }
2923}
2924
2925
2926/**********************************************************************
2927 * TrackPopupMenu (USER32.549)
2928 *
2929 * Like the win32 API, the function return the command ID only if the
2930 * flag TPM_RETURNCMD is on.
2931 *
2932 */
2933BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
2934 INT nReserved, HWND hWnd, const RECT *lpRect )
2935{
2936 BOOL ret = FALSE;
2937
2938 dprintf(("USER32: TrackPopupMenu"));
2939
2940 MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
2941
2942 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2943 if (!(wFlags & TPM_NONOTIFY))
2944 SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
2945
2946 if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
2947 ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd,FALSE, lpRect );
2948 MENU_ExitTracking(hWnd);
2949
2950 if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
2951 ret = 1;
2952
2953 return ret;
2954}
2955
2956/**********************************************************************
2957 * TrackPopupMenuEx (USER32.550)
2958 */
2959BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
2960 HWND hWnd, LPTPMPARAMS lpTpm )
2961{
2962 dprintf(("USER32: TrackPopupMenuEx"));
2963 //FIXME("not fully implemented\n" );
2964 return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
2965 lpTpm ? &lpTpm->rcExclude : NULL );
2966}
2967
2968/***********************************************************************
2969 * PopupMenuWndProc
2970 *
2971 * NOTE: Windows has totally different (and undocumented) popup wndproc.
2972 */
2973LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
2974 LPARAM lParam )
2975{
2976 LRESULT retvalue;
2977
2978 //TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
2979 //hwnd, message, wParam, lParam);
2980
2981 switch(message)
2982 {
2983 case WM_CREATE:
2984 {
2985 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
2986 SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
2987 retvalue = 0;
2988 goto END;
2989 }
2990
2991 case WM_MOUSEACTIVATE: /* We don't want to be activated */
2992 retvalue = MA_NOACTIVATE;
2993 goto END;
2994
2995 case WM_PAINT:
2996 {
2997 PAINTSTRUCT ps;
2998 BeginPaint( hwnd, &ps );
2999 MENU_DrawPopupMenu( hwnd, ps.hdc,
3000 (HMENU)GetWindowLongA( hwnd, 0 ) );
3001 EndPaint( hwnd, &ps );
3002 retvalue = 0;
3003 goto END;
3004 }
3005 case WM_ERASEBKGND:
3006 retvalue = 1;
3007 goto END;
3008
3009 case WM_DESTROY:
3010
3011 /* zero out global pointer in case resident popup window
3012 * was somehow destroyed. */
3013
3014 if(MENU_GetTopPopupWnd() )
3015 {
3016 if( hwnd == pTopPopupWnd )
3017 {
3018 //ERR("resident popup destroyed!\n");
3019
3020 MENU_DestroyTopPopupWnd();
3021 uSubPWndLevel = 0;
3022 }
3023 else
3024 uSubPWndLevel--;
3025 MENU_ReleaseTopPopupWnd();
3026 }
3027 break;
3028
3029 case WM_SHOWWINDOW:
3030
3031 if( wParam )
3032 {
3033 //if( !(*(HMENU*)wndPtr->wExtra) )
3034 // ERR("no menu to display\n");
3035 }
3036 else
3037 SetWindowLongA(hwnd,0,0);
3038 break;
3039
3040 case MM_SETMENUHANDLE:
3041
3042 SetWindowLongA(hwnd,0,wParam);
3043 break;
3044
3045 case MM_GETMENUHANDLE:
3046
3047 retvalue = GetWindowLongA(hwnd,0);
3048 goto END;
3049
3050 default:
3051 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
3052 goto END;
3053 }
3054 retvalue = 0;
3055END:
3056 return retvalue;
3057}
3058
3059
3060/***********************************************************************
3061 * MENU_GetMenuBarHeight
3062 *
3063 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3064 */
3065UINT MENU_GetMenuBarHeight(HWND hwnd,UINT menubarWidth,INT orgX,INT orgY)
3066{
3067 HDC hdc;
3068 RECT rectBar;
3069 LPPOPUPMENU lppop;
3070 UINT retvalue;
3071
3072 //TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
3073 // hwnd, menubarWidth, orgX, orgY );
3074
3075 if (!(lppop = (LPPOPUPMENU)getMenu(hwnd)))
3076 {
3077 return 0;
3078 }
3079
3080 hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
3081 SelectObject( hdc, hMenuFont);
3082 SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
3083 MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
3084 ReleaseDC( hwnd, hdc );
3085 retvalue = lppop->Height;
3086 return retvalue;
3087}
3088
3089
3090/*******************************************************************
3091 * ChangeMenu32A (USER32.23)
3092 */
3093BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
3094 UINT id, UINT flags )
3095{
3096 dprintf(("USER32: ChangeMenuA"));
3097
3098 //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3099 // hMenu, pos, (DWORD)data, id, flags );
3100 if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
3101 id, data );
3102 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3103 if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
3104 id, data );
3105 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
3106 flags & MF_BYPOSITION ? pos : id,
3107 flags & ~MF_REMOVE );
3108 /* Default: MF_INSERT */
3109 return InsertMenuA( hMenu, pos, flags, id, data );
3110}
3111
3112
3113/*******************************************************************
3114 * ChangeMenu32W (USER32.24)
3115 */
3116BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
3117 UINT id, UINT flags )
3118{
3119 dprintf(("USER32: ChangeMenuW"));
3120
3121 //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3122 // hMenu, pos, (DWORD)data, id, flags );
3123 if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
3124 id, data );
3125 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3126 if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
3127 id, data );
3128 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
3129 flags & MF_BYPOSITION ? pos : id,
3130 flags & ~MF_REMOVE );
3131 /* Default: MF_INSERT */
3132 return InsertMenuW( hMenu, pos, flags, id, data );
3133}
3134
3135
3136/*******************************************************************
3137 * CheckMenuItem (USER32.46)
3138 */
3139DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
3140{
3141 MENUITEM *item;
3142 DWORD ret;
3143
3144 dprintf(("USER32: CheckMenuItem %x %x %x", hMenu, id, flags));
3145
3146 //TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
3147 if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
3148 ret = item->fState & MF_CHECKED;
3149 if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
3150 else item->fState &= ~MF_CHECKED;
3151 return ret;
3152}
3153
3154
3155/**********************************************************************
3156 * EnableMenuItem32 (USER32.170)
3157 */
3158ULONG WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
3159{
3160 UINT oldflags;
3161 MENUITEM *item;
3162 POPUPMENU *menu;
3163
3164 dprintf(("USER32: EnableMenuItem %x %x %x", hMenu, wItemID, wFlags));
3165
3166 //TRACE("(%04x, %04X, %04X) !\n",
3167 // hMenu, wItemID, wFlags);
3168
3169 /* Get the Popupmenu to access the owner menu */
3170 if (!(menu = (POPUPMENU*)hMenu))
3171 return (UINT)-1;
3172
3173 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
3174 return (UINT)-1;
3175
3176 oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
3177 item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
3178
3179 /* In win95 if the close item in the system menu change update the close button */
3180 if((item->wID == SC_CLOSE) && (oldflags != wFlags))
3181 {
3182 if (menu->hSysMenuOwner != 0)
3183 {
3184 POPUPMENU* parentMenu;
3185
3186 /* Get the parent menu to access*/
3187 if (!(parentMenu = (POPUPMENU*)menu->hSysMenuOwner))
3188 return (UINT)-1;
3189
3190 /* Refresh the frame to reflect the change*/
3191 SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
3192 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
3193 }
3194 }
3195
3196 return oldflags;
3197}
3198
3199
3200/*******************************************************************
3201 * GetMenuString32A (USER32.268)
3202 */
3203INT WINAPI GetMenuStringA( HMENU hMenu, UINT wItemID,
3204 LPSTR str, INT nMaxSiz, UINT wFlags )
3205{
3206 MENUITEM *item;
3207
3208 dprintf(("USER32: GetMenuStringA"));
3209
3210 //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3211 // hMenu, wItemID, str, nMaxSiz, wFlags );
3212 if (!str || !nMaxSiz) return 0;
3213 str[0] = '\0';
3214 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
3215 if (!IS_STRING_ITEM(item->fType)) return 0;
3216 lstrcpynA( str, item->text, nMaxSiz );
3217 //TRACE("returning '%s'\n", str );
3218 return strlen(str);
3219}
3220
3221
3222/*******************************************************************
3223 * GetMenuString32W (USER32.269)
3224 */
3225INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
3226 LPWSTR str, INT nMaxSiz, UINT wFlags )
3227{
3228 MENUITEM *item;
3229
3230 dprintf(("USER32: GetMenuStringW"));
3231
3232 //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3233 // hMenu, wItemID, str, nMaxSiz, wFlags );
3234 if (!str || !nMaxSiz) return 0;
3235 str[0] = '\0';
3236 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
3237 if (!IS_STRING_ITEM(item->fType)) return 0;
3238 lstrcpynAtoW( str, item->text, nMaxSiz );
3239 return lstrlenW(str);
3240}
3241
3242
3243/**********************************************************************
3244 * HiliteMenuItem32 (USER32.318)
3245 */
3246BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
3247 UINT wHilite )
3248{
3249 LPPOPUPMENU menu;
3250
3251 dprintf(("USER32: HiliteMenuItem"));
3252
3253 //TRACE("(%04x, %04x, %04x, %04x);\n",
3254 // hWnd, hMenu, wItemID, wHilite);
3255 if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
3256 if (!(menu = (LPPOPUPMENU)hMenu)) return FALSE;
3257 if (menu->FocusedItem == wItemID) return TRUE;
3258 MENU_HideSubPopups( hWnd, hMenu, FALSE );
3259 MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 );
3260 return TRUE;
3261}
3262
3263
3264/**********************************************************************
3265 * GetMenuState (USER32.267)
3266 */
3267UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
3268{
3269 MENUITEM *item;
3270
3271 dprintf(("USER32: GetMenuState %d %d",wItemID,wFlags));
3272
3273 //TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
3274 // hMenu, wItemID, wFlags);
3275
3276 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
3277
3278 //debug_print_menuitem (" item: ", item, "");
3279 if (item->fType & MF_POPUP)
3280 {
3281 POPUPMENU *menu = (POPUPMENU*)item->hSubMenu;
3282 if (!menu) return -1;
3283 else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
3284 }
3285 else
3286 {
3287 /* We used to (from way back then) mask the result to 0xff. */
3288 /* I don't know why and it seems wrong as the documented */
3289 /* return flag MF_SEPARATOR is outside that mask. */
3290 return (item->fType | item->fState);
3291 }
3292}
3293
3294
3295/**********************************************************************
3296 * GetMenuItemCount32 (USER32.262)
3297 */
3298INT WINAPI GetMenuItemCount( HMENU hMenu )
3299{
3300 LPPOPUPMENU menu = (LPPOPUPMENU)hMenu;
3301
3302 dprintf(("USER32: GetMenuItemCount"));
3303
3304 if (!IS_A_MENU(menu)) return -1;
3305 //TRACE("(%04x) returning %d\n",
3306 // hMenu, menu->nItems );
3307 return menu->nItems;
3308}
3309
3310/**********************************************************************
3311 * GetMenuItemID32 (USER32.263)
3312 */
3313UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
3314{
3315 MENUITEM * lpmi;
3316
3317 dprintf(("USER32: GetMenuItemID"));
3318
3319 if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
3320 if (lpmi->fType & MF_POPUP) return -1;
3321 return lpmi->wID;
3322
3323}
3324
3325/*******************************************************************
3326 * InsertMenu32A (USER32.322)
3327 */
3328BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
3329 UINT id, LPCSTR str )
3330{
3331 MENUITEM *item;
3332
3333 if (IS_STRING_ITEM(flags) && str)
3334 dprintf(("USER32: InsertMenuA %x %d %x %d %s", hMenu, pos, flags, id, str));
3335 // TRACE("hMenu %04x, pos %d, flags %08x, "
3336 // "id %04x, str '%s'\n",
3337 // hMenu, pos, flags, id, str );
3338 else // TRACE("hMenu %04x, pos %d, flags %08x, "
3339 dprintf(("USER32: InsertMenuA %x %d %x %d %x", hMenu, pos, flags, id, str));
3340 // "id %04x, str %08lx (not a string)\n",
3341 // hMenu, pos, flags, id, (DWORD)str );
3342
3343 if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
3344
3345 if (!(MENU_SetItemData( item, flags, id, str )))
3346 {
3347 RemoveMenu( hMenu, pos, flags );
3348 return FALSE;
3349 }
3350
3351 if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
3352 ((POPUPMENU *)(HMENU)id)->wFlags |= MF_POPUP;
3353
3354 item->hCheckBit = item->hUnCheckBit = 0;
3355 return TRUE;
3356}
3357
3358
3359/*******************************************************************
3360 * InsertMenu32W (USER32.325)
3361 */
3362BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
3363 UINT id, LPCWSTR str )
3364{
3365 BOOL ret;
3366
3367 if (IS_STRING_ITEM(flags) && str)
3368 {
3369 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
3370 ret = InsertMenuA( hMenu, pos, flags, id, newstr );
3371 HeapFree( GetProcessHeap(), 0, newstr );
3372 return ret;
3373 }
3374 else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
3375}
3376
3377
3378/*******************************************************************
3379 * AppendMenu32A (USER32.5)
3380 */
3381BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
3382 UINT id, LPCSTR data )
3383{
3384 dprintf(("USER32: AppendMenuA"));
3385
3386 return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
3387}
3388
3389
3390/*******************************************************************
3391 * AppendMenu32W (USER32.6)
3392 */
3393BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
3394 UINT id, LPCWSTR data )
3395{
3396 dprintf(("USER32: AppendMenuW %x %x %d %x", hMenu, flags, id, data));
3397
3398 return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
3399}
3400
3401
3402/**********************************************************************
3403 * RemoveMenu (USER32.441)
3404 */
3405BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
3406{
3407 LPPOPUPMENU menu;
3408 MENUITEM *item;
3409
3410 dprintf(("USER32: RemoveMenu %x %d %x", hMenu, nPos, wFlags));
3411
3412 //TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
3413 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
3414 if (!(menu = (LPPOPUPMENU)hMenu)) return FALSE;
3415
3416 /* Remove item */
3417
3418 MENU_FreeItemData( item );
3419
3420 if (--menu->nItems == 0)
3421 {
3422 HeapFree(GetProcessHeap(), 0, menu->items );
3423 menu->items = NULL;
3424 }
3425 else
3426 {
3427 while(nPos < menu->nItems)
3428 {
3429 *item = *(item+1);
3430 item++;
3431 nPos++;
3432 }
3433 menu->items = (MENUITEM*)HeapReAlloc(GetProcessHeap(), 0, menu->items,
3434 menu->nItems * sizeof(MENUITEM) );
3435 }
3436 return TRUE;
3437}
3438
3439
3440/**********************************************************************
3441 * DeleteMenu32 (USER32.129)
3442 */
3443BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
3444{
3445 MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
3446
3447 dprintf(("USER32: DeleteMenu %x %d %x", hMenu, nPos, wFlags));
3448
3449 if (!item) return FALSE;
3450 if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
3451 /* nPos is now the position of the item */
3452 RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
3453 return TRUE;
3454}
3455
3456
3457/*******************************************************************
3458 * ModifyMenu32A (USER32.397)
3459 */
3460BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
3461 UINT id, LPCSTR str )
3462{
3463 MENUITEM *item;
3464
3465
3466 if (IS_STRING_ITEM(flags))
3467 {
3468 dprintf(("USER32: ModifyMenuA, %x %d %x %d %s", hMenu, pos, flags, id, str));
3469 //TRACE("%04x %d %04x %04x '%s'\n",
3470 // hMenu, pos, flags, id, str ? str : "#NULL#" );
3471 if (!str) return FALSE;
3472 }
3473 else
3474 {
3475 dprintf(("USER32: ModifyMenuA, %x %d %x %d %x", hMenu, pos, flags, id, str));
3476 //TRACE("%04x %d %04x %04x %08lx\n",
3477 // hMenu, pos, flags, id, (DWORD)str );
3478 }
3479
3480 if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
3481 return MENU_SetItemData( item, flags, id, str );
3482}
3483
3484
3485/*******************************************************************
3486 * ModifyMenu32W (USER32.398)
3487 */
3488BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
3489 UINT id, LPCWSTR str )
3490{
3491 BOOL ret;
3492
3493 if (IS_STRING_ITEM(flags) && str)
3494 {
3495 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
3496 ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
3497 HeapFree( GetProcessHeap(), 0, newstr );
3498 return ret;
3499 }
3500 else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
3501}
3502
3503
3504/**********************************************************************
3505 * CreatePopupMenu32 (USER32.82)
3506 */
3507HMENU WINAPI CreatePopupMenu(void)
3508{
3509 HMENU hmenu;
3510 POPUPMENU *menu;
3511
3512 dprintf(("USER32: CreatePopupMenu"));
3513
3514 if (!(hmenu = CreateMenu())) return 0;
3515 menu = (POPUPMENU*)hmenu;
3516 menu->wFlags |= MF_POPUP;
3517 menu->bTimeToHide = FALSE;
3518 return hmenu;
3519}
3520
3521
3522/**********************************************************************
3523 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
3524 */
3525DWORD WINAPI GetMenuCheckMarkDimensions(void)
3526{
3527 dprintf(("USER32: GetMenuCheckMarkDimensions"));
3528
3529 return MAKELONG( check_bitmap_width, check_bitmap_height );
3530}
3531
3532
3533/**********************************************************************
3534 * SetMenuItemBitmaps32 (USER32.490)
3535 */
3536BOOL WINAPI SetMenuItemBitmaps(HMENU hMenu, UINT nPos, UINT wFlags,
3537 HBITMAP hNewUnCheck, HBITMAP hNewCheck)
3538{
3539 MENUITEM *item;
3540
3541 dprintf(("USER32: SetMenuItemBitmaps %x %d %x %x %x", hMenu, nPos, wFlags, hNewCheck, hNewUnCheck));
3542
3543 //TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
3544 // hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
3545 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
3546
3547 if (!hNewCheck && !hNewUnCheck)
3548 {
3549 item->fState &= ~MF_USECHECKBITMAPS;
3550 }
3551 else /* Install new bitmaps */
3552 {
3553 item->hCheckBit = hNewCheck;
3554 item->hUnCheckBit = hNewUnCheck;
3555 item->fState |= MF_USECHECKBITMAPS;
3556 }
3557 return TRUE;
3558}
3559
3560
3561/**********************************************************************
3562 * CreateMenu (USER32.81)
3563 */
3564HMENU WINAPI CreateMenu(void)
3565{
3566 HMENU hMenu;
3567 LPPOPUPMENU menu;
3568
3569 dprintf(("USER32: CreateMenu"));
3570
3571 if (!(hMenu = (HMENU)HeapAlloc(GetProcessHeap(),0,sizeof(POPUPMENU)))) return 0;
3572 menu = (LPPOPUPMENU)hMenu;
3573
3574 ZeroMemory(menu, sizeof(POPUPMENU));
3575 menu->wMagic = MENU_MAGIC;
3576 menu->FocusedItem = NO_SELECTED_ITEM;
3577 menu->bTimeToHide = FALSE;
3578
3579 //TRACE("return %04x\n", hMenu );
3580
3581 return hMenu;
3582}
3583
3584
3585/**********************************************************************
3586 * DestroyMenu32 (USER32.134)
3587 */
3588BOOL WINAPI DestroyMenu( HMENU hMenu )
3589{
3590 //TRACE("(%04x)\n", hMenu);
3591
3592 dprintf(("USER32: DestroyMenu %x", hMenu));
3593
3594 /* Silently ignore attempts to destroy default system popup */
3595
3596 if (hMenu && hMenu != MENU_DefSysPopup)
3597 {
3598 LPPOPUPMENU lppop = (LPPOPUPMENU)hMenu;
3599 HWND pTPWnd = MENU_GetTopPopupWnd();
3600
3601 if( pTPWnd && (hMenu == GetWindowLongA(pTPWnd,0)) )
3602 SetWindowLongA(pTPWnd,0,0);
3603
3604 if (IS_A_MENU( lppop ))
3605 {
3606 lppop->wMagic = 0; /* Mark it as destroyed */
3607
3608 if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
3609 (!pTPWnd || (lppop->hWnd != pTPWnd)))
3610 DestroyWindow( lppop->hWnd );
3611
3612 if (lppop->items) /* recursively destroy submenus */
3613 {
3614 int i;
3615 MENUITEM *item = lppop->items;
3616 for (i = lppop->nItems; i > 0; i--, item++)
3617 {
3618 if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
3619 MENU_FreeItemData( item );
3620 }
3621 HeapFree(GetProcessHeap(), 0, lppop->items );
3622 }
3623 HeapFree(GetProcessHeap(),0,(LPVOID)hMenu);
3624 MENU_ReleaseTopPopupWnd();
3625 }
3626 else
3627 {
3628 MENU_ReleaseTopPopupWnd();
3629 return FALSE;
3630 }
3631 }
3632 return (hMenu != MENU_DefSysPopup);
3633}
3634
3635/**********************************************************************
3636 * GetSystemMenu32 (USER32.291)
3637 */
3638HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
3639{
3640 HMENU retvalue = 0;
3641 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
3642
3643 dprintf(("USER32: GetSystemMenu"));
3644
3645 if (win32wnd)
3646 {
3647 HMENU hSysMenu = getSysMenu(hWnd);
3648 if(hSysMenu)
3649 {
3650 if( bRevert )
3651 {
3652 DestroyMenu(hSysMenu);
3653 hSysMenu = 0;
3654 setSysMenu(hWnd,hSysMenu);
3655 }
3656 else
3657 {
3658 POPUPMENU *menu = (POPUPMENU*)hSysMenu;
3659 if( IS_A_MENU(menu) )
3660 {
3661 if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
3662 menu->items[0].hSubMenu = MENU_CopySysPopup();
3663 }
3664 else
3665 {
3666 //WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
3667 // wndPtr->hSysMenu, hWnd);
3668 hSysMenu = 0;
3669 setSysMenu(hWnd,hSysMenu);
3670 }
3671 }
3672 }
3673
3674 if(!hSysMenu && (GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) )
3675 {
3676 hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
3677 setSysMenu(hWnd,hSysMenu);
3678 }
3679
3680 if( hSysMenu )
3681 {
3682 POPUPMENU *menu;
3683 retvalue = GetSubMenu(hSysMenu, 0);
3684
3685 /* Store the dummy sysmenu handle to facilitate the refresh */
3686 /* of the close button if the SC_CLOSE item change */
3687 menu = (POPUPMENU*)retvalue;
3688 if ( IS_A_MENU(menu) )
3689 menu->hSysMenuOwner = hSysMenu;
3690 }
3691 }
3692 return retvalue;
3693}
3694
3695
3696/*******************************************************************
3697 * SetSystemMenu32 (USER32.508)
3698 */
3699BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
3700{
3701 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
3702
3703 dprintf(("USER32: SetSystemMenu"));
3704
3705 if (win32wnd)
3706 {
3707 if (win32wnd->GetSysMenu()) DestroyMenu(win32wnd->GetSysMenu());
3708 win32wnd->SetSysMenu(MENU_GetSysMenu( hwnd, hMenu ));
3709 return TRUE;
3710 }
3711 return FALSE;
3712}
3713
3714/**********************************************************************
3715 * GetMenu32 (USER32.257)
3716 */
3717HMENU WINAPI GetMenu( HWND hWnd )
3718{
3719 HMENU retvalue;
3720
3721 dprintf(("USER32: GetMenu %x", hWnd));
3722
3723 if (GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) return 0;
3724 else return getMenu(hWnd);
3725}
3726
3727/**********************************************************************
3728 * SetMenu32 (USER32.487)
3729 */
3730BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
3731{
3732 //TRACE("(%04x, %04x);\n", hWnd, hMenu);
3733
3734 dprintf(("USER32: SetMenu %x %x", hWnd, hMenu));
3735
3736 if (hMenu && !IsMenu(hMenu))
3737 {
3738 //WARN("hMenu is not a menu handle\n");
3739 return FALSE;
3740 }
3741
3742
3743 if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD))
3744 {
3745 if (GetCapture() == hWnd) ReleaseCapture();
3746
3747 setMenu(hWnd,hMenu);
3748 if (hMenu != 0)
3749 {
3750 LPPOPUPMENU lpmenu;
3751
3752 if (!(lpmenu = (LPPOPUPMENU)hMenu))
3753 {
3754 return FALSE;
3755 }
3756 lpmenu->hWnd = hWnd;
3757 lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
3758 lpmenu->Height = 0; /* Make sure we recalculate the size */
3759 }
3760 if (IsWindowVisible(hWnd))
3761 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
3762 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
3763 return TRUE;
3764 }
3765 return FALSE;
3766}
3767
3768
3769/**********************************************************************
3770 * GetSubMenu32 (USER32.288)
3771 */
3772HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
3773{
3774 MENUITEM * lpmi;
3775
3776 dprintf(("USER32: GetSubMenu %x %d", nPos));
3777
3778 if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
3779 if (!(lpmi->fType & MF_POPUP)) return 0;
3780 return lpmi->hSubMenu;
3781}
3782
3783
3784/**********************************************************************
3785 * DrawMenuBar (USER32.161)
3786 */
3787BOOL WINAPI DrawMenuBar( HWND hWnd )
3788{
3789 LPPOPUPMENU lppop;
3790
3791 dprintf(("USER32: DrawMenuBar %x", hWnd));
3792
3793 if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) && getMenu(hWnd))
3794 {
3795 lppop = (LPPOPUPMENU)getMenu(hWnd);
3796 if (lppop == NULL)
3797 {
3798 return FALSE;
3799 }
3800
3801 lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
3802 lppop->hwndOwner = hWnd;
3803 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
3804 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
3805 return TRUE;
3806 }
3807 return FALSE;
3808}
3809
3810
3811/***********************************************************************
3812 * EndMenu (USER.187) (USER32.175)
3813 */
3814void WINAPI EndMenu(void)
3815{
3816 dprintf(("USER32: EndMenu not implemented!"));
3817 /*
3818 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
3819 */
3820
3821 fEndMenu = TRUE;
3822}
3823
3824
3825/*****************************************************************
3826 * LoadMenu32A (USER32.370)
3827 */
3828HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
3829{
3830 HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
3831
3832 dprintf(("USER32: LoadMenuA %x %x", instance, name));
3833
3834 if (!hrsrc) return 0;
3835 return LoadMenuIndirectA( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
3836}
3837
3838
3839/*****************************************************************
3840 * LoadMenu32W (USER32.373)
3841 */
3842HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
3843{
3844 HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
3845
3846 dprintf(("USER32: LoadMenuW %x %x", instance, name));
3847
3848 if (!hrsrc) return 0;
3849 return LoadMenuIndirectW( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
3850}
3851
3852
3853/**********************************************************************
3854 * LoadMenuIndirect32A (USER32.371)
3855 */
3856HMENU WINAPI LoadMenuIndirectA(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate)
3857{
3858 HMENU hMenu;
3859 WORD version, offset;
3860 LPCSTR p = (LPCSTR)lpMenuTemplate;
3861
3862 dprintf(("USER32: LoadMenuIndirectA"));
3863
3864 //TRACE("%p\n", template );
3865 version = GET_WORD(p);
3866 p += sizeof(WORD);
3867 switch (version)
3868 {
3869 case 0:
3870 offset = GET_WORD(p);
3871 p += sizeof(WORD) + offset;
3872 if (!(hMenu = CreateMenu())) return 0;
3873 if (!MENU_ParseResource( p, hMenu, TRUE ))
3874 {
3875 DestroyMenu( hMenu );
3876 return 0;
3877 }
3878 return hMenu;
3879 case 1:
3880 offset = GET_WORD(p);
3881 p += sizeof(WORD) + offset;
3882 if (!(hMenu = CreateMenu())) return 0;
3883 if (!MENUEX_ParseResource( p, hMenu))
3884 {
3885 DestroyMenu( hMenu );
3886 return 0;
3887 }
3888 return hMenu;
3889 default:
3890 //ERR("version %d not supported.\n", version);
3891 return 0;
3892 }
3893}
3894
3895
3896/**********************************************************************
3897 * LoadMenuIndirect32W (USER32.372)
3898 */
3899HMENU WINAPI LoadMenuIndirectW(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate )
3900{
3901 dprintf(("USER32: LoadMenuIndirectW"));
3902
3903 /* FIXME: is there anything different between A and W? */
3904 return LoadMenuIndirectA(lpMenuTemplate);
3905}
3906
3907
3908/**********************************************************************
3909 * IsMenu32 (USER32.346)
3910 */
3911BOOL WINAPI IsMenu(HMENU hmenu)
3912{
3913 LPPOPUPMENU menu = (LPPOPUPMENU)hmenu;
3914
3915 dprintf(("USER32: IsMenu"));
3916
3917 return IS_A_MENU(menu);
3918}
3919
3920/**********************************************************************
3921 * GetMenuItemInfo32_common
3922 */
3923
3924static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
3925 LPMENUITEMINFOA lpmii, BOOL unicode)
3926{
3927 MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
3928
3929 //debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
3930
3931 if (!menu)
3932 return FALSE;
3933
3934 if (lpmii->fMask & MIIM_TYPE) {
3935 lpmii->fType = menu->fType;
3936 switch (MENU_ITEM_TYPE(menu->fType)) {
3937 case MF_STRING:
3938 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
3939 if (unicode) {
3940 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
3941 lpmii->cch = lstrlenW((LPWSTR)menu->text);
3942 } else {
3943 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
3944 lpmii->cch = lstrlenA(menu->text);
3945 }
3946 }
3947 break;
3948 case MF_OWNERDRAW:
3949 case MF_BITMAP:
3950 lpmii->dwTypeData = menu->text;
3951 /* fall through */
3952 default:
3953 lpmii->cch = 0;
3954 }
3955 }
3956
3957 if (lpmii->fMask & MIIM_STRING) {
3958 if (unicode) {
3959 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
3960 lpmii->cch = lstrlenW((LPWSTR)menu->text);
3961 } else {
3962 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
3963 lpmii->cch = lstrlenA(menu->text);
3964 }
3965 }
3966
3967 if (lpmii->fMask & MIIM_FTYPE)
3968 lpmii->fType = menu->fType;
3969
3970 if (lpmii->fMask & MIIM_BITMAP)
3971 lpmii->hbmpItem = menu->hbmpItem;
3972
3973 if (lpmii->fMask & MIIM_STATE)
3974 lpmii->fState = menu->fState;
3975
3976 if (lpmii->fMask & MIIM_ID)
3977 lpmii->wID = menu->wID;
3978
3979 if (lpmii->fMask & MIIM_SUBMENU)
3980 lpmii->hSubMenu = menu->hSubMenu;
3981
3982 if (lpmii->fMask & MIIM_CHECKMARKS) {
3983 lpmii->hbmpChecked = menu->hCheckBit;
3984 lpmii->hbmpUnchecked = menu->hUnCheckBit;
3985 }
3986 if (lpmii->fMask & MIIM_DATA)
3987 lpmii->dwItemData = menu->dwItemData;
3988
3989 return TRUE;
3990}
3991
3992/**********************************************************************
3993 * GetMenuItemInfoA (USER32.264)
3994 */
3995BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
3996 LPMENUITEMINFOA lpmii)
3997{
3998 dprintf(("USER32: GetMenuItemInfoA"));
3999
4000 return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
4001}
4002
4003/**********************************************************************
4004 * GetMenuItemInfoW (USER32.265)
4005 */
4006BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
4007 LPMENUITEMINFOW lpmii)
4008{
4009 dprintf(("USER32: GetMenuItemInfoW"));
4010
4011 return GetMenuItemInfo_common (hmenu, item, bypos,
4012 (LPMENUITEMINFOA)lpmii, TRUE);
4013}
4014
4015/**********************************************************************
4016 * SetMenuItemInfo32_common
4017 */
4018
4019static BOOL SetMenuItemInfo_common(MENUITEM * menu,
4020 const MENUITEMINFOA *lpmii,
4021 BOOL unicode)
4022{
4023 if (!menu) return FALSE;
4024
4025 if (lpmii->fMask & MIIM_TYPE ) {
4026 /* Get rid of old string. */
4027 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4028 HeapFree(GetProcessHeap(), 0, menu->text);
4029 menu->text = NULL;
4030 }
4031
4032 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4033 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4034 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4035
4036 menu->text = lpmii->dwTypeData;
4037
4038 if (IS_STRING_ITEM(menu->fType) && menu->text) {
4039 if (unicode)
4040 menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
4041 else
4042 menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
4043 }
4044 }
4045
4046 if (lpmii->fMask & MIIM_FTYPE ) {
4047 /* free the string when the type is changing */
4048 if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
4049 HeapFree(GetProcessHeap(), 0, menu->text);
4050 menu->text = NULL;
4051 }
4052 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4053 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4054 }
4055
4056 if (lpmii->fMask & MIIM_STRING ) {
4057 /* free the string when used */
4058 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4059 HeapFree(GetProcessHeap(), 0, menu->text);
4060 if (unicode)
4061 menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
4062 else
4063 menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
4064 }
4065 }
4066
4067 if (lpmii->fMask & MIIM_STATE)
4068 {
4069 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
4070 menu->fState = lpmii->fState;
4071 }
4072
4073 if (lpmii->fMask & MIIM_ID)
4074 menu->wID = lpmii->wID;
4075
4076 if (lpmii->fMask & MIIM_SUBMENU) {
4077 menu->hSubMenu = lpmii->hSubMenu;
4078 if (menu->hSubMenu) {
4079 POPUPMENU *subMenu = (POPUPMENU*)(UINT)menu->hSubMenu;
4080 if (IS_A_MENU(subMenu)) {
4081 subMenu->wFlags |= MF_POPUP;
4082 menu->fType |= MF_POPUP;
4083 }
4084 else
4085 /* FIXME: Return an error ? */
4086 menu->fType &= ~MF_POPUP;
4087 }
4088 else
4089 menu->fType &= ~MF_POPUP;
4090 }
4091
4092 if (lpmii->fMask & MIIM_CHECKMARKS)
4093 {
4094 menu->hCheckBit = lpmii->hbmpChecked;
4095 menu->hUnCheckBit = lpmii->hbmpUnchecked;
4096 }
4097 if (lpmii->fMask & MIIM_DATA)
4098 menu->dwItemData = lpmii->dwItemData;
4099
4100 //debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
4101 return TRUE;
4102}
4103
4104/**********************************************************************
4105 * SetMenuItemInfo32A (USER32.491)
4106 */
4107BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
4108 const MENUITEMINFOA *lpmii)
4109{
4110 dprintf(("USER32: SetMenuItemInfoA"));
4111
4112 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4113 lpmii, FALSE);
4114}
4115
4116/**********************************************************************
4117 * SetMenuItemInfo32W (USER32.492)
4118 */
4119BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
4120 const MENUITEMINFOW *lpmii)
4121{
4122 dprintf(("USER32: SetMenuItemInfoW"));
4123
4124 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4125 (const MENUITEMINFOA*)lpmii, TRUE);
4126}
4127
4128/**********************************************************************
4129 * SetMenuDefaultItem (USER32.489)
4130 *
4131 */
4132BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
4133{
4134 UINT i;
4135 POPUPMENU *menu;
4136 MENUITEM *item;
4137
4138
4139 dprintf(("USER32: SetMenuDefaultItem"));
4140 //TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
4141
4142 if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
4143
4144 /* reset all default-item flags */
4145 item = menu->items;
4146 for (i = 0; i < menu->nItems; i++, item++)
4147 {
4148 item->fState &= ~MFS_DEFAULT;
4149 }
4150
4151 /* no default item */
4152 if ( -1 == uItem)
4153 {
4154 return TRUE;
4155 }
4156
4157 item = menu->items;
4158 if ( bypos )
4159 {
4160 if ( uItem >= menu->nItems ) return FALSE;
4161 item[uItem].fState |= MFS_DEFAULT;
4162 return TRUE;
4163 }
4164 else
4165 {
4166 for (i = 0; i < menu->nItems; i++, item++)
4167 {
4168 if (item->wID == uItem)
4169 {
4170 item->fState |= MFS_DEFAULT;
4171 return TRUE;
4172 }
4173 }
4174
4175 }
4176 return FALSE;
4177}
4178
4179/**********************************************************************
4180 * GetMenuDefaultItem (USER32.260)
4181 */
4182UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
4183{
4184 POPUPMENU *menu;
4185 MENUITEM * item;
4186 UINT i = 0;
4187
4188 dprintf(("USER32: GetMenuDefaultItem"));
4189 //TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
4190
4191 if (!(menu = (POPUPMENU*)hmenu)) return -1;
4192
4193 /* find default item */
4194 item = menu->items;
4195
4196 /* empty menu */
4197 if (! item) return -1;
4198
4199 while ( !( item->fState & MFS_DEFAULT ) )
4200 {
4201 i++; item++;
4202 if (i >= menu->nItems ) return -1;
4203 }
4204
4205 /* default: don't return disabled items */
4206 if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
4207
4208 /* search rekursiv when needed */
4209 if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
4210 {
4211 UINT ret;
4212 ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
4213 if ( -1 != ret ) return ret;
4214
4215 /* when item not found in submenu, return the popup item */
4216 }
4217 return ( bypos ) ? i : item->wID;
4218
4219}
4220
4221/**********************************************************************
4222 * InsertMenuItem32A (USER32.323)
4223 */
4224BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
4225 const MENUITEMINFOA *lpmii)
4226{
4227 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
4228
4229 dprintf(("USER32: InsertMenuItemA"));
4230
4231 return SetMenuItemInfo_common(item, lpmii, FALSE);
4232}
4233
4234
4235/**********************************************************************
4236 * InsertMenuItem32W (USER32.324)
4237 */
4238BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
4239 const MENUITEMINFOW *lpmii)
4240{
4241 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
4242
4243 dprintf(("USER32: InsertMenuItemW"));
4244
4245 return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
4246}
4247
4248/**********************************************************************
4249 * CheckMenuRadioItem32 (USER32.47)
4250 */
4251
4252BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
4253 UINT first, UINT last, UINT check,
4254 UINT bypos)
4255{
4256 MENUITEM *mifirst, *milast, *micheck;
4257 HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
4258
4259 dprintf(("USER32: CheckMenuRadioItem"));
4260 //TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
4261 // hMenu, first, last, check, bypos);
4262
4263 mifirst = MENU_FindItem (&mfirst, &first, bypos);
4264 milast = MENU_FindItem (&mlast, &last, bypos);
4265 micheck = MENU_FindItem (&mcheck, &check, bypos);
4266
4267 if (mifirst == NULL || milast == NULL || micheck == NULL ||
4268 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
4269 micheck > milast || micheck < mifirst)
4270 return FALSE;
4271
4272 while (mifirst <= milast)
4273 {
4274 if (mifirst == micheck)
4275 {
4276 mifirst->fType |= MFT_RADIOCHECK;
4277 mifirst->fState |= MFS_CHECKED;
4278 } else {
4279 mifirst->fType &= ~MFT_RADIOCHECK;
4280 mifirst->fState &= ~MFS_CHECKED;
4281 }
4282 mifirst++;
4283 }
4284
4285 return TRUE;
4286}
4287
4288/**********************************************************************
4289 * GetMenuItemRect32 (USER32.266)
4290 *
4291 * ATTENTION: Here, the returned values in rect are the screen
4292 * coordinates of the item just like if the menu was
4293 * always on the upper left side of the application.
4294 *
4295 */
4296BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
4297 LPRECT rect)
4298{
4299 POPUPMENU *itemMenu;
4300 MENUITEM *item;
4301 HWND referenceHwnd;
4302
4303 dprintf(("USER32: GetMenuItemRect"));
4304 //TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
4305
4306 item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
4307 referenceHwnd = hwnd;
4308
4309 if(!hwnd)
4310 {
4311 itemMenu = (POPUPMENU*)hMenu;
4312 if (itemMenu == NULL)
4313 return FALSE;
4314
4315 if(itemMenu->hWnd == 0)
4316 return FALSE;
4317 referenceHwnd = itemMenu->hWnd;
4318 }
4319
4320 if ((rect == NULL) || (item == NULL))
4321 return FALSE;
4322
4323 *rect = item->rect;
4324
4325 MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
4326
4327 return TRUE;
4328}
4329
4330/**********************************************************************
4331 * SetMenuInfo
4332 *
4333 * FIXME
4334 * MIM_APPLYTOSUBMENUS
4335 * actually use the items to draw the menu
4336 */
4337BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
4338{
4339 POPUPMENU *menu;
4340
4341 dprintf(("USER32: SetMenuInfo"));
4342 //TRACE("(0x%04x %p)\n", hMenu, lpmi);
4343
4344 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)hMenu))
4345 {
4346
4347 if (lpmi->fMask & MIM_BACKGROUND)
4348 menu->hbrBack = lpmi->hbrBack;
4349
4350 if (lpmi->fMask & MIM_HELPID)
4351 menu->dwContextHelpID = lpmi->dwContextHelpID;
4352
4353 if (lpmi->fMask & MIM_MAXHEIGHT)
4354 menu->cyMax = lpmi->cyMax;
4355
4356 if (lpmi->fMask & MIM_MENUDATA)
4357 menu->dwMenuData = lpmi->dwMenuData;
4358
4359 if (lpmi->fMask & MIM_STYLE)
4360 menu->dwStyle = lpmi->dwStyle;
4361
4362 return TRUE;
4363 }
4364 return FALSE;
4365}
4366
4367/**********************************************************************
4368 * GetMenuInfo
4369 *
4370 * NOTES
4371 * win98/NT5.0
4372 *
4373 */
4374BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
4375{ POPUPMENU *menu;
4376
4377 dprintf(("USER32: GetMenuInfo"));
4378 //TRACE("(0x%04x %p)\n", hMenu, lpmi);
4379
4380 if (lpmi && (menu = (POPUPMENU*)hMenu))
4381 {
4382
4383 if (lpmi->fMask & MIM_BACKGROUND)
4384 lpmi->hbrBack = menu->hbrBack;
4385
4386 if (lpmi->fMask & MIM_HELPID)
4387 lpmi->dwContextHelpID = menu->dwContextHelpID;
4388
4389 if (lpmi->fMask & MIM_MAXHEIGHT)
4390 lpmi->cyMax = menu->cyMax;
4391
4392 if (lpmi->fMask & MIM_MENUDATA)
4393 lpmi->dwMenuData = menu->dwMenuData;
4394
4395 if (lpmi->fMask & MIM_STYLE)
4396 lpmi->dwStyle = menu->dwStyle;
4397
4398 return TRUE;
4399 }
4400 return FALSE;
4401}
4402
4403/**********************************************************************
4404 * SetMenuContextHelpId (USER32.488)
4405 */
4406BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
4407{
4408 LPPOPUPMENU menu;
4409
4410 dprintf(("USER32: SetMenuContextHelpId"));
4411 //TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
4412
4413 menu = (POPUPMENU*)hMenu;
4414 if (menu)
4415 {
4416 menu->dwContextHelpID = dwContextHelpID;
4417 return TRUE;
4418 }
4419 return FALSE;
4420}
4421
4422/**********************************************************************
4423 * GetMenuContextHelpId (USER32.488)
4424 */
4425DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
4426{
4427 LPPOPUPMENU menu;
4428
4429 dprintf(("USER32: GetMenuContextHelpId"));
4430 //TRACE("(0x%04x)\n", hMenu);
4431
4432 menu = (POPUPMENU*)hMenu;
4433 if (menu)
4434 {
4435 return menu->dwContextHelpID;
4436 }
4437 return 0;
4438}
4439
4440/**********************************************************************
4441 * MenuItemFromPoint (USER32.387)
4442 */
4443UINT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen)
4444{
4445 dprintf(("USER32: MenuItemFromPoint not implemented!"));
4446 //FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
4447 // hWnd, hMenu, ptScreen.x, ptScreen.y);
4448 return 0;
4449}
4450
4451BOOL POPUPMENU_Register()
4452{
4453 WNDCLASSA wndClass;
4454 BOOL rc;
4455
4456//SvL: Don't check this now
4457// if (GlobalFindAtomA(POPUPMENUCLASSNAME)) return FALSE;
4458
4459 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
4460 wndClass.style = CS_GLOBALCLASS | CS_SAVEBITS;
4461 wndClass.lpfnWndProc = (WNDPROC)PopupMenuWndProc;
4462 wndClass.cbClsExtra = 0;
4463 wndClass.cbWndExtra = sizeof(HMENU);
4464 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
4465 wndClass.hbrBackground = NULL_BRUSH;
4466 wndClass.lpszClassName = POPUPMENUCLASSNAME;
4467
4468 rc = RegisterClassA(&wndClass);
4469 MENU_Init();
4470
4471 return rc;
4472}
4473//******************************************************************************
4474//******************************************************************************
4475BOOL POPUPMENU_Unregister()
4476{
4477 if (GlobalFindAtomA(POPUPMENUCLASSNAME))
4478 return UnregisterClassA(POPUPMENUCLASSNAME,(HINSTANCE)NULL);
4479 else return FALSE;
4480}
4481//******************************************************************************
4482//******************************************************************************
4483
Note: See TracBrowser for help on using the repository browser.