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

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

Menu bugfixes

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