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

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

menu and titlebar fix, some new stubs

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