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

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

several nc changes

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