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

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

GetDCEx changes (fail if hwnd == 0)

File size: 135.9 KB
Line 
1/* $Id: menu.cpp,v 1.14 2000-01-31 22:30:52 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
1709 if (IS_STRING_ITEM(flags))
1710 {
1711 if (!str || !*str)
1712 {
1713 flags |= MF_SEPARATOR;
1714 item->text = NULL;
1715 }
1716 else
1717 {
1718 LPSTR text;
1719 /* Item beginning with a backspace is a help item */
1720 if (*str == '\b')
1721 {
1722 flags |= MF_HELP;
1723 str++;
1724 }
1725 if (!(text = HEAP_strdupA(GetProcessHeap(), 0, str ))) return FALSE;
1726 item->text = text;
1727 }
1728 }
1729 else if (IS_BITMAP_ITEM(flags))
1730 item->text = (LPSTR)(HBITMAP)LOWORD(str);
1731 else item->text = NULL;
1732
1733 if (flags & MF_OWNERDRAW)
1734 item->dwItemData = (DWORD)str;
1735 else
1736 item->dwItemData = 0;
1737
1738 if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) )
1739 DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */
1740
1741 if (flags & MF_POPUP)
1742 {
1743 POPUPMENU *menu = (POPUPMENU*)(UINT)id;
1744 if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP;
1745 else
1746 {
1747 item->wID = 0;
1748 item->hSubMenu = 0;
1749 item->fType = 0;
1750 item->fState = 0;
1751 return FALSE;
1752 }
1753 }
1754
1755 item->wID = id;
1756 if (flags & MF_POPUP)
1757 item->hSubMenu = id;
1758
1759 if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) )
1760 flags |= MF_POPUP; /* keep popup */
1761
1762 item->fType = flags & TYPE_MASK;
1763 item->fState = (flags & STATE_MASK) &
1764 ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION);
1765
1766
1767 /* Don't call SetRectEmpty here! */
1768
1769
1770 if (prevText) HeapFree(GetProcessHeap(), 0, prevText );
1771
1772 //debug_print_menuitem("MENU_SetItemData to : ", item, "");
1773 return TRUE;
1774}
1775
1776
1777/**********************************************************************
1778 * MENU_InsertItem
1779 *
1780 * Insert a new item into a menu.
1781 */
1782static MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags )
1783{
1784 MENUITEM *newItems;
1785 POPUPMENU *menu;
1786
1787 if (!(menu = (POPUPMENU*)hMenu))
1788 {
1789 //WARN("%04x not a menu handle\n",
1790 // hMenu );
1791 return NULL;
1792 }
1793
1794 /* Find where to insert new item */
1795
1796 if ((pos==(UINT)-1) || ((flags & MF_BYPOSITION) && (pos == menu->nItems)))
1797 {
1798 /* Special case: append to menu */
1799 /* Some programs specify the menu length to do that */
1800 pos = menu->nItems;
1801 }
1802 else
1803 {
1804 if (!MENU_FindItem( &hMenu, &pos, flags ))
1805 {
1806 //WARN("item %x not found\n",
1807 // pos );
1808 return NULL;
1809 }
1810 if (!(menu = (LPPOPUPMENU)hMenu))
1811 {
1812 //WARN("%04x not a menu handle\n",
1813 // hMenu);
1814 return NULL;
1815 }
1816 }
1817
1818 /* Create new items array */
1819
1820 newItems = (MENUITEM*)HeapAlloc(GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) );
1821 if (!newItems)
1822 {
1823 //WARN("allocation failed\n" );
1824 return NULL;
1825 }
1826 if (menu->nItems > 0)
1827 {
1828 /* Copy the old array into the new */
1829 if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) );
1830 if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos],
1831 (menu->nItems-pos)*sizeof(MENUITEM) );
1832 HeapFree(GetProcessHeap(), 0, menu->items );
1833 }
1834 menu->items = newItems;
1835 menu->nItems++;
1836 memset( &newItems[pos], 0, sizeof(*newItems) );
1837 menu->Height = 0; /* force size recalculate */
1838 return &newItems[pos];
1839}
1840
1841
1842/**********************************************************************
1843 * MENU_ParseResource
1844 *
1845 * Parse a standard menu resource and add items to the menu.
1846 * Return a pointer to the end of the resource.
1847 */
1848static LPCSTR MENU_ParseResource( LPCSTR res, HMENU hMenu, BOOL unicode )
1849{
1850 WORD flags, id = 0;
1851 LPCSTR str;
1852
1853 do
1854 {
1855 flags = GET_WORD(res);
1856 res += sizeof(WORD);
1857 if (!(flags & MF_POPUP))
1858 {
1859 id = GET_WORD(res);
1860 res += sizeof(WORD);
1861 }
1862 //if (!IS_STRING_ITEM(flags))
1863 // ERR("not a string item %04x\n", flags );
1864 str = res;
1865 if (!unicode) res += strlen(str) + 1;
1866 else res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR);
1867 if (flags & MF_POPUP)
1868 {
1869 HMENU hSubMenu = CreatePopupMenu();
1870 if (!hSubMenu) return NULL;
1871 if (!(res = MENU_ParseResource( res, hSubMenu, unicode )))
1872 return NULL;
1873 if (!unicode) AppendMenuA( hMenu, flags, (UINT)hSubMenu, str );
1874 else AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str );
1875 }
1876 else /* Not a popup */
1877 {
1878 if (!unicode) AppendMenuA( hMenu, flags, id, *str ? str : NULL );
1879 else AppendMenuW( hMenu, flags, id,
1880 *(LPCWSTR)str ? (LPCWSTR)str : NULL );
1881 }
1882 } while (!(flags & MF_END));
1883 return res;
1884}
1885
1886
1887/**********************************************************************
1888 * MENUEX_ParseResource
1889 *
1890 * Parse an extended menu resource and add items to the menu.
1891 * Return a pointer to the end of the resource.
1892 */
1893static LPCSTR MENUEX_ParseResource( LPCSTR res, HMENU hMenu)
1894{
1895 WORD resinfo;
1896 do {
1897 MENUITEMINFOW mii;
1898
1899 mii.cbSize = sizeof(mii);
1900 mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE;
1901 mii.fType = GET_DWORD(res);
1902 res += sizeof(DWORD);
1903 mii.fState = GET_DWORD(res);
1904 res += sizeof(DWORD);
1905 mii.wID = GET_DWORD(res);
1906 res += sizeof(DWORD);
1907 resinfo = GET_WORD(res);
1908 res += sizeof(WORD);
1909 /* Align the text on a word boundary. */
1910 res += (~((int)res - 1)) & 1;
1911 mii.dwTypeData = (LPWSTR) res;
1912 res += (1 + lstrlenW(mii.dwTypeData)) * sizeof(WCHAR);
1913 /* Align the following fields on a dword boundary. */
1914 res += (~((int)res - 1)) & 3;
1915
1916 /* FIXME: This is inefficient and cannot be optimised away by gcc. */
1917 {
1918 LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(),
1919 0, mii.dwTypeData);
1920 //TRACE("Menu item: [%08x,%08x,%04x,%04x,%s]\n",
1921 // mii.fType, mii.fState, mii.wID, resinfo, newstr);
1922 HeapFree( GetProcessHeap(), 0, newstr );
1923 }
1924
1925 if (resinfo & 1) { /* Pop-up? */
1926 /* DWORD helpid = GET_DWORD(res); FIXME: use this. */
1927 res += sizeof(DWORD);
1928 mii.hSubMenu = CreatePopupMenu();
1929 if (!mii.hSubMenu)
1930 return NULL;
1931 if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) {
1932 DestroyMenu(mii.hSubMenu);
1933 return NULL;
1934 }
1935 mii.fMask |= MIIM_SUBMENU;
1936 mii.fType |= MF_POPUP;
1937 }
1938 InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii);
1939 } while (!(resinfo & MF_END));
1940 return res;
1941}
1942
1943
1944/***********************************************************************
1945 * MENU_GetSubPopup
1946 *
1947 * Return the handle of the selected sub-popup menu (if any).
1948 */
1949static HMENU MENU_GetSubPopup( HMENU hmenu )
1950{
1951 POPUPMENU *menu;
1952 MENUITEM *item;
1953
1954 menu = (POPUPMENU*)hmenu;
1955
1956 if (menu->FocusedItem == NO_SELECTED_ITEM) return 0;
1957
1958 item = &menu->items[menu->FocusedItem];
1959 if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT))
1960 return item->hSubMenu;
1961 return 0;
1962}
1963
1964
1965/***********************************************************************
1966 * MENU_HideSubPopups
1967 *
1968 * Hide the sub-popup menus of this menu.
1969 */
1970static void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu,
1971 BOOL sendMenuSelect )
1972{
1973 POPUPMENU *menu = (POPUPMENU*)hmenu;
1974
1975 //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, sendMenuSelect);
1976
1977 if (menu && uSubPWndLevel)
1978 {
1979 HMENU hsubmenu;
1980 POPUPMENU *submenu;
1981 MENUITEM *item;
1982
1983 if (menu->FocusedItem != NO_SELECTED_ITEM)
1984 {
1985 item = &menu->items[menu->FocusedItem];
1986 if (!(item->fType & MF_POPUP) ||
1987 !(item->fState & MF_MOUSESELECT)) return;
1988 item->fState &= ~MF_MOUSESELECT;
1989 hsubmenu = item->hSubMenu;
1990 } else return;
1991
1992 submenu = (POPUPMENU*)hsubmenu;
1993 MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE );
1994 MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect, 0 );
1995
1996 if (submenu->hWnd == MENU_GetTopPopupWnd() )
1997 {
1998 ShowWindow( submenu->hWnd, SW_HIDE );
1999 uSubPWndLevel = 0;
2000 }
2001 else
2002 {
2003 DestroyWindow( submenu->hWnd );
2004 submenu->hWnd = 0;
2005 }
2006 MENU_ReleaseTopPopupWnd();
2007 }
2008}
2009
2010
2011/***********************************************************************
2012 * MENU_ShowSubPopup
2013 *
2014 * Display the sub-menu of the selected item of this menu.
2015 * Return the handle of the submenu, or hmenu if no submenu to display.
2016 */
2017static HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu,
2018 BOOL selectFirst, UINT wFlags,POINT *pt)
2019{
2020 RECT rect;
2021 POPUPMENU *menu;
2022 MENUITEM *item;
2023 HDC hdc;
2024
2025 //TRACE("owner=0x%04x hmenu=0x%04x 0x%04x\n", hwndOwner, hmenu, selectFirst);
2026
2027 if (!(menu = (POPUPMENU*)hmenu)) return hmenu;
2028
2029 if (menu->FocusedItem == NO_SELECTED_ITEM)
2030 {
2031 return hmenu;
2032 }
2033
2034 item = &menu->items[menu->FocusedItem];
2035 if (!(item->fType & MF_POPUP) ||
2036 (item->fState & (MF_GRAYED | MF_DISABLED)))
2037 {
2038 return hmenu;
2039 }
2040
2041 /* message must be send before using item,
2042 because nearly everything may by changed by the application ! */
2043
2044 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2045 if (!(wFlags & TPM_NONOTIFY))
2046 SendMessageA( hwndOwner, WM_INITMENUPOPUP, item->hSubMenu,
2047 MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) ));
2048
2049 item = &menu->items[menu->FocusedItem];
2050 rect = item->rect;
2051
2052 /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */
2053 if (!(item->fState & MF_HILITE))
2054 {
2055 if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd );
2056 else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW);
2057
2058 SelectObject( hdc, hMenuFont);
2059
2060 item->fState |= MF_HILITE;
2061 MENU_DrawMenuItem( menu->hWnd, hmenu, hwndOwner, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE );
2062 ReleaseDC( menu->hWnd, hdc );
2063 }
2064 if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right)
2065 item->rect = rect;
2066
2067 item->fState |= MF_MOUSESELECT;
2068
2069 if (IS_SYSTEM_MENU(menu))
2070 {
2071 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
2072
2073 MENU_InitSysMenuPopup(item->hSubMenu,GetWindowLongA(menu->hWnd,GWL_STYLE), GetClassLongA(menu->hWnd, GCL_STYLE));
2074
2075 if ((wFlags & TPM_CAPTIONSYSMENU) && pt)
2076 {
2077 rect.top = pt->y;
2078 rect.left = pt->x;
2079 rect.bottom = rect.right = 0;
2080 } else
2081 {
2082 if (win32wnd) win32wnd->GetSysPopupPos(&rect);
2083 rect.top = rect.bottom;
2084 rect.right = GetSystemMetrics(SM_CXSIZE);
2085 rect.bottom = GetSystemMetrics(SM_CYSIZE);
2086 }
2087 }
2088 else
2089 {
2090 if (menu->wFlags & MF_POPUP)
2091 {
2092 RECT rectWindow;
2093
2094 GetWindowRect(menu->hWnd,&rectWindow);
2095 rect.left = rectWindow.left + item->rect.right-arrow_bitmap_width;
2096 rect.top = rectWindow.top + item->rect.top;
2097 rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width;
2098 rect.bottom = item->rect.top - item->rect.bottom;
2099 }
2100 else
2101 {
2102 RECT rectWindow;
2103
2104 GetWindowRect(menu->hWnd,&rectWindow);
2105 rect.left = rectWindow.left + item->rect.left;
2106 rect.top = rectWindow.top + item->rect.bottom;
2107 rect.right = item->rect.right - item->rect.left;
2108 rect.bottom = item->rect.bottom - item->rect.top;
2109 }
2110 }
2111
2112 MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem,
2113 rect.left, rect.top, rect.right, rect.bottom );
2114 if (selectFirst)
2115 MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT );
2116 return item->hSubMenu;
2117}
2118
2119/***********************************************************************
2120 * MENU_PtMenu
2121 *
2122 * Walks menu chain trying to find a menu pt maps to.
2123 */
2124static HMENU MENU_PtMenu(HMENU hMenu,POINT pt,BOOL inMenuBar)
2125{
2126 POPUPMENU *menu = (POPUPMENU*)hMenu;
2127 register UINT ht = menu->FocusedItem;
2128
2129 /* try subpopup first (if any) */
2130 ht = (ht != NO_SELECTED_ITEM &&
2131 (menu->items[ht].fType & MF_POPUP) &&
2132 (menu->items[ht].fState & MF_MOUSESELECT))
2133 ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu,pt,inMenuBar) : 0;
2134
2135 if( !ht ) /* check the current window (avoiding WM_HITTEST) */
2136 {
2137 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(menu->hWnd);
2138 if(win32wnd==NULL)
2139 DebugInt3();
2140
2141 ht = win32wnd->HandleNCHitTest(pt);
2142 if( menu->wFlags & MF_POPUP )
2143 ht = (ht != (UINT)HTNOWHERE &&
2144 ht != (UINT)HTERROR) ? (UINT)hMenu : 0;
2145 else
2146 {
2147 ht = ((ht == HTSYSMENU) && !inMenuBar) ? (UINT)(getSysMenu(menu->hWnd))
2148 : ((ht == HTMENU) && inMenuBar) ? (UINT)(getMenu(menu->hWnd)) : 0;
2149 }
2150 }
2151 return (HMENU)ht;
2152}
2153
2154/***********************************************************************
2155 * MENU_ExecFocusedItem
2156 *
2157 * Execute a menu item (for instance when user pressed Enter).
2158 * Return the wID of the executed item. Otherwise, -1 indicating
2159 * that no menu item wase executed;
2160 * Have to receive the flags for the TrackPopupMenu options to avoid
2161 * sending unwanted message.
2162 *
2163 */
2164static INT MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu, UINT wFlags )
2165{
2166 MENUITEM *item;
2167 POPUPMENU *menu = (POPUPMENU*)hMenu;
2168
2169 //TRACE("%p hmenu=0x%04x\n", pmt, hMenu);
2170
2171 if (!menu || !menu->nItems ||
2172 (menu->FocusedItem == NO_SELECTED_ITEM)) return -1;
2173
2174 item = &menu->items[menu->FocusedItem];
2175
2176 //TRACE("%08x %08x %08x\n",
2177 // hMenu, item->wID, item->hSubMenu);
2178
2179 if (!(item->fType & MF_POPUP))
2180 {
2181 if (!(item->fState & (MF_GRAYED | MF_DISABLED)))
2182 {
2183 /* If TPM_RETURNCMD is set you return the id, but
2184 do not send a message to the owner */
2185 if(!(wFlags & TPM_RETURNCMD))
2186 {
2187 if( menu->wFlags & MF_SYSMENU )
2188 PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID,
2189 MAKELPARAM(pmt->pt.x, pmt->pt.y) );
2190 else
2191 PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 );
2192 }
2193 return item->wID;
2194 }
2195 }
2196 else
2197 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hMenu, TRUE, wFlags,&pmt->pt);
2198
2199 return -1;
2200}
2201
2202/***********************************************************************
2203 * MENU_SwitchTracking
2204 *
2205 * Helper function for menu navigation routines.
2206 */
2207static void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id )
2208{
2209 POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
2210 POPUPMENU *topmenu = (POPUPMENU*)pmt->hTopMenu;
2211
2212 //TRACE("%p hmenu=0x%04x 0x%04x\n", pmt, hPtMenu, id);
2213
2214 if( pmt->hTopMenu != hPtMenu &&
2215 !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) )
2216 {
2217 /* both are top level menus (system and menu-bar) */
2218 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2219 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
2220 pmt->hTopMenu = hPtMenu;
2221 }
2222 else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE );
2223 MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE, 0 );
2224}
2225
2226
2227/***********************************************************************
2228 * MENU_ButtonDown
2229 *
2230 * Return TRUE if we can go on with menu tracking.
2231 */
2232static BOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
2233{
2234 //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
2235
2236 if (hPtMenu)
2237 {
2238 UINT id = 0;
2239 POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
2240 MENUITEM *item;
2241
2242 if( IS_SYSTEM_MENU(ptmenu) )
2243 item = ptmenu->items;
2244 else
2245 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2246
2247 if( item )
2248 {
2249 if( ptmenu->FocusedItem != id )
2250 MENU_SwitchTracking( pmt, hPtMenu, id );
2251
2252 /* If the popup menu is not already "popped" */
2253 if(!(item->fState & MF_MOUSESELECT ))
2254 {
2255 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,hPtMenu,FALSE,wFlags,&pmt->pt);
2256 }
2257
2258 return TRUE;
2259 }
2260 /* Else the click was on the menu bar, finish the tracking */
2261 }
2262 return FALSE;
2263}
2264
2265/***********************************************************************
2266 * MENU_ButtonUp
2267 *
2268 * Return the value of MENU_ExecFocusedItem if
2269 * the selected item was not a popup. Else open the popup.
2270 * A -1 return value indicates that we go on with menu tracking.
2271 *
2272 */
2273static INT MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags)
2274{
2275 //TRACE("%p hmenu=0x%04x\n", pmt, hPtMenu);
2276
2277 if (hPtMenu)
2278 {
2279 UINT id = 0;
2280 POPUPMENU *ptmenu = (POPUPMENU*)hPtMenu;
2281 MENUITEM *item;
2282
2283 if( IS_SYSTEM_MENU(ptmenu) )
2284 item = ptmenu->items;
2285 else
2286 item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2287
2288 if( item && (ptmenu->FocusedItem == id ))
2289 {
2290 if( !(item->fType & MF_POPUP) )
2291 return MENU_ExecFocusedItem( pmt, hPtMenu, wFlags);
2292
2293 /* If we are dealing with the top-level menu and that this */
2294 /* is a click on an already "poppped" item */
2295 /* Stop the menu tracking and close the opened submenus */
2296 if((pmt->hTopMenu == hPtMenu) && (ptmenu->bTimeToHide == TRUE))
2297 return 0;
2298 }
2299 ptmenu->bTimeToHide = TRUE;
2300 }
2301 return -1;
2302}
2303
2304
2305/***********************************************************************
2306 * MENU_MouseMove
2307 *
2308 * Return TRUE if we can go on with menu tracking.
2309 */
2310static BOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu, UINT wFlags )
2311{
2312 UINT id = NO_SELECTED_ITEM;
2313 POPUPMENU *ptmenu = NULL;
2314
2315 if( hPtMenu )
2316 {
2317 ptmenu = (POPUPMENU*)hPtMenu;
2318 if( IS_SYSTEM_MENU(ptmenu) )
2319 id = 0;
2320 else
2321 MENU_FindItemByCoords( ptmenu, pmt->pt, &id );
2322 }
2323
2324 if( id == NO_SELECTED_ITEM )
2325 {
2326 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2327 NO_SELECTED_ITEM, TRUE, pmt->hTopMenu);
2328
2329 }
2330 else if( ptmenu->FocusedItem != id )
2331 {
2332 MENU_SwitchTracking( pmt, hPtMenu, id );
2333 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hPtMenu, FALSE, wFlags,&pmt->pt);
2334 }
2335 return TRUE;
2336}
2337
2338
2339/***********************************************************************
2340 * MENU_DoNextMenu
2341 *
2342 * NOTE: WM_NEXTMENU documented in Win32 is a bit different.
2343 */
2344static LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk )
2345{
2346 POPUPMENU *menu = (POPUPMENU*)pmt->hTopMenu;
2347
2348 if( (vk == VK_LEFT && menu->FocusedItem == 0 ) ||
2349 (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1))
2350 {
2351 HMENU hNewMenu;
2352 HWND hNewWnd;
2353 UINT id = 0;
2354 LRESULT l = SendMessageA( pmt->hOwnerWnd, WM_NEXTMENU, vk,
2355 (IS_SYSTEM_MENU(menu)) ? GetSubMenu(pmt->hTopMenu,0) : pmt->hTopMenu );
2356
2357 //TRACE("%04x [%04x] -> %04x [%04x]\n",
2358 // (UINT16)pmt->hCurrentMenu, (UINT16)pmt->hOwnerWnd, LOWORD(l), HIWORD(l) );
2359
2360 if( l == 0 )
2361 {
2362 hNewWnd = pmt->hOwnerWnd;
2363 if( IS_SYSTEM_MENU(menu) )
2364 {
2365 /* switch to the menu bar */
2366
2367 if( (GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_CHILD) || !getMenu(pmt->hOwnerWnd) )
2368 {
2369 return FALSE;
2370 }
2371
2372 hNewMenu = getMenu(pmt->hOwnerWnd);
2373 if( vk == VK_LEFT )
2374 {
2375 menu = (POPUPMENU*)hNewMenu;
2376 id = menu->nItems - 1;
2377 }
2378 }
2379 else if( GetWindowLongA(pmt->hOwnerWnd,GWL_STYLE) & WS_SYSMENU )
2380 {
2381 /* switch to the system menu */
2382 hNewMenu = getSysMenu(pmt->hOwnerWnd);
2383 }
2384 else
2385 {
2386 return FALSE;
2387 }
2388 }
2389 else /* application returned a new menu to switch to */
2390 {
2391 hNewMenu = LOWORD(l); hNewWnd = HIWORD(l);
2392
2393 if( IsMenu(hNewMenu) && IsWindow(hNewWnd) )
2394 {
2395 if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_SYSMENU) &&
2396 GetSubMenu(getSysMenu(hNewWnd), 0) == hNewMenu )
2397 {
2398 /* get the real system menu */
2399 hNewMenu = getSysMenu(hNewWnd);
2400 }
2401 else if( (GetWindowLongA(hNewWnd,GWL_STYLE) & WS_CHILD) || (getMenu(hNewWnd) != hNewMenu) )
2402 {
2403 /* FIXME: Not sure what to do here, perhaps,
2404 * try to track hNewMenu as a popup? */
2405
2406 //TRACE(" -- got confused.\n");
2407 return FALSE;
2408 }
2409 }
2410 else return FALSE;
2411 }
2412
2413 if( hNewMenu != pmt->hTopMenu )
2414 {
2415 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM,
2416 FALSE, 0 );
2417 if( pmt->hCurrentMenu != pmt->hTopMenu )
2418 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2419 }
2420
2421 if( hNewWnd != pmt->hOwnerWnd )
2422 {
2423 ReleaseCapture();
2424 pmt->hOwnerWnd = hNewWnd;
2425 SetCapture(pmt->hOwnerWnd); //SvL: Don't know if this is good enough
2426 //EVENT_Capture( pmt->hOwnerWnd, HTMENU ); //CB: todo
2427 }
2428
2429 pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */
2430 MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE, 0 );
2431
2432 return TRUE;
2433 }
2434 return FALSE;
2435}
2436
2437/***********************************************************************
2438 * MENU_SuspendPopup
2439 *
2440 * The idea is not to show the popup if the next input message is
2441 * going to hide it anyway.
2442 */
2443static BOOL MENU_SuspendPopup( MTRACKER* pmt, UINT uMsg )
2444{
2445 MSG msg;
2446
2447 msg.hwnd = pmt->hOwnerWnd;
2448
2449 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2450 pmt->trackFlags |= TF_SKIPREMOVE;
2451
2452 switch( uMsg )
2453 {
2454 case WM_KEYDOWN:
2455 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
2456 if( msg.message == WM_KEYUP || msg.message == WM_PAINT )
2457 {
2458 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE);
2459 PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE);
2460 if( msg.message == WM_KEYDOWN &&
2461 (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT))
2462 {
2463 pmt->trackFlags |= TF_SUSPENDPOPUP;
2464 return TRUE;
2465 }
2466 }
2467 break;
2468 }
2469
2470 /* failures go through this */
2471 pmt->trackFlags &= ~TF_SUSPENDPOPUP;
2472 return FALSE;
2473}
2474
2475/***********************************************************************
2476 * MENU_KeyLeft
2477 *
2478 * Handle a VK_LEFT key event in a menu.
2479 */
2480static void MENU_KeyLeft( MTRACKER* pmt, UINT wFlags )
2481{
2482 POPUPMENU *menu;
2483 HMENU hmenutmp, hmenuprev;
2484 UINT prevcol;
2485
2486 hmenuprev = hmenutmp = pmt->hTopMenu;
2487 menu = (POPUPMENU*)hmenutmp;
2488
2489 /* Try to move 1 column left (if possible) */
2490 if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) !=
2491 NO_SELECTED_ITEM ) {
2492
2493 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2494 prevcol, TRUE, 0 );
2495 return;
2496 }
2497
2498 /* close topmost popup */
2499 while (hmenutmp != pmt->hCurrentMenu)
2500 {
2501 hmenuprev = hmenutmp;
2502 hmenutmp = MENU_GetSubPopup( hmenuprev );
2503 }
2504
2505 MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE );
2506 pmt->hCurrentMenu = hmenuprev;
2507
2508 if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) )
2509 {
2510 /* move menu bar selection if no more popups are left */
2511
2512 if( !MENU_DoNextMenu( pmt, VK_LEFT) )
2513 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV );
2514
2515 if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2516 {
2517 /* A sublevel menu was displayed - display the next one
2518 * unless there is another displacement coming up */
2519
2520 if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) )
2521 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2522 pmt->hTopMenu, TRUE, wFlags,&pmt->pt);
2523 }
2524 }
2525}
2526
2527
2528/***********************************************************************
2529 * MENU_KeyRight
2530 *
2531 * Handle a VK_RIGHT key event in a menu.
2532 */
2533static void MENU_KeyRight( MTRACKER* pmt, UINT wFlags )
2534{
2535 HMENU hmenutmp;
2536 POPUPMENU *menu = (POPUPMENU*)pmt->hTopMenu;
2537 UINT nextcol;
2538
2539 //TRACE("MENU_KeyRight called, cur %x (%s), top %x (%s).\n",
2540 // pmt->hCurrentMenu,
2541 // ((POPUPMENU *)USER_HEAP_LIN_ADDR(pmt->hCurrentMenu))->
2542 // items[0].text,
2543 // pmt->hTopMenu, menu->items[0].text );
2544
2545 if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu))
2546 {
2547 /* If already displaying a popup, try to display sub-popup */
2548
2549 hmenutmp = pmt->hCurrentMenu;
2550 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd, hmenutmp, TRUE, wFlags,&pmt->pt);
2551
2552 /* if subpopup was displayed then we are done */
2553 if (hmenutmp != pmt->hCurrentMenu) return;
2554 }
2555
2556 /* Check to see if there's another column */
2557 if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) !=
2558 NO_SELECTED_ITEM ) {
2559 //TRACE("Going to %d.\n", nextcol );
2560 MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu,
2561 nextcol, TRUE, 0 );
2562 return;
2563 }
2564
2565 if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */
2566 {
2567 if( pmt->hCurrentMenu != pmt->hTopMenu )
2568 {
2569 MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE );
2570 hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu;
2571 } else hmenutmp = 0;
2572
2573 /* try to move to the next item */
2574 if( !MENU_DoNextMenu( pmt, VK_RIGHT) )
2575 MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT );
2576
2577 if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP )
2578 if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) )
2579 pmt->hCurrentMenu = MENU_ShowSubPopup(pmt->hOwnerWnd,
2580 pmt->hTopMenu, TRUE, wFlags,&pmt->pt);
2581 }
2582}
2583
2584VOID MENU_DispatchMouseMsg(MSG *msg)
2585{
2586 LONG hittest;
2587
2588 hittest = SendMessageA(msg->hwnd,WM_NCHITTEST,0,MAKELONG(msg->pt.x,msg->pt.y));
2589 if (hittest != HTCLIENT)
2590 SendMessageA(msg->hwnd,msg->message+WM_NCMOUSEMOVE-WM_MOUSEMOVE,hittest,MAKELONG(msg->pt.x,msg->pt.y));
2591 else
2592 DispatchMessageA(msg);
2593}
2594
2595/***********************************************************************
2596 * MENU_TrackMenu
2597 *
2598 * Menu tracking code.
2599 */
2600static INT MENU_TrackMenu(HMENU hmenu,UINT wFlags,INT x,INT y,HWND hwnd,BOOL inMenuBar,const RECT *lprect)
2601{
2602 MSG msg;
2603 POPUPMENU *menu;
2604 BOOL fRemove;
2605 INT executedMenuId = -1;
2606 MTRACKER mt;
2607 BOOL enterIdleSent = FALSE;
2608
2609 mt.trackFlags = 0;
2610 mt.hCurrentMenu = hmenu;
2611 mt.hTopMenu = hmenu;
2612 mt.hOwnerWnd = hwnd;
2613 mt.pt.x = x;
2614 mt.pt.y = y;
2615
2616 //TRACE("hmenu=0x%04x flags=0x%08x (%d,%d) hwnd=0x%04x (%d,%d)-(%d,%d)\n",
2617 // hmenu, wFlags, x, y, hwnd, (lprect) ? lprect->left : 0, (lprect) ? lprect->top : 0,
2618 // (lprect) ? lprect->right : 0, (lprect) ? lprect->bottom : 0);
2619
2620 fEndMenu = FALSE;
2621 if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
2622
2623 if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu, wFlags );
2624
2625 //EVENT_Capture( mt.hOwnerWnd, HTMENU ); //CB: todo
2626 //SvL: Set keyboard & mouse event capture
2627 SetCapture(mt.hOwnerWnd);
2628
2629 while (!fEndMenu)
2630 {
2631 menu = (POPUPMENU*)mt.hCurrentMenu;
2632 msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0;
2633
2634 /* we have to keep the message in the queue until it's
2635 * clear that menu loop is not over yet. */
2636// if (!GetMessageA(&msg,msg.hwnd,0,0)) break;
2637 //SvL: Getting messages for only the menu delays background paints (i.e. VPBuddy logo)
2638 if (!GetMessageA(&msg,0,0,0)) break;
2639 TranslateMessage( &msg );
2640 mt.pt = msg.pt;
2641
2642 if ( (msg.hwnd==menu->hWnd) || (msg.message!=WM_TIMER) )
2643 enterIdleSent=FALSE;
2644
2645 fRemove = FALSE;
2646 if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
2647 {
2648 /* Find a menu for this mouse event */
2649 POINT pt = msg.pt;
2650
2651 hmenu = MENU_PtMenu(mt.hTopMenu,pt,inMenuBar);
2652
2653 //CB: todo: Win32 dispatches at least some mouse messages!
2654
2655 switch(msg.message)
2656 {
2657 /* no WM_NC... messages in captured state */
2658
2659 case WM_RBUTTONDBLCLK:
2660 case WM_RBUTTONDOWN:
2661 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2662 /* fall through */
2663 case WM_LBUTTONDBLCLK:
2664 case WM_LBUTTONDOWN:
2665 /* If the message belongs to the menu, removes it from the queue */
2666 /* Else, end menu tracking */
2667 fRemove = MENU_ButtonDown( &mt, hmenu, wFlags );
2668 fEndMenu = !fRemove;
2669 break;
2670
2671 case WM_RBUTTONUP:
2672 if (!(wFlags & TPM_RIGHTBUTTON)) break;
2673 /* fall through */
2674 case WM_LBUTTONUP:
2675 /* Check if a menu was selected by the mouse */
2676 if (hmenu)
2677 {
2678 executedMenuId = MENU_ButtonUp( &mt, hmenu, wFlags);
2679
2680 /* End the loop if executedMenuId is an item ID */
2681 /* or if the job was done (executedMenuId = 0). */
2682 fEndMenu = fRemove = (executedMenuId != -1);
2683 }
2684 /* No menu was selected by the mouse */
2685 /* if the function was called by TrackPopupMenu, continue
2686 with the menu tracking. If not, stop it */
2687 else
2688 fEndMenu = ((wFlags & TPM_POPUPMENU) ? FALSE : TRUE);
2689
2690 break;
2691
2692 case WM_MOUSEMOVE:
2693 /* In win95 winelook, the selected menu item must be changed every time the
2694 mouse moves. In Win31 winelook, the mouse button has to be held down */
2695
2696 fEndMenu |= !MENU_MouseMove( &mt, hmenu, wFlags );
2697 //CB: dispatch message
2698 if (!fEndMenu && !hmenu) DispatchMessageA(&msg);
2699
2700 } /* switch(msg.message) - mouse */
2701 }
2702 else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
2703 {
2704 fRemove = TRUE; /* Keyboard messages are always removed */
2705 switch(msg.message)
2706 {
2707 case WM_KEYDOWN:
2708 switch(msg.wParam)
2709 {
2710 case VK_HOME:
2711 case VK_END:
2712 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu,
2713 NO_SELECTED_ITEM, FALSE, 0 );
2714 /* fall through */
2715 case VK_UP:
2716 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu,
2717 (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV );
2718 break;
2719
2720 case VK_DOWN: /* If on menu bar, pull-down the menu */
2721
2722 menu = (POPUPMENU*)mt.hCurrentMenu;
2723 if (!(menu->wFlags & MF_POPUP))
2724 mt.hCurrentMenu = MENU_ShowSubPopup(mt.hOwnerWnd, mt.hTopMenu, TRUE, wFlags,&mt.pt);
2725 else /* otherwise try to move selection */
2726 MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT );
2727 break;
2728
2729 case VK_LEFT:
2730 MENU_KeyLeft( &mt, wFlags );
2731 break;
2732
2733 case VK_RIGHT:
2734 MENU_KeyRight( &mt, wFlags );
2735 break;
2736
2737 case VK_ESCAPE:
2738 fEndMenu = TRUE;
2739 break;
2740
2741 default:
2742 break;
2743 }
2744 break; /* WM_KEYDOWN */
2745
2746 case WM_SYSKEYDOWN:
2747 switch(msg.wParam)
2748 {
2749 case VK_MENU:
2750 fEndMenu = TRUE;
2751 break;
2752
2753 }
2754 break; /* WM_SYSKEYDOWN */
2755
2756 case WM_CHAR:
2757 {
2758 UINT pos;
2759
2760 if (msg.wParam == '\r' || msg.wParam == ' ')
2761 {
2762 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
2763 fEndMenu = (executedMenuId != -1);
2764
2765 break;
2766 }
2767
2768 /* Hack to avoid control chars. */
2769 /* We will find a better way real soon... */
2770 if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
2771
2772 pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu,
2773 LOWORD(msg.wParam), FALSE );
2774 if (pos == (UINT)-2) fEndMenu = TRUE;
2775 else if (pos == (UINT)-1) MessageBeep(0);
2776 else
2777 {
2778 MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos,
2779 TRUE, 0 );
2780 executedMenuId = MENU_ExecFocusedItem(&mt,mt.hCurrentMenu, wFlags);
2781 fEndMenu = (executedMenuId != -1);
2782 }
2783 }
2784 break;
2785 } /* switch(msg.message) - kbd */
2786 }
2787 else
2788 {
2789 DispatchMessageA( &msg );
2790 }
2791
2792 if (!fEndMenu) fRemove = TRUE;
2793
2794 /* finally remove message from the queue */
2795
2796 if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) )
2797 PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE );
2798 else mt.trackFlags &= ~TF_SKIPREMOVE;
2799 }
2800
2801 ReleaseCapture();
2802
2803 menu = (POPUPMENU*)mt.hTopMenu;
2804
2805 if( IsWindow( mt.hOwnerWnd ) )
2806 {
2807 MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE );
2808
2809 if (menu && menu->wFlags & MF_POPUP)
2810 {
2811 ShowWindow( menu->hWnd, SW_HIDE );
2812 uSubPWndLevel = 0;
2813 }
2814 MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE, 0 );
2815 SendMessageA( mt.hOwnerWnd, WM_MENUSELECT, MAKELONG(0,0xffff), 0 );
2816 }
2817
2818 /* Reset the variable for hiding menu */
2819 menu->bTimeToHide = FALSE;
2820
2821 /* The return value is only used by TrackPopupMenu */
2822 return ((executedMenuId != -1) ? executedMenuId : 0);
2823}
2824
2825/***********************************************************************
2826 * MENU_InitTracking
2827 */
2828static BOOL MENU_InitTracking(HWND hWnd, HMENU hMenu, BOOL bPopup, UINT wFlags)
2829{
2830 //TRACE("hwnd=0x%04x hmenu=0x%04x\n", hWnd, hMenu);
2831
2832 HideCaret(0);
2833
2834 /* Send WM_ENTERMENULOOP and WM_INITMENU message only if TPM_NONOTIFY flag is not specified */
2835 if (!(wFlags & TPM_NONOTIFY))
2836 SendMessageA( hWnd, WM_ENTERMENULOOP, bPopup, 0 );
2837
2838 SendMessageA( hWnd, WM_SETCURSOR, hWnd, HTCAPTION );
2839
2840 if (!(wFlags & TPM_NONOTIFY))
2841 SendMessageA( hWnd, WM_INITMENU, hMenu, 0 );
2842
2843 return TRUE;
2844}
2845/***********************************************************************
2846 * MENU_ExitTracking
2847 */
2848static BOOL MENU_ExitTracking(HWND hWnd)
2849{
2850 //TRACE("hwnd=0x%04x\n", hWnd);
2851
2852 SendMessageA( hWnd, WM_EXITMENULOOP, 0, 0 );
2853 ShowCaret(0);
2854 return TRUE;
2855}
2856
2857/***********************************************************************
2858 * MENU_TrackMouseMenuBar
2859 *
2860 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
2861 */
2862void MENU_TrackMouseMenuBar( HWND hWnd, INT ht, POINT pt )
2863{
2864 HMENU hMenu = (ht == 0) ? getMenu(hWnd):getSysMenu(hWnd);
2865 UINT wFlags = TPM_ENTERIDLEEX | TPM_BUTTONDOWN | TPM_LEFTALIGN | TPM_LEFTBUTTON;
2866
2867 //TRACE("pwnd=%p ht=0x%04x (%ld,%ld)\n", wndPtr, ht, pt.x, pt.y);
2868
2869 if (IsMenu(hMenu))
2870 {
2871 if (ht == HTCAPTION) wFlags |= TPM_CAPTIONSYSMENU | TPM_RIGHTBUTTON;
2872 if (IsIconic(hWnd)) wFlags |= TPM_BOTTOMALIGN; //CB: todo: for minimized windows
2873
2874 MENU_InitTracking( hWnd, hMenu, FALSE, wFlags );
2875 MENU_TrackMenu( hMenu, wFlags, pt.x, pt.y, hWnd,ht == 0, NULL );
2876 MENU_ExitTracking(hWnd);
2877 }
2878}
2879
2880
2881/***********************************************************************
2882 * MENU_TrackKbdMenuBar
2883 *
2884 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
2885 */
2886void MENU_TrackKbdMenuBar( HWND hWnd, UINT wParam, INT vkey)
2887{
2888 UINT uItem = NO_SELECTED_ITEM;
2889 HMENU hTrackMenu;
2890 UINT wFlags = TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON;
2891
2892 /* find window that has a menu */
2893
2894 while(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD)
2895 if( !(hWnd = GetParent(hWnd)) ) return;
2896
2897 /* check if we have to track a system menu */
2898
2899 if( (GetWindowLongA(hWnd,GWL_STYLE) & (WS_CHILD | WS_MINIMIZE)) ||
2900 !getMenu(hWnd) || vkey == VK_SPACE )
2901 {
2902 if( !(GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) ) return;
2903 hTrackMenu = getSysMenu(hWnd);
2904 uItem = 0;
2905 wParam |= HTSYSMENU; /* prevent item lookup */
2906 }
2907 else
2908 hTrackMenu = getMenu(hWnd);
2909
2910 if (IsMenu( hTrackMenu ))
2911 {
2912 MENU_InitTracking( hWnd, hTrackMenu, FALSE, wFlags );
2913
2914 if( vkey && vkey != VK_SPACE )
2915 {
2916 uItem = MENU_FindItemByKey( hWnd, hTrackMenu,
2917 vkey, (wParam & HTSYSMENU) );
2918 if( uItem >= (UINT)(-2) )
2919 {
2920 if( uItem == (UINT)(-1) ) MessageBeep(0);
2921 hTrackMenu = 0;
2922 }
2923 }
2924
2925 if( hTrackMenu )
2926 {
2927 MENU_SelectItem( hWnd, hTrackMenu, uItem, TRUE, 0 );
2928
2929 if( uItem == NO_SELECTED_ITEM )
2930 MENU_MoveSelection( hWnd, hTrackMenu, ITEM_NEXT );
2931 else if( vkey )
2932 PostMessageA( hWnd, WM_KEYDOWN, VK_DOWN, 0L );
2933
2934 MENU_TrackMenu( hTrackMenu, wFlags, 0, 0, hWnd,TRUE, NULL );
2935 }
2936
2937 MENU_ExitTracking (hWnd);
2938 }
2939}
2940
2941
2942/**********************************************************************
2943 * TrackPopupMenu (USER32.549)
2944 *
2945 * Like the win32 API, the function return the command ID only if the
2946 * flag TPM_RETURNCMD is on.
2947 *
2948 */
2949BOOL WINAPI TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y,
2950 INT nReserved, HWND hWnd, const RECT *lpRect )
2951{
2952 BOOL ret = FALSE;
2953
2954 dprintf(("USER32: TrackPopupMenu"));
2955
2956 MENU_InitTracking(hWnd, hMenu, TRUE, wFlags);
2957
2958 /* Send WM_INITMENUPOPUP message only if TPM_NONOTIFY flag is not specified */
2959 if (!(wFlags & TPM_NONOTIFY))
2960 SendMessageA( hWnd, WM_INITMENUPOPUP, hMenu, 0);
2961
2962 if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 ))
2963 ret = MENU_TrackMenu( hMenu, wFlags | TPM_POPUPMENU, 0, 0, hWnd,FALSE, lpRect );
2964 MENU_ExitTracking(hWnd);
2965
2966 if( (!(wFlags & TPM_RETURNCMD)) && (ret != FALSE) )
2967 ret = 1;
2968
2969 return ret;
2970}
2971
2972/**********************************************************************
2973 * TrackPopupMenuEx (USER32.550)
2974 */
2975BOOL WINAPI TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y,
2976 HWND hWnd, LPTPMPARAMS lpTpm )
2977{
2978 dprintf(("USER32: TrackPopupMenuEx"));
2979 //FIXME("not fully implemented\n" );
2980 return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd,
2981 lpTpm ? &lpTpm->rcExclude : NULL );
2982}
2983
2984/***********************************************************************
2985 * PopupMenuWndProc
2986 *
2987 * NOTE: Windows has totally different (and undocumented) popup wndproc.
2988 */
2989LRESULT WINAPI PopupMenuWndProc( HWND hwnd, UINT message, WPARAM wParam,
2990 LPARAM lParam )
2991{
2992 LRESULT retvalue;
2993
2994 //TRACE("hwnd=0x%04x msg=0x%04x wp=0x%04x lp=0x%08lx\n",
2995 //hwnd, message, wParam, lParam);
2996
2997 switch(message)
2998 {
2999 case WM_CREATE:
3000 {
3001 CREATESTRUCTA *cs = (CREATESTRUCTA*)lParam;
3002 SetWindowLongA( hwnd, 0, (LONG)cs->lpCreateParams );
3003 retvalue = 0;
3004 goto END;
3005 }
3006
3007 case WM_MOUSEACTIVATE: /* We don't want to be activated */
3008 retvalue = MA_NOACTIVATE;
3009 goto END;
3010
3011 case WM_PAINT:
3012 {
3013 PAINTSTRUCT ps;
3014 BeginPaint( hwnd, &ps );
3015 MENU_DrawPopupMenu( hwnd, ps.hdc,
3016 (HMENU)GetWindowLongA( hwnd, 0 ) );
3017 EndPaint( hwnd, &ps );
3018 retvalue = 0;
3019 goto END;
3020 }
3021 case WM_ERASEBKGND:
3022 retvalue = 1;
3023 goto END;
3024
3025 case WM_DESTROY:
3026
3027 /* zero out global pointer in case resident popup window
3028 * was somehow destroyed. */
3029
3030 if(MENU_GetTopPopupWnd() )
3031 {
3032 if( hwnd == pTopPopupWnd )
3033 {
3034 //ERR("resident popup destroyed!\n");
3035
3036 MENU_DestroyTopPopupWnd();
3037 uSubPWndLevel = 0;
3038 }
3039 else
3040 uSubPWndLevel--;
3041 MENU_ReleaseTopPopupWnd();
3042 }
3043 break;
3044
3045 case WM_SHOWWINDOW:
3046
3047 if( wParam )
3048 {
3049 //if( !(*(HMENU*)wndPtr->wExtra) )
3050 // ERR("no menu to display\n");
3051 }
3052 else
3053 SetWindowLongA(hwnd,0,0);
3054 break;
3055
3056 case MM_SETMENUHANDLE:
3057
3058 SetWindowLongA(hwnd,0,wParam);
3059 break;
3060
3061 case MM_GETMENUHANDLE:
3062
3063 retvalue = GetWindowLongA(hwnd,0);
3064 goto END;
3065
3066 default:
3067 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
3068 goto END;
3069 }
3070 retvalue = 0;
3071END:
3072 return retvalue;
3073}
3074
3075
3076/***********************************************************************
3077 * MENU_GetMenuBarHeight
3078 *
3079 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
3080 */
3081UINT MENU_GetMenuBarHeight(HWND hwnd,UINT menubarWidth,INT orgX,INT orgY)
3082{
3083 HDC hdc;
3084 RECT rectBar;
3085 LPPOPUPMENU lppop;
3086 UINT retvalue;
3087
3088 //TRACE("HWND 0x%x, width %d, at (%d, %d).\n",
3089 // hwnd, menubarWidth, orgX, orgY );
3090
3091 if (!(lppop = (LPPOPUPMENU)getMenu(hwnd)))
3092 {
3093 return 0;
3094 }
3095
3096 hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW );
3097 SelectObject( hdc, hMenuFont);
3098 SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+GetSystemMetrics(SM_CYMENU));
3099 MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
3100 ReleaseDC( hwnd, hdc );
3101 retvalue = lppop->Height;
3102 return retvalue;
3103}
3104
3105
3106/*******************************************************************
3107 * ChangeMenu32A (USER32.23)
3108 */
3109BOOL WINAPI ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data,
3110 UINT id, UINT flags )
3111{
3112 dprintf(("USER32: ChangeMenuA"));
3113
3114 //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3115 // hMenu, pos, (DWORD)data, id, flags );
3116 if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND,
3117 id, data );
3118 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3119 if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE,
3120 id, data );
3121 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
3122 flags & MF_BYPOSITION ? pos : id,
3123 flags & ~MF_REMOVE );
3124 /* Default: MF_INSERT */
3125 return InsertMenuA( hMenu, pos, flags, id, data );
3126}
3127
3128
3129/*******************************************************************
3130 * ChangeMenu32W (USER32.24)
3131 */
3132BOOL WINAPI ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data,
3133 UINT id, UINT flags )
3134{
3135 dprintf(("USER32: ChangeMenuW"));
3136
3137 //TRACE("menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n",
3138 // hMenu, pos, (DWORD)data, id, flags );
3139 if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND,
3140 id, data );
3141 if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE);
3142 if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE,
3143 id, data );
3144 if (flags & MF_REMOVE) return RemoveMenu( hMenu,
3145 flags & MF_BYPOSITION ? pos : id,
3146 flags & ~MF_REMOVE );
3147 /* Default: MF_INSERT */
3148 return InsertMenuW( hMenu, pos, flags, id, data );
3149}
3150
3151
3152/*******************************************************************
3153 * CheckMenuItem (USER32.46)
3154 */
3155DWORD WINAPI CheckMenuItem( HMENU hMenu, UINT id, UINT flags )
3156{
3157 MENUITEM *item;
3158 DWORD ret;
3159
3160 dprintf(("USER32: CheckMenuItem %x %x %x", hMenu, id, flags));
3161
3162 //TRACE("menu=%04x id=%04x flags=%04x\n", hMenu, id, flags );
3163 if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1;
3164 ret = item->fState & MF_CHECKED;
3165 if (flags & MF_CHECKED) item->fState |= MF_CHECKED;
3166 else item->fState &= ~MF_CHECKED;
3167 return ret;
3168}
3169
3170
3171/**********************************************************************
3172 * EnableMenuItem32 (USER32.170)
3173 */
3174ULONG WINAPI EnableMenuItem( HMENU hMenu, UINT wItemID, UINT wFlags )
3175{
3176 UINT oldflags;
3177 MENUITEM *item;
3178 POPUPMENU *menu;
3179
3180 dprintf(("USER32: EnableMenuItem %x %x %x", hMenu, wItemID, wFlags));
3181
3182 //TRACE("(%04x, %04X, %04X) !\n",
3183 // hMenu, wItemID, wFlags);
3184
3185 /* Get the Popupmenu to access the owner menu */
3186 if (!(menu = (POPUPMENU*)hMenu))
3187 return (UINT)-1;
3188
3189 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags )))
3190 return (UINT)-1;
3191
3192 oldflags = item->fState & (MF_GRAYED | MF_DISABLED);
3193 item->fState ^= (oldflags ^ wFlags) & (MF_GRAYED | MF_DISABLED);
3194
3195 /* In win95 if the close item in the system menu change update the close button */
3196 if((item->wID == SC_CLOSE) && (oldflags != wFlags))
3197 {
3198 if (menu->hSysMenuOwner != 0)
3199 {
3200 POPUPMENU* parentMenu;
3201
3202 /* Get the parent menu to access*/
3203 if (!(parentMenu = (POPUPMENU*)menu->hSysMenuOwner))
3204 return (UINT)-1;
3205
3206 /* Refresh the frame to reflect the change*/
3207 SetWindowPos(parentMenu->hWnd, 0, 0, 0, 0, 0,
3208 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
3209 }
3210 }
3211
3212 return oldflags;
3213}
3214
3215
3216/*******************************************************************
3217 * GetMenuString32A (USER32.268)
3218 */
3219INT WINAPI GetMenuStringA(HMENU hMenu, UINT wItemID,
3220 LPSTR str, INT nMaxSiz, UINT wFlags )
3221{
3222 MENUITEM *item;
3223
3224 dprintf(("USER32: GetMenuStringA %x %d %d %x", hMenu, wItemID, nMaxSiz, wFlags));
3225
3226 //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3227 // hMenu, wItemID, str, nMaxSiz, wFlags );
3228 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
3229 if (!IS_STRING_ITEM(item->fType)) return 0;
3230 if (!str || !nMaxSiz) return strlen(item->text);
3231 str[0] = '\0';
3232 lstrcpynA( str, item->text, nMaxSiz );
3233 //TRACE("returning '%s'\n", str );
3234 return strlen(str);
3235}
3236
3237
3238/*******************************************************************
3239 * GetMenuString32W (USER32.269)
3240 */
3241INT WINAPI GetMenuStringW( HMENU hMenu, UINT wItemID,
3242 LPWSTR str, INT nMaxSiz, UINT wFlags )
3243{
3244 MENUITEM *item;
3245
3246 dprintf(("USER32: GetMenuStringW"));
3247
3248 //TRACE("menu=%04x item=%04x ptr=%p len=%d flags=%04x\n",
3249 // hMenu, wItemID, str, nMaxSiz, wFlags );
3250 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return 0;
3251 if (!IS_STRING_ITEM(item->fType)) return 0;
3252 if (!str || !nMaxSiz) return strlen(item->text);
3253 str[0] = '\0';
3254 lstrcpynAtoW( str, item->text, nMaxSiz );
3255 return lstrlenW(str);
3256}
3257
3258
3259/**********************************************************************
3260 * HiliteMenuItem32 (USER32.318)
3261 */
3262BOOL WINAPI HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID,
3263 UINT wHilite )
3264{
3265 LPPOPUPMENU menu;
3266
3267 dprintf(("USER32: HiliteMenuItem"));
3268
3269 //TRACE("(%04x, %04x, %04x, %04x);\n",
3270 // hWnd, hMenu, wItemID, wHilite);
3271 if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE;
3272 if (!(menu = (LPPOPUPMENU)hMenu)) return FALSE;
3273 if (menu->FocusedItem == wItemID) return TRUE;
3274 MENU_HideSubPopups( hWnd, hMenu, FALSE );
3275 MENU_SelectItem( hWnd, hMenu, wItemID, TRUE, 0 );
3276 return TRUE;
3277}
3278
3279
3280/**********************************************************************
3281 * GetMenuState (USER32.267)
3282 */
3283UINT WINAPI GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags )
3284{
3285 MENUITEM *item;
3286
3287 dprintf(("USER32: GetMenuState %d %d",wItemID,wFlags));
3288
3289 //TRACE("(menu=%04x, id=%04x, flags=%04x);\n",
3290 // hMenu, wItemID, wFlags);
3291
3292 if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
3293
3294 //debug_print_menuitem (" item: ", item, "");
3295 if (item->fType & MF_POPUP)
3296 {
3297 POPUPMENU *menu = (POPUPMENU*)item->hSubMenu;
3298 if (!menu) return -1;
3299 else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff);
3300 }
3301 else
3302 {
3303 /* We used to (from way back then) mask the result to 0xff. */
3304 /* I don't know why and it seems wrong as the documented */
3305 /* return flag MF_SEPARATOR is outside that mask. */
3306 return (item->fType | item->fState);
3307 }
3308}
3309
3310
3311/**********************************************************************
3312 * GetMenuItemCount32 (USER32.262)
3313 */
3314INT WINAPI GetMenuItemCount( HMENU hMenu )
3315{
3316 LPPOPUPMENU menu = (LPPOPUPMENU)hMenu;
3317
3318 dprintf(("USER32: GetMenuItemCount"));
3319
3320 if (!IS_A_MENU(menu)) return -1;
3321 //TRACE("(%04x) returning %d\n",
3322 // hMenu, menu->nItems );
3323 return menu->nItems;
3324}
3325
3326/**********************************************************************
3327 * GetMenuItemID32 (USER32.263)
3328 */
3329UINT WINAPI GetMenuItemID( HMENU hMenu, INT nPos )
3330{
3331 MENUITEM * lpmi;
3332
3333 dprintf(("USER32: GetMenuItemID"));
3334
3335 if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
3336 if (lpmi->fType & MF_POPUP) return -1;
3337 return lpmi->wID;
3338
3339}
3340
3341/*******************************************************************
3342 * InsertMenu32A (USER32.322)
3343 */
3344BOOL WINAPI InsertMenuA( HMENU hMenu, UINT pos, UINT flags,
3345 UINT id, LPCSTR str )
3346{
3347 MENUITEM *item;
3348
3349 if (IS_STRING_ITEM(flags) && str)
3350 dprintf(("USER32: InsertMenuA %x %d %x %d %s", hMenu, pos, flags, id, str));
3351 // TRACE("hMenu %04x, pos %d, flags %08x, "
3352 // "id %04x, str '%s'\n",
3353 // hMenu, pos, flags, id, str );
3354 else // TRACE("hMenu %04x, pos %d, flags %08x, "
3355 dprintf(("USER32: InsertMenuA %x %d %x %d %x", hMenu, pos, flags, id, str));
3356 // "id %04x, str %08lx (not a string)\n",
3357 // hMenu, pos, flags, id, (DWORD)str );
3358
3359 if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE;
3360
3361 if (!(MENU_SetItemData( item, flags, id, str )))
3362 {
3363 RemoveMenu( hMenu, pos, flags );
3364 return FALSE;
3365 }
3366
3367 if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
3368 ((POPUPMENU *)(HMENU)id)->wFlags |= MF_POPUP;
3369
3370 item->hCheckBit = item->hUnCheckBit = 0;
3371 return TRUE;
3372}
3373
3374
3375/*******************************************************************
3376 * InsertMenu32W (USER32.325)
3377 */
3378BOOL WINAPI InsertMenuW( HMENU hMenu, UINT pos, UINT flags,
3379 UINT id, LPCWSTR str )
3380{
3381 BOOL ret;
3382
3383 if (IS_STRING_ITEM(flags) && str)
3384 {
3385 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
3386 ret = InsertMenuA( hMenu, pos, flags, id, newstr );
3387 HeapFree( GetProcessHeap(), 0, newstr );
3388 return ret;
3389 }
3390 else return InsertMenuA( hMenu, pos, flags, id, (LPCSTR)str );
3391}
3392
3393
3394/*******************************************************************
3395 * AppendMenu32A (USER32.5)
3396 */
3397BOOL WINAPI AppendMenuA( HMENU hMenu, UINT flags,
3398 UINT id, LPCSTR data )
3399{
3400 dprintf(("USER32: AppendMenuA"));
3401
3402 return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data );
3403}
3404
3405
3406/*******************************************************************
3407 * AppendMenu32W (USER32.6)
3408 */
3409BOOL WINAPI AppendMenuW( HMENU hMenu, UINT flags,
3410 UINT id, LPCWSTR data )
3411{
3412 dprintf(("USER32: AppendMenuW %x %x %d %x", hMenu, flags, id, data));
3413
3414 return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data );
3415}
3416
3417
3418/**********************************************************************
3419 * RemoveMenu (USER32.441)
3420 */
3421BOOL WINAPI RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags )
3422{
3423 LPPOPUPMENU menu;
3424 MENUITEM *item;
3425
3426 dprintf(("USER32: RemoveMenu %x %d %x", hMenu, nPos, wFlags));
3427
3428 //TRACE("(menu=%04x pos=%04x flags=%04x)\n",hMenu, nPos, wFlags);
3429 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
3430 if (!(menu = (LPPOPUPMENU)hMenu)) return FALSE;
3431
3432 /* Remove item */
3433
3434 MENU_FreeItemData( item );
3435
3436 if (--menu->nItems == 0)
3437 {
3438 HeapFree(GetProcessHeap(), 0, menu->items );
3439 menu->items = NULL;
3440 }
3441 else
3442 {
3443 while(nPos < menu->nItems)
3444 {
3445 *item = *(item+1);
3446 item++;
3447 nPos++;
3448 }
3449 menu->items = (MENUITEM*)HeapReAlloc(GetProcessHeap(), 0, menu->items,
3450 menu->nItems * sizeof(MENUITEM) );
3451 }
3452 return TRUE;
3453}
3454
3455
3456/**********************************************************************
3457 * DeleteMenu32 (USER32.129)
3458 */
3459BOOL WINAPI DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags )
3460{
3461 MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
3462
3463 dprintf(("USER32: DeleteMenu %x %d %x", hMenu, nPos, wFlags));
3464
3465 if (!item) return FALSE;
3466 if (item->fType & MF_POPUP) DestroyMenu( item->hSubMenu );
3467 /* nPos is now the position of the item */
3468 RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
3469 return TRUE;
3470}
3471
3472
3473/*******************************************************************
3474 * ModifyMenu32A (USER32.397)
3475 */
3476BOOL WINAPI ModifyMenuA( HMENU hMenu, UINT pos, UINT flags,
3477 UINT id, LPCSTR str )
3478{
3479 MENUITEM *item;
3480
3481
3482 if (IS_STRING_ITEM(flags))
3483 {
3484 dprintf(("USER32: ModifyMenuA, %x %d %x %d %s", hMenu, pos, flags, id, str));
3485 //TRACE("%04x %d %04x %04x '%s'\n",
3486 // hMenu, pos, flags, id, str ? str : "#NULL#" );
3487 if (!str) return FALSE;
3488 }
3489 else
3490 {
3491 dprintf(("USER32: ModifyMenuA, %x %d %x %d %x", hMenu, pos, flags, id, str));
3492 //TRACE("%04x %d %04x %04x %08lx\n",
3493 // hMenu, pos, flags, id, (DWORD)str );
3494 }
3495
3496 if (!(item = MENU_FindItem( &hMenu, &pos, flags ))) return FALSE;
3497 return MENU_SetItemData( item, flags, id, str );
3498}
3499
3500
3501/*******************************************************************
3502 * ModifyMenu32W (USER32.398)
3503 */
3504BOOL WINAPI ModifyMenuW( HMENU hMenu, UINT pos, UINT flags,
3505 UINT id, LPCWSTR str )
3506{
3507 BOOL ret;
3508
3509 if (IS_STRING_ITEM(flags) && str)
3510 {
3511 LPSTR newstr = HEAP_strdupWtoA( GetProcessHeap(), 0, str );
3512 ret = ModifyMenuA( hMenu, pos, flags, id, newstr );
3513 HeapFree( GetProcessHeap(), 0, newstr );
3514 return ret;
3515 }
3516 else return ModifyMenuA( hMenu, pos, flags, id, (LPCSTR)str );
3517}
3518
3519
3520/**********************************************************************
3521 * CreatePopupMenu32 (USER32.82)
3522 */
3523HMENU WINAPI CreatePopupMenu(void)
3524{
3525 HMENU hmenu;
3526 POPUPMENU *menu;
3527
3528 dprintf(("USER32: CreatePopupMenu"));
3529
3530 if (!(hmenu = CreateMenu())) return 0;
3531 menu = (POPUPMENU*)hmenu;
3532 menu->wFlags |= MF_POPUP;
3533 menu->bTimeToHide = FALSE;
3534 return hmenu;
3535}
3536
3537
3538/**********************************************************************
3539 * GetMenuCheckMarkDimensions (USER.417) (USER32.258)
3540 */
3541DWORD WINAPI GetMenuCheckMarkDimensions(void)
3542{
3543 dprintf(("USER32: GetMenuCheckMarkDimensions"));
3544
3545 return MAKELONG( check_bitmap_width, check_bitmap_height );
3546}
3547
3548
3549/**********************************************************************
3550 * SetMenuItemBitmaps32 (USER32.490)
3551 */
3552BOOL WINAPI SetMenuItemBitmaps(HMENU hMenu, UINT nPos, UINT wFlags,
3553 HBITMAP hNewUnCheck, HBITMAP hNewCheck)
3554{
3555 MENUITEM *item;
3556
3557 dprintf(("USER32: SetMenuItemBitmaps %x %d %x %x %x", hMenu, nPos, wFlags, hNewCheck, hNewUnCheck));
3558
3559 //TRACE("(%04x, %04x, %04x, %04x, %04x)\n",
3560 // hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
3561 if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
3562
3563 if (!hNewCheck && !hNewUnCheck)
3564 {
3565 item->fState &= ~MF_USECHECKBITMAPS;
3566 }
3567 else /* Install new bitmaps */
3568 {
3569 item->hCheckBit = hNewCheck;
3570 item->hUnCheckBit = hNewUnCheck;
3571 item->fState |= MF_USECHECKBITMAPS;
3572 }
3573 return TRUE;
3574}
3575
3576
3577/**********************************************************************
3578 * CreateMenu (USER32.81)
3579 */
3580HMENU WINAPI CreateMenu(void)
3581{
3582 HMENU hMenu;
3583 LPPOPUPMENU menu;
3584
3585 dprintf(("USER32: CreateMenu"));
3586
3587 if (!(hMenu = (HMENU)HeapAlloc(GetProcessHeap(),0,sizeof(POPUPMENU)))) return 0;
3588 menu = (LPPOPUPMENU)hMenu;
3589
3590 ZeroMemory(menu, sizeof(POPUPMENU));
3591 menu->wMagic = MENU_MAGIC;
3592 menu->FocusedItem = NO_SELECTED_ITEM;
3593 menu->bTimeToHide = FALSE;
3594
3595 //TRACE("return %04x\n", hMenu );
3596
3597 return hMenu;
3598}
3599
3600
3601/**********************************************************************
3602 * DestroyMenu32 (USER32.134)
3603 */
3604BOOL WINAPI DestroyMenu( HMENU hMenu )
3605{
3606 //TRACE("(%04x)\n", hMenu);
3607
3608 dprintf(("USER32: DestroyMenu %x", hMenu));
3609
3610 /* Silently ignore attempts to destroy default system popup */
3611
3612 if (hMenu && hMenu != MENU_DefSysPopup)
3613 {
3614 LPPOPUPMENU lppop = (LPPOPUPMENU)hMenu;
3615 HWND pTPWnd = MENU_GetTopPopupWnd();
3616
3617 if( pTPWnd && (hMenu == GetWindowLongA(pTPWnd,0)) )
3618 SetWindowLongA(pTPWnd,0,0);
3619
3620 if (IS_A_MENU( lppop ))
3621 {
3622 lppop->wMagic = 0; /* Mark it as destroyed */
3623
3624 if ((lppop->wFlags & MF_POPUP) && lppop->hWnd &&
3625 (!pTPWnd || (lppop->hWnd != pTPWnd)))
3626 DestroyWindow( lppop->hWnd );
3627
3628 if (lppop->items) /* recursively destroy submenus */
3629 {
3630 int i;
3631 MENUITEM *item = lppop->items;
3632 for (i = lppop->nItems; i > 0; i--, item++)
3633 {
3634 if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu);
3635 MENU_FreeItemData( item );
3636 }
3637 HeapFree(GetProcessHeap(), 0, lppop->items );
3638 }
3639 HeapFree(GetProcessHeap(),0,(LPVOID)hMenu);
3640 MENU_ReleaseTopPopupWnd();
3641 }
3642 else
3643 {
3644 MENU_ReleaseTopPopupWnd();
3645 return FALSE;
3646 }
3647 }
3648 return (hMenu != MENU_DefSysPopup);
3649}
3650
3651/**********************************************************************
3652 * GetSystemMenu32 (USER32.291)
3653 */
3654HMENU WINAPI GetSystemMenu( HWND hWnd, BOOL bRevert )
3655{
3656 HMENU retvalue = 0;
3657 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hWnd);
3658
3659 dprintf(("USER32: GetSystemMenu"));
3660
3661 if (win32wnd)
3662 {
3663 HMENU hSysMenu = getSysMenu(hWnd);
3664 if(hSysMenu)
3665 {
3666 if( bRevert )
3667 {
3668 DestroyMenu(hSysMenu);
3669 hSysMenu = 0;
3670 setSysMenu(hWnd,hSysMenu);
3671 }
3672 else
3673 {
3674 POPUPMENU *menu = (POPUPMENU*)hSysMenu;
3675 if( IS_A_MENU(menu) )
3676 {
3677 if( menu->nItems > 0 && menu->items[0].hSubMenu == MENU_DefSysPopup )
3678 menu->items[0].hSubMenu = MENU_CopySysPopup();
3679 }
3680 else
3681 {
3682 //WARN("Current sys-menu (%04x) of wnd %04x is broken\n",
3683 // wndPtr->hSysMenu, hWnd);
3684 hSysMenu = 0;
3685 setSysMenu(hWnd,hSysMenu);
3686 }
3687 }
3688 }
3689
3690 if(!hSysMenu && (GetWindowLongA(hWnd,GWL_STYLE) & WS_SYSMENU) )
3691 {
3692 hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) );
3693 setSysMenu(hWnd,hSysMenu);
3694 }
3695
3696 if( hSysMenu )
3697 {
3698 POPUPMENU *menu;
3699 retvalue = GetSubMenu(hSysMenu, 0);
3700
3701 /* Store the dummy sysmenu handle to facilitate the refresh */
3702 /* of the close button if the SC_CLOSE item change */
3703 menu = (POPUPMENU*)retvalue;
3704 if ( IS_A_MENU(menu) )
3705 menu->hSysMenuOwner = hSysMenu;
3706 }
3707 }
3708 return retvalue;
3709}
3710
3711
3712/*******************************************************************
3713 * SetSystemMenu32 (USER32.508)
3714 */
3715BOOL WINAPI SetSystemMenu( HWND hwnd, HMENU hMenu )
3716{
3717 Win32BaseWindow *win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
3718
3719 dprintf(("USER32: SetSystemMenu"));
3720
3721 if (win32wnd)
3722 {
3723 if (win32wnd->GetSysMenu()) DestroyMenu(win32wnd->GetSysMenu());
3724 win32wnd->SetSysMenu(MENU_GetSysMenu( hwnd, hMenu ));
3725 return TRUE;
3726 }
3727 return FALSE;
3728}
3729
3730/**********************************************************************
3731 * GetMenu32 (USER32.257)
3732 */
3733HMENU WINAPI GetMenu( HWND hWnd )
3734{
3735 HMENU retvalue;
3736
3737 dprintf(("USER32: GetMenu %x", hWnd));
3738
3739 if (GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) return 0;
3740 else return getMenu(hWnd);
3741}
3742
3743/**********************************************************************
3744 * SetMenu32 (USER32.487)
3745 */
3746BOOL WINAPI SetMenu( HWND hWnd, HMENU hMenu )
3747{
3748 //TRACE("(%04x, %04x);\n", hWnd, hMenu);
3749
3750 dprintf(("USER32: SetMenu %x %x", hWnd, hMenu));
3751
3752 if (hMenu && !IsMenu(hMenu))
3753 {
3754 //WARN("hMenu is not a menu handle\n");
3755 return FALSE;
3756 }
3757
3758
3759 if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD))
3760 {
3761 if (GetCapture() == hWnd) ReleaseCapture();
3762
3763 setMenu(hWnd,hMenu);
3764 if (hMenu != 0)
3765 {
3766 LPPOPUPMENU lpmenu;
3767
3768 if (!(lpmenu = (LPPOPUPMENU)hMenu))
3769 {
3770 return FALSE;
3771 }
3772 lpmenu->hWnd = hWnd;
3773 lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
3774 lpmenu->Height = 0; /* Make sure we recalculate the size */
3775 }
3776//SvL: This fixes the menu in standard mine sweeper (window isn't visible
3777// when SetMenu is called)
3778// if (IsWindowVisible(hWnd))
3779 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
3780 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
3781 return TRUE;
3782 }
3783 return FALSE;
3784}
3785
3786
3787/**********************************************************************
3788 * GetSubMenu32 (USER32.288)
3789 */
3790HMENU WINAPI GetSubMenu( HMENU hMenu, INT nPos )
3791{
3792 MENUITEM * lpmi;
3793
3794 dprintf(("USER32: GetSubMenu %x %d", nPos));
3795
3796 if (!(lpmi = MENU_FindItem(&hMenu,(UINT*)&nPos,MF_BYPOSITION))) return 0;
3797 if (!(lpmi->fType & MF_POPUP)) return 0;
3798 return lpmi->hSubMenu;
3799}
3800
3801
3802/**********************************************************************
3803 * DrawMenuBar (USER32.161)
3804 */
3805BOOL WINAPI DrawMenuBar( HWND hWnd )
3806{
3807 LPPOPUPMENU lppop;
3808
3809 dprintf(("USER32: DrawMenuBar %x", hWnd));
3810
3811 if (!(GetWindowLongA(hWnd,GWL_STYLE) & WS_CHILD) && getMenu(hWnd))
3812 {
3813 lppop = (LPPOPUPMENU)getMenu(hWnd);
3814 if (lppop == NULL)
3815 {
3816 return FALSE;
3817 }
3818
3819 lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */
3820 lppop->hwndOwner = hWnd;
3821 SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
3822 SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
3823 return TRUE;
3824 }
3825 return FALSE;
3826}
3827
3828
3829/***********************************************************************
3830 * EndMenu (USER.187) (USER32.175)
3831 */
3832void WINAPI EndMenu(void)
3833{
3834 dprintf(("USER32: EndMenu not implemented!"));
3835 /*
3836 * FIXME: NOT ENOUGH! This has to cancel menu tracking right away.
3837 */
3838
3839 fEndMenu = TRUE;
3840}
3841
3842
3843/*****************************************************************
3844 * LoadMenu32A (USER32.370)
3845 */
3846HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
3847{
3848 HRSRC hrsrc = FindResourceA( instance, name, RT_MENUA );
3849
3850 dprintf(("USER32: LoadMenuA %x %x", instance, name));
3851
3852 if (!hrsrc) return 0;
3853 return LoadMenuIndirectA( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
3854}
3855
3856
3857/*****************************************************************
3858 * LoadMenu32W (USER32.373)
3859 */
3860HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
3861{
3862 HRSRC hrsrc = FindResourceW( instance, name, RT_MENUW );
3863
3864 dprintf(("USER32: LoadMenuW %x %x", instance, name));
3865
3866 if (!hrsrc) return 0;
3867 return LoadMenuIndirectW( (MENUITEMTEMPLATEHEADER*)LoadResource( instance, hrsrc ));
3868}
3869
3870
3871/**********************************************************************
3872 * LoadMenuIndirect32A (USER32.371)
3873 */
3874HMENU WINAPI LoadMenuIndirectA(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate)
3875{
3876 HMENU hMenu;
3877 WORD version, offset;
3878 LPCSTR p = (LPCSTR)lpMenuTemplate;
3879
3880 dprintf(("USER32: LoadMenuIndirectA"));
3881
3882 //TRACE("%p\n", template );
3883 version = GET_WORD(p);
3884 p += sizeof(WORD);
3885 switch (version)
3886 {
3887 case 0:
3888 offset = GET_WORD(p);
3889 p += sizeof(WORD) + offset;
3890 if (!(hMenu = CreateMenu())) return 0;
3891 if (!MENU_ParseResource( p, hMenu, TRUE ))
3892 {
3893 DestroyMenu( hMenu );
3894 return 0;
3895 }
3896 return hMenu;
3897 case 1:
3898 offset = GET_WORD(p);
3899 p += sizeof(WORD) + offset;
3900 if (!(hMenu = CreateMenu())) return 0;
3901 if (!MENUEX_ParseResource( p, hMenu))
3902 {
3903 DestroyMenu( hMenu );
3904 return 0;
3905 }
3906 return hMenu;
3907 default:
3908 //ERR("version %d not supported.\n", version);
3909 return 0;
3910 }
3911}
3912
3913
3914/**********************************************************************
3915 * LoadMenuIndirect32W (USER32.372)
3916 */
3917HMENU WINAPI LoadMenuIndirectW(CONST MENUITEMTEMPLATEHEADER *lpMenuTemplate )
3918{
3919 dprintf(("USER32: LoadMenuIndirectW"));
3920
3921 /* FIXME: is there anything different between A and W? */
3922 return LoadMenuIndirectA(lpMenuTemplate);
3923}
3924
3925
3926/**********************************************************************
3927 * IsMenu32 (USER32.346)
3928 */
3929BOOL WINAPI IsMenu(HMENU hmenu)
3930{
3931 LPPOPUPMENU menu = (LPPOPUPMENU)hmenu;
3932
3933 dprintf(("USER32: IsMenu"));
3934
3935 return IS_A_MENU(menu);
3936}
3937
3938/**********************************************************************
3939 * GetMenuItemInfo32_common
3940 */
3941
3942static BOOL GetMenuItemInfo_common ( HMENU hmenu, UINT item, BOOL bypos,
3943 LPMENUITEMINFOA lpmii, BOOL unicode)
3944{
3945 MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0);
3946
3947 //debug_print_menuitem("GetMenuItemInfo32_common: ", menu, "");
3948
3949 if (!menu)
3950 return FALSE;
3951
3952 if (lpmii->fMask & MIIM_TYPE) {
3953 lpmii->fType = menu->fType;
3954 switch (MENU_ITEM_TYPE(menu->fType)) {
3955 case MF_STRING:
3956 if (menu->text && lpmii->dwTypeData && lpmii->cch) {
3957 if (unicode) {
3958 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
3959 lpmii->cch = lstrlenW((LPWSTR)menu->text);
3960 } else {
3961 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
3962 lpmii->cch = lstrlenA(menu->text);
3963 }
3964 }
3965 break;
3966 case MF_OWNERDRAW:
3967 case MF_BITMAP:
3968 lpmii->dwTypeData = menu->text;
3969 /* fall through */
3970 default:
3971 lpmii->cch = 0;
3972 }
3973 }
3974
3975 if (lpmii->fMask & MIIM_STRING) {
3976 if (unicode) {
3977 lstrcpynAtoW((LPWSTR) lpmii->dwTypeData, menu->text, lpmii->cch);
3978 lpmii->cch = lstrlenW((LPWSTR)menu->text);
3979 } else {
3980 lstrcpynA(lpmii->dwTypeData, menu->text, lpmii->cch);
3981 lpmii->cch = lstrlenA(menu->text);
3982 }
3983 }
3984
3985 if (lpmii->fMask & MIIM_FTYPE)
3986 lpmii->fType = menu->fType;
3987
3988 if (lpmii->fMask & MIIM_BITMAP)
3989 lpmii->hbmpItem = menu->hbmpItem;
3990
3991 if (lpmii->fMask & MIIM_STATE)
3992 lpmii->fState = menu->fState;
3993
3994 if (lpmii->fMask & MIIM_ID)
3995 lpmii->wID = menu->wID;
3996
3997 if (lpmii->fMask & MIIM_SUBMENU)
3998 lpmii->hSubMenu = menu->hSubMenu;
3999
4000 if (lpmii->fMask & MIIM_CHECKMARKS) {
4001 lpmii->hbmpChecked = menu->hCheckBit;
4002 lpmii->hbmpUnchecked = menu->hUnCheckBit;
4003 }
4004 if (lpmii->fMask & MIIM_DATA)
4005 lpmii->dwItemData = menu->dwItemData;
4006
4007 return TRUE;
4008}
4009
4010/**********************************************************************
4011 * GetMenuItemInfoA (USER32.264)
4012 */
4013BOOL WINAPI GetMenuItemInfoA( HMENU hmenu, UINT item, BOOL bypos,
4014 LPMENUITEMINFOA lpmii)
4015{
4016 dprintf(("USER32: GetMenuItemInfoA"));
4017
4018 return GetMenuItemInfo_common (hmenu, item, bypos, lpmii, FALSE);
4019}
4020
4021/**********************************************************************
4022 * GetMenuItemInfoW (USER32.265)
4023 */
4024BOOL WINAPI GetMenuItemInfoW( HMENU hmenu, UINT item, BOOL bypos,
4025 LPMENUITEMINFOW lpmii)
4026{
4027 dprintf(("USER32: GetMenuItemInfoW"));
4028
4029 return GetMenuItemInfo_common (hmenu, item, bypos,
4030 (LPMENUITEMINFOA)lpmii, TRUE);
4031}
4032
4033/**********************************************************************
4034 * SetMenuItemInfo32_common
4035 */
4036
4037static BOOL SetMenuItemInfo_common(MENUITEM * menu,
4038 const MENUITEMINFOA *lpmii,
4039 BOOL unicode)
4040{
4041 if (!menu) return FALSE;
4042
4043 if (lpmii->fMask & MIIM_TYPE ) {
4044 /* Get rid of old string. */
4045 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4046 HeapFree(GetProcessHeap(), 0, menu->text);
4047 menu->text = NULL;
4048 }
4049
4050 /* make only MENU_ITEM_TYPE bits in menu->fType equal lpmii->fType */
4051 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4052 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4053
4054 menu->text = lpmii->dwTypeData;
4055
4056 if (IS_STRING_ITEM(menu->fType) && menu->text) {
4057 if (unicode)
4058 menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
4059 else
4060 menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
4061 }
4062 }
4063
4064 if (lpmii->fMask & MIIM_FTYPE ) {
4065 /* free the string when the type is changing */
4066 if ( (!IS_STRING_ITEM(lpmii->fType)) && IS_STRING_ITEM(menu->fType) && menu->text) {
4067 HeapFree(GetProcessHeap(), 0, menu->text);
4068 menu->text = NULL;
4069 }
4070 menu->fType &= ~MENU_ITEM_TYPE(menu->fType);
4071 menu->fType |= MENU_ITEM_TYPE(lpmii->fType);
4072 }
4073
4074 if (lpmii->fMask & MIIM_STRING ) {
4075 /* free the string when used */
4076 if ( IS_STRING_ITEM(menu->fType) && menu->text) {
4077 HeapFree(GetProcessHeap(), 0, menu->text);
4078 if (unicode)
4079 menu->text = HEAP_strdupWtoA(GetProcessHeap(), 0, (LPWSTR) lpmii->dwTypeData);
4080 else
4081 menu->text = HEAP_strdupA(GetProcessHeap(), 0, lpmii->dwTypeData);
4082 }
4083 }
4084
4085 if (lpmii->fMask & MIIM_STATE)
4086 {
4087 /* fixme: MFS_DEFAULT do we have to reset the other menu items? */
4088 menu->fState = lpmii->fState;
4089 }
4090
4091 if (lpmii->fMask & MIIM_ID)
4092 menu->wID = lpmii->wID;
4093
4094 if (lpmii->fMask & MIIM_SUBMENU) {
4095 menu->hSubMenu = lpmii->hSubMenu;
4096 if (menu->hSubMenu) {
4097 POPUPMENU *subMenu = (POPUPMENU*)(UINT)menu->hSubMenu;
4098 if (IS_A_MENU(subMenu)) {
4099 subMenu->wFlags |= MF_POPUP;
4100 menu->fType |= MF_POPUP;
4101 }
4102 else
4103 /* FIXME: Return an error ? */
4104 menu->fType &= ~MF_POPUP;
4105 }
4106 else
4107 menu->fType &= ~MF_POPUP;
4108 }
4109
4110 if (lpmii->fMask & MIIM_CHECKMARKS)
4111 {
4112 menu->hCheckBit = lpmii->hbmpChecked;
4113 menu->hUnCheckBit = lpmii->hbmpUnchecked;
4114 }
4115 if (lpmii->fMask & MIIM_DATA)
4116 menu->dwItemData = lpmii->dwItemData;
4117
4118 //debug_print_menuitem("SetMenuItemInfo32_common: ", menu, "");
4119 return TRUE;
4120}
4121
4122/**********************************************************************
4123 * SetMenuItemInfo32A (USER32.491)
4124 */
4125BOOL WINAPI SetMenuItemInfoA(HMENU hmenu, UINT item, BOOL bypos,
4126 const MENUITEMINFOA *lpmii)
4127{
4128 dprintf(("USER32: SetMenuItemInfoA %x %d %d %x", hmenu, item, bypos, lpmii));
4129
4130 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4131 lpmii, FALSE);
4132}
4133
4134/**********************************************************************
4135 * SetMenuItemInfo32W (USER32.492)
4136 */
4137BOOL WINAPI SetMenuItemInfoW(HMENU hmenu, UINT item, BOOL bypos,
4138 const MENUITEMINFOW *lpmii)
4139{
4140 dprintf(("USER32: SetMenuItemInfoW"));
4141
4142 return SetMenuItemInfo_common(MENU_FindItem(&hmenu, &item, bypos? MF_BYPOSITION : 0),
4143 (const MENUITEMINFOA*)lpmii, TRUE);
4144}
4145
4146/**********************************************************************
4147 * SetMenuDefaultItem (USER32.489)
4148 *
4149 */
4150BOOL WINAPI SetMenuDefaultItem(HMENU hmenu, UINT uItem, UINT bypos)
4151{
4152 UINT i;
4153 POPUPMENU *menu;
4154 MENUITEM *item;
4155
4156
4157 dprintf(("USER32: SetMenuDefaultItem"));
4158 //TRACE("(0x%x,%d,%d)\n", hmenu, uItem, bypos);
4159
4160 if (!(menu = (POPUPMENU*)hmenu)) return FALSE;
4161
4162 /* reset all default-item flags */
4163 item = menu->items;
4164 for (i = 0; i < menu->nItems; i++, item++)
4165 {
4166 item->fState &= ~MFS_DEFAULT;
4167 }
4168
4169 /* no default item */
4170 if ( -1 == uItem)
4171 {
4172 return TRUE;
4173 }
4174
4175 item = menu->items;
4176 if ( bypos )
4177 {
4178 if ( uItem >= menu->nItems ) return FALSE;
4179 item[uItem].fState |= MFS_DEFAULT;
4180 return TRUE;
4181 }
4182 else
4183 {
4184 for (i = 0; i < menu->nItems; i++, item++)
4185 {
4186 if (item->wID == uItem)
4187 {
4188 item->fState |= MFS_DEFAULT;
4189 return TRUE;
4190 }
4191 }
4192
4193 }
4194 return FALSE;
4195}
4196
4197/**********************************************************************
4198 * GetMenuDefaultItem (USER32.260)
4199 */
4200UINT WINAPI GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags)
4201{
4202 POPUPMENU *menu;
4203 MENUITEM * item;
4204 UINT i = 0;
4205
4206 dprintf(("USER32: GetMenuDefaultItem"));
4207 //TRACE("(0x%x,%d,%d)\n", hmenu, bypos, flags);
4208
4209 if (!(menu = (POPUPMENU*)hmenu)) return -1;
4210
4211 /* find default item */
4212 item = menu->items;
4213
4214 /* empty menu */
4215 if (! item) return -1;
4216
4217 while ( !( item->fState & MFS_DEFAULT ) )
4218 {
4219 i++; item++;
4220 if (i >= menu->nItems ) return -1;
4221 }
4222
4223 /* default: don't return disabled items */
4224 if ( (!(GMDI_USEDISABLED & flags)) && (item->fState & MFS_DISABLED )) return -1;
4225
4226 /* search rekursiv when needed */
4227 if ( (item->fType & MF_POPUP) && (flags & GMDI_GOINTOPOPUPS) )
4228 {
4229 UINT ret;
4230 ret = GetMenuDefaultItem( item->hSubMenu, bypos, flags );
4231 if ( -1 != ret ) return ret;
4232
4233 /* when item not found in submenu, return the popup item */
4234 }
4235 return ( bypos ) ? i : item->wID;
4236
4237}
4238
4239/**********************************************************************
4240 * InsertMenuItem32A (USER32.323)
4241 */
4242BOOL WINAPI InsertMenuItemA(HMENU hMenu, UINT uItem, BOOL bypos,
4243 const MENUITEMINFOA *lpmii)
4244{
4245 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
4246
4247 dprintf(("USER32: InsertMenuItemA %x %d %d %x", hMenu, uItem, bypos, lpmii->wID));
4248
4249 return SetMenuItemInfo_common(item, lpmii, FALSE);
4250}
4251
4252
4253/**********************************************************************
4254 * InsertMenuItem32W (USER32.324)
4255 */
4256BOOL WINAPI InsertMenuItemW(HMENU hMenu, UINT uItem, BOOL bypos,
4257 const MENUITEMINFOW *lpmii)
4258{
4259 MENUITEM *item = MENU_InsertItem(hMenu, uItem, bypos ? MF_BYPOSITION : 0 );
4260
4261 dprintf(("USER32: InsertMenuItemW"));
4262
4263 return SetMenuItemInfo_common(item, (const MENUITEMINFOA*)lpmii, TRUE);
4264}
4265
4266/**********************************************************************
4267 * CheckMenuRadioItem32 (USER32.47)
4268 */
4269
4270BOOL WINAPI CheckMenuRadioItem(HMENU hMenu,
4271 UINT first, UINT last, UINT check,
4272 UINT bypos)
4273{
4274 MENUITEM *mifirst, *milast, *micheck;
4275 HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu;
4276
4277 dprintf(("USER32: CheckMenuRadioItem"));
4278 //TRACE("ox%x: %d-%d, check %d, bypos=%d\n",
4279 // hMenu, first, last, check, bypos);
4280
4281 mifirst = MENU_FindItem (&mfirst, &first, bypos);
4282 milast = MENU_FindItem (&mlast, &last, bypos);
4283 micheck = MENU_FindItem (&mcheck, &check, bypos);
4284
4285 if (mifirst == NULL || milast == NULL || micheck == NULL ||
4286 mifirst > milast || mfirst != mlast || mfirst != mcheck ||
4287 micheck > milast || micheck < mifirst)
4288 return FALSE;
4289
4290 while (mifirst <= milast)
4291 {
4292 if (mifirst == micheck)
4293 {
4294 mifirst->fType |= MFT_RADIOCHECK;
4295 mifirst->fState |= MFS_CHECKED;
4296 } else {
4297 mifirst->fType &= ~MFT_RADIOCHECK;
4298 mifirst->fState &= ~MFS_CHECKED;
4299 }
4300 mifirst++;
4301 }
4302
4303 return TRUE;
4304}
4305
4306/**********************************************************************
4307 * GetMenuItemRect32 (USER32.266)
4308 *
4309 * ATTENTION: Here, the returned values in rect are the screen
4310 * coordinates of the item just like if the menu was
4311 * always on the upper left side of the application.
4312 *
4313 */
4314BOOL WINAPI GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem,
4315 LPRECT rect)
4316{
4317 POPUPMENU *itemMenu;
4318 MENUITEM *item;
4319 HWND referenceHwnd;
4320
4321 //TRACE("(0x%x,0x%x,%d,%p)\n", hwnd, hMenu, uItem, rect);
4322
4323 item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION);
4324 referenceHwnd = hwnd;
4325
4326 if(!hwnd)
4327 {
4328 itemMenu = (POPUPMENU*)hMenu;
4329 if (itemMenu == NULL) {
4330 SetLastError(ERROR_INVALID_PARAMETER);
4331 return FALSE;
4332 }
4333
4334 if(itemMenu->hWnd == 0)
4335 return FALSE;
4336 referenceHwnd = itemMenu->hWnd;
4337 }
4338
4339 if ((rect == NULL) || (item == NULL)) {
4340 SetLastError(ERROR_INVALID_PARAMETER);
4341 return FALSE;
4342 }
4343 *rect = item->rect;
4344
4345 MapWindowPoints(referenceHwnd, 0, (LPPOINT)rect, 2);
4346 dprintf(("USER32: GetMenuItemRect %x %x %d (%d,%d)(%d,%d)", hwnd, hMenu, uItem, rect->left, rect->top, rect->right, rect->bottom));
4347
4348 return TRUE;
4349}
4350
4351/**********************************************************************
4352 * SetMenuInfo
4353 *
4354 * FIXME
4355 * MIM_APPLYTOSUBMENUS
4356 * actually use the items to draw the menu
4357 */
4358BOOL WINAPI SetMenuInfo (HMENU hMenu, LPCMENUINFO lpmi)
4359{
4360 POPUPMENU *menu;
4361
4362 dprintf(("USER32: SetMenuInfo"));
4363 //TRACE("(0x%04x %p)\n", hMenu, lpmi);
4364
4365 if (lpmi && (lpmi->cbSize==sizeof(MENUINFO)) && (menu=(POPUPMENU*)hMenu))
4366 {
4367
4368 if (lpmi->fMask & MIM_BACKGROUND)
4369 menu->hbrBack = lpmi->hbrBack;
4370
4371 if (lpmi->fMask & MIM_HELPID)
4372 menu->dwContextHelpID = lpmi->dwContextHelpID;
4373
4374 if (lpmi->fMask & MIM_MAXHEIGHT)
4375 menu->cyMax = lpmi->cyMax;
4376
4377 if (lpmi->fMask & MIM_MENUDATA)
4378 menu->dwMenuData = lpmi->dwMenuData;
4379
4380 if (lpmi->fMask & MIM_STYLE)
4381 menu->dwStyle = lpmi->dwStyle;
4382
4383 return TRUE;
4384 }
4385 return FALSE;
4386}
4387
4388/**********************************************************************
4389 * GetMenuInfo
4390 *
4391 * NOTES
4392 * win98/NT5.0
4393 *
4394 */
4395BOOL WINAPI GetMenuInfo (HMENU hMenu, LPMENUINFO lpmi)
4396{ POPUPMENU *menu;
4397
4398 dprintf(("USER32: GetMenuInfo"));
4399 //TRACE("(0x%04x %p)\n", hMenu, lpmi);
4400
4401 if (lpmi && (menu = (POPUPMENU*)hMenu))
4402 {
4403
4404 if (lpmi->fMask & MIM_BACKGROUND)
4405 lpmi->hbrBack = menu->hbrBack;
4406
4407 if (lpmi->fMask & MIM_HELPID)
4408 lpmi->dwContextHelpID = menu->dwContextHelpID;
4409
4410 if (lpmi->fMask & MIM_MAXHEIGHT)
4411 lpmi->cyMax = menu->cyMax;
4412
4413 if (lpmi->fMask & MIM_MENUDATA)
4414 lpmi->dwMenuData = menu->dwMenuData;
4415
4416 if (lpmi->fMask & MIM_STYLE)
4417 lpmi->dwStyle = menu->dwStyle;
4418
4419 return TRUE;
4420 }
4421 return FALSE;
4422}
4423
4424/**********************************************************************
4425 * SetMenuContextHelpId (USER32.488)
4426 */
4427BOOL WINAPI SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpID)
4428{
4429 LPPOPUPMENU menu;
4430
4431 dprintf(("USER32: SetMenuContextHelpId"));
4432 //TRACE("(0x%04x 0x%08lx)\n", hMenu, dwContextHelpID);
4433
4434 menu = (POPUPMENU*)hMenu;
4435 if (menu)
4436 {
4437 menu->dwContextHelpID = dwContextHelpID;
4438 return TRUE;
4439 }
4440 return FALSE;
4441}
4442
4443/**********************************************************************
4444 * GetMenuContextHelpId (USER32.488)
4445 */
4446DWORD WINAPI GetMenuContextHelpId( HMENU hMenu )
4447{
4448 LPPOPUPMENU menu;
4449
4450 dprintf(("USER32: GetMenuContextHelpId"));
4451 //TRACE("(0x%04x)\n", hMenu);
4452
4453 menu = (POPUPMENU*)hMenu;
4454 if (menu)
4455 {
4456 return menu->dwContextHelpID;
4457 }
4458 return 0;
4459}
4460
4461/**********************************************************************
4462 * MenuItemFromPoint (USER32.387)
4463 */
4464UINT WINAPI MenuItemFromPoint(HWND hWnd, HMENU hMenu, POINT ptScreen)
4465{
4466 dprintf(("USER32: MenuItemFromPoint not implemented!"));
4467 //FIXME("(0x%04x,0x%04x,(%ld,%ld)):stub\n",
4468 // hWnd, hMenu, ptScreen.x, ptScreen.y);
4469 return 0;
4470}
4471
4472BOOL POPUPMENU_Register()
4473{
4474 WNDCLASSA wndClass;
4475 BOOL rc;
4476
4477//SvL: Don't check this now
4478// if (GlobalFindAtomA(POPUPMENUCLASSNAME)) return FALSE;
4479
4480 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
4481 wndClass.style = CS_GLOBALCLASS | CS_SAVEBITS;
4482 wndClass.lpfnWndProc = (WNDPROC)PopupMenuWndProc;
4483 wndClass.cbClsExtra = 0;
4484 wndClass.cbWndExtra = sizeof(HMENU);
4485 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);
4486 wndClass.hbrBackground = NULL_BRUSH;
4487 wndClass.lpszClassName = POPUPMENUCLASSNAME;
4488
4489 rc = RegisterClassA(&wndClass);
4490 MENU_Init();
4491
4492 return rc;
4493}
4494//******************************************************************************
4495//******************************************************************************
4496BOOL POPUPMENU_Unregister()
4497{
4498 if (GlobalFindAtomA(POPUPMENUCLASSNAME))
4499 return UnregisterClassA(POPUPMENUCLASSNAME,(HINSTANCE)NULL);
4500 else return FALSE;
4501}
4502//******************************************************************************
4503//******************************************************************************
4504
Note: See TracBrowser for help on using the repository browser.