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

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

fixed dialog rect

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