source: trunk/src/user32/menu.cpp@ 2804

Last change on this file since 2804 was 2804, checked in by sandervl, 26 years ago

Added new logging feature

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