4 * Copyright 1993 Martin Ayotte
5 * Copyright 1994 Alexandre Julliard
9 * Note: the style MF_MOUSESELECT is used to mark popup items that
10 * have been selected, i.e. their popup menu is currently displayed.
11 * This is probably not the meaning this style has in MS-Windows.
20 #include "sysmetrics.h"
28 /* #define DEBUG_MENU */
29 /* #define DEBUG_MENUCALC */
30 /* #define DEBUG_MENUSHORTCUT */
34 /* Dimension of the menu bitmaps */
35 static WORD check_bitmap_width
= 0, check_bitmap_height
= 0;
36 static WORD arrow_bitmap_width
= 0, arrow_bitmap_height
= 0;
38 /* Flag set by EndMenu() to force an exit from menu tracking */
39 static BOOL fEndMenuCalled
= FALSE
;
41 /* Space between 2 menu bar items */
42 #define MENU_BAR_ITEMS_SPACE 16
44 /* Minimum width of a tab character */
45 #define MENU_TAB_SPACE 8
47 /* Height of a separator item */
48 #define SEPARATOR_HEIGHT 5
50 /* Values for menu->FocusedItem */
51 /* (other values give the position of the focused item) */
52 #define NO_SELECTED_ITEM 0xffff
53 #define SYSMENU_SELECTED 0xfffe /* Only valid on menu-bars */
55 #define IS_STRING_ITEM(flags) (!((flags) & (MF_BITMAP | MF_OWNERDRAW | \
56 MF_MENUBARBREAK | MF_MENUBREAK | MF_SEPARATOR)))
59 extern void NC_DrawSysButton(HWND hwnd
, HDC hdc
, BOOL down
); /* nonclient.c */
61 static HBITMAP hStdCheck
= 0;
62 static HBITMAP hStdMnArrow
= 0;
65 WORD
* ParseMenuResource(WORD
*first_item
, int level
, HMENU hMenu
);
68 /***********************************************************************
71 * Menus initialisation.
79 if (!(hStdCheck
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_CHECK
) )))
81 GetObject( hStdCheck
, sizeof(BITMAP
), (LPSTR
)&bm
);
82 check_bitmap_width
= bm
.bmWidth
;
83 check_bitmap_height
= bm
.bmHeight
;
84 if (!(hStdMnArrow
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_MNARROW
) )))
86 GetObject( hStdMnArrow
, sizeof(BITMAP
), (LPSTR
)&bm
);
87 arrow_bitmap_width
= bm
.bmWidth
;
88 arrow_bitmap_height
= bm
.bmHeight
;
94 /***********************************************************************
97 * Check whether the window owning the menu bar has a system menu.
99 static BOOL
MENU_HasSysMenu( POPUPMENU
*menu
)
103 if (menu
->wFlags
& MF_POPUP
) return FALSE
;
104 if (!(wndPtr
= WIN_FindWndPtr( menu
->hWnd
))) return FALSE
;
105 return (wndPtr
->dwStyle
& WS_SYSMENU
) != 0;
109 /***********************************************************************
112 * Check whether the point (in screen coords) is in the system menu
113 * of the window owning the given menu.
115 static BOOL
MENU_IsInSysMenu( POPUPMENU
*menu
, POINT pt
)
119 if (menu
->wFlags
& MF_POPUP
) return FALSE
;
120 if (!(wndPtr
= WIN_FindWndPtr( menu
->hWnd
))) return FALSE
;
121 if (!(wndPtr
->dwStyle
& WS_SYSMENU
)) return FALSE
;
122 if ((pt
.x
< wndPtr
->rectClient
.left
) ||
123 (pt
.x
>= wndPtr
->rectClient
.left
+SYSMETRICS_CXSIZE
+SYSMETRICS_CXBORDER
))
125 if ((pt
.y
>= wndPtr
->rectClient
.top
- menu
->Height
) ||
126 (pt
.y
< wndPtr
->rectClient
.top
- menu
->Height
-
127 SYSMETRICS_CYSIZE
- SYSMETRICS_CYBORDER
)) return FALSE
;
132 /***********************************************************************
135 * Find a menu item. Return a pointer on the item, and modifies *hmenu
136 * in case the item was in a sub-menu.
138 static MENUITEM
*MENU_FindItem( HMENU
*hmenu
, WORD
*nPos
, WORD wFlags
)
144 if (!(menu
= (POPUPMENU
*) USER_HEAP_ADDR(*hmenu
))) return NULL
;
145 item
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
146 if (wFlags
& MF_BYPOSITION
)
148 if (*nPos
>= menu
->nItems
) return NULL
;
153 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
155 if (item
->item_id
== *nPos
)
160 else if (item
->item_flags
& MF_POPUP
)
162 HMENU hsubmenu
= (HMENU
)item
->item_id
;
163 MENUITEM
*subitem
= MENU_FindItem( &hsubmenu
, nPos
, wFlags
);
176 /***********************************************************************
177 * MENU_FindItemByCoords
179 * Find the item at the specified coordinates (screen coords).
181 static MENUITEM
*MENU_FindItemByCoords( POPUPMENU
*menu
, int x
, int y
, WORD
*pos
)
187 if (!(wndPtr
= WIN_FindWndPtr( menu
->hWnd
))) return NULL
;
188 x
-= wndPtr
->rectWindow
.left
;
189 y
-= wndPtr
->rectWindow
.top
;
190 item
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
191 for (i
= 0; i
< menu
->nItems
; i
++, item
++)
193 if ((x
>= item
->rect
.left
) && (x
< item
->rect
.right
) &&
194 (y
>= item
->rect
.top
) && (y
< item
->rect
.bottom
))
204 /***********************************************************************
207 * Find the menu item selected by a key press.
208 * Return item id, -1 if none, -2 if we should close the menu.
210 static WORD
MENU_FindItemByKey( HWND hwndOwner
, HMENU hmenu
, WORD key
)
217 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
218 lpitem
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
220 for (i
= 0; i
< menu
->nItems
; i
++, lpitem
++)
222 if (IS_STRING_ITEM(lpitem
->item_flags
))
224 char *p
= strchr( lpitem
->item_text
, '&' );
225 if (p
&& (p
[1] != '&') && (toupper(p
[1]) == key
)) return i
;
228 menuchar
= SendMessage( hwndOwner
, WM_MENUCHAR
, key
,
229 MAKELONG( menu
->wFlags
, hmenu
) );
230 if (HIWORD(menuchar
) == 2) return LOWORD(menuchar
);
231 if (HIWORD(menuchar
) == 1) return -2;
236 /***********************************************************************
239 * Calculate the size of the menu item and store it in lpitem->rect.
241 static void MENU_CalcItemSize( HDC hdc
, LPMENUITEM lpitem
, HWND hwndOwner
,
242 int orgX
, int orgY
, BOOL menuBar
)
247 SetRect( &lpitem
->rect
, orgX
, orgY
, orgX
, orgY
);
250 if (lpitem
->item_flags
& MF_SEPARATOR
)
252 lpitem
->rect
.bottom
+= SEPARATOR_HEIGHT
;
258 lpitem
->rect
.right
+= 2 * check_bitmap_width
;
259 if (lpitem
->item_flags
& MF_POPUP
)
260 lpitem
->rect
.right
+= arrow_bitmap_width
;
263 if (lpitem
->item_flags
& MF_BITMAP
)
266 GetObject( (HBITMAP
)lpitem
->hText
, sizeof(BITMAP
), (LPSTR
)&bm
);
267 lpitem
->rect
.right
+= bm
.bmWidth
;
268 lpitem
->rect
.bottom
+= bm
.bmHeight
;
272 /* If we get here, then it is a text item */
274 dwSize
= (lpitem
->item_text
== NULL
) ? 0 : GetTextExtent( hdc
, lpitem
->item_text
, strlen(lpitem
->item_text
));
275 lpitem
->rect
.right
+= LOWORD(dwSize
);
276 lpitem
->rect
.bottom
+= max( HIWORD(dwSize
), SYSMETRICS_CYMENU
);
278 if (menuBar
) lpitem
->rect
.right
+= MENU_BAR_ITEMS_SPACE
;
279 else if ((p
= strchr( lpitem
->item_text
, '\t' )) != NULL
)
281 /* Item contains a tab (only meaningful in popup menus) */
282 lpitem
->xTab
= check_bitmap_width
+ MENU_TAB_SPACE
+
283 LOWORD( GetTextExtent( hdc
, lpitem
->item_text
,
284 (int)(p
- lpitem
->item_text
) ));
285 lpitem
->rect
.right
+= MENU_TAB_SPACE
;
289 if (strchr( lpitem
->item_text
, '\b' ))
290 lpitem
->rect
.right
+= MENU_TAB_SPACE
;
291 lpitem
->xTab
= lpitem
->rect
.right
- check_bitmap_width
292 - arrow_bitmap_width
;
297 /***********************************************************************
298 * MENU_PopupMenuCalcSize
300 * Calculate the size of a popup menu.
302 static void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop
, HWND hwndOwner
)
304 LPMENUITEM items
, lpitem
;
307 int orgX
, orgY
, maxX
, maxTab
, maxTabWidth
;
309 lppop
->Width
= lppop
->Height
= 0;
310 if (lppop
->nItems
== 0) return;
311 items
= (MENUITEM
*)USER_HEAP_ADDR( lppop
->hItems
);
314 while (start
< lppop
->nItems
)
316 lpitem
= &items
[start
];
319 maxTab
= maxTabWidth
= 0;
321 /* Parse items until column break or end of menu */
322 for (i
= start
; i
< lppop
->nItems
; i
++, lpitem
++)
325 (lpitem
->item_flags
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
326 MENU_CalcItemSize( hdc
, lpitem
, hwndOwner
, orgX
, orgY
, FALSE
);
327 maxX
= max( maxX
, lpitem
->rect
.right
);
328 orgY
= lpitem
->rect
.bottom
;
331 maxTab
= max( maxTab
, lpitem
->xTab
);
332 maxTabWidth
= max(maxTabWidth
,lpitem
->rect
.right
-lpitem
->xTab
);
336 /* Finish the column (set all items to the largest width found) */
337 maxX
= max( maxX
, maxTab
+ maxTabWidth
);
338 for (lpitem
= &items
[start
]; start
< i
; start
++, lpitem
++)
340 lpitem
->rect
.right
= maxX
;
341 if (lpitem
->xTab
) lpitem
->xTab
= maxTab
;
343 lppop
->Height
= max( lppop
->Height
, orgY
);
351 /***********************************************************************
352 * MENU_MenuBarCalcSize
354 * Calculate the size of the menu bar.
356 static void MENU_MenuBarCalcSize( HDC hdc
, LPRECT lprect
, LPPOPUPMENU lppop
,
359 LPMENUITEM lpitem
, items
;
360 int start
, i
, orgX
, orgY
, maxY
, helpPos
;
362 if ((lprect
== NULL
) || (lppop
== NULL
)) return;
363 if (lppop
->nItems
== 0) return;
364 dprintf_menucalc(stddeb
,"MenuBarCalcSize left=%d top=%d right=%d bottom=%d !\n",
365 lprect
->left
, lprect
->top
, lprect
->right
, lprect
->bottom
);
366 items
= (MENUITEM
*)USER_HEAP_ADDR( lppop
->hItems
);
367 lppop
->Width
= lprect
->right
- lprect
->left
;
372 while (start
< lppop
->nItems
)
374 lpitem
= &items
[start
];
378 /* Parse items until line break or end of menu */
379 for (i
= start
; i
< lppop
->nItems
; i
++, lpitem
++)
381 if ((helpPos
== -1) && (lpitem
->item_flags
& MF_HELP
)) helpPos
= i
;
383 (lpitem
->item_flags
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
384 MENU_CalcItemSize( hdc
, lpitem
, hwndOwner
, orgX
, orgY
, TRUE
);
385 if (lpitem
->rect
.right
> lprect
->right
)
387 if (i
!= start
) break;
388 else lpitem
->rect
.right
= lprect
->right
;
390 maxY
= max( maxY
, lpitem
->rect
.bottom
);
391 orgX
= lpitem
->rect
.right
;
394 /* Finish the line (set all items to the largest height found) */
395 while (start
< i
) items
[start
++].rect
.bottom
= maxY
;
398 lprect
->bottom
= maxY
;
399 lppop
->Height
= lprect
->bottom
- lprect
->top
;
401 /* Flush right all items between the MF_HELP and the last item */
402 /* (if several lines, only move the last line) */
405 lpitem
= &items
[lppop
->nItems
-1];
406 orgY
= lpitem
->rect
.top
;
407 orgX
= lprect
->right
;
408 for (i
= lppop
->nItems
- 1; i
>= helpPos
; i
--, lpitem
--)
410 if (lpitem
->rect
.top
!= orgY
) break; /* Other line */
411 if (lpitem
->rect
.right
>= orgX
) break; /* Too far right already */
412 lpitem
->rect
.left
+= orgX
- lpitem
->rect
.right
;
413 lpitem
->rect
.right
= orgX
;
414 orgX
= lpitem
->rect
.left
;
420 /***********************************************************************
423 * Draw a single menu item.
425 static void MENU_DrawMenuItem( HDC hdc
, LPMENUITEM lpitem
,
426 WORD height
, BOOL menuBar
)
430 if (menuBar
&& (lpitem
->item_flags
& MF_SEPARATOR
)) return;
433 /* Draw the background */
435 if (lpitem
->item_flags
& MF_HILITE
)
436 FillRect( hdc
, &rect
, sysColorObjects
.hbrushHighlight
);
437 else FillRect( hdc
, &rect
, sysColorObjects
.hbrushMenu
);
438 SetBkMode( hdc
, TRANSPARENT
);
440 /* Draw the separator bar (if any) */
442 if (!menuBar
&& (lpitem
->item_flags
& MF_MENUBARBREAK
))
444 SelectObject( hdc
, sysColorObjects
.hpenWindowFrame
);
445 MoveTo( hdc
, rect
.left
, 0 );
446 LineTo( hdc
, rect
.left
, height
);
448 if (lpitem
->item_flags
& MF_SEPARATOR
)
450 SelectObject( hdc
, sysColorObjects
.hpenWindowFrame
);
451 MoveTo( hdc
, rect
.left
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
452 LineTo( hdc
, rect
.right
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
458 if (lpitem
->item_flags
& MF_HILITE
)
460 if (lpitem
->item_flags
& MF_GRAYED
)
461 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
463 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
464 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
468 if (lpitem
->item_flags
& MF_GRAYED
)
469 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
471 SetTextColor( hdc
, GetSysColor( COLOR_MENUTEXT
) );
472 SetBkColor( hdc
, GetSysColor( COLOR_MENU
) );
477 /* Draw the check mark */
479 if (lpitem
->item_flags
& MF_CHECKED
)
481 GRAPH_DrawBitmap(hdc
, lpitem
->hCheckBit
? lpitem
->hCheckBit
:
482 hStdCheck
, rect
.left
,
483 (rect
.top
+rect
.bottom
-check_bitmap_height
) / 2,
484 0, 0, check_bitmap_width
, check_bitmap_height
);
486 else if (lpitem
->hUnCheckBit
!= 0) /* Not checked */
488 GRAPH_DrawBitmap(hdc
, lpitem
->hUnCheckBit
, rect
.left
,
489 (rect
.top
+rect
.bottom
-check_bitmap_height
) / 2,
490 0, 0, check_bitmap_width
, check_bitmap_height
);
493 /* Draw the popup-menu arrow */
495 if (lpitem
->item_flags
& MF_POPUP
)
497 GRAPH_DrawBitmap( hdc
, hStdMnArrow
,
498 rect
.right
-arrow_bitmap_width
-1,
499 (rect
.top
+rect
.bottom
-arrow_bitmap_height
) / 2,
500 0, 0, arrow_bitmap_width
, arrow_bitmap_height
);
503 rect
.left
+= check_bitmap_width
;
504 rect
.right
-= arrow_bitmap_width
;
507 /* Draw the item text or bitmap */
509 if (lpitem
->item_flags
& MF_BITMAP
)
511 GRAPH_DrawBitmap( hdc
, (HBITMAP
)lpitem
->hText
, rect
.left
, rect
.top
,
512 0, 0, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
);
515 /* No bitmap - process text if present */
516 else if ((lpitem
->item_text
) != ((char *) NULL
))
522 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
523 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
524 i
= strlen( lpitem
->item_text
);
528 for (i
= 0; lpitem
->item_text
[i
]; i
++)
529 if ((lpitem
->item_text
[i
] == '\t') ||
530 (lpitem
->item_text
[i
] == '\b')) break;
533 DrawText( hdc
, lpitem
->item_text
, i
, &rect
,
534 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
536 if (lpitem
->item_text
[i
]) /* There's a tab or flush-right char */
538 if (lpitem
->item_text
[i
] == '\t')
540 rect
.left
= lpitem
->xTab
;
541 DrawText( hdc
, lpitem
->item_text
+ i
+ 1, -1, &rect
,
542 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
544 else DrawText( hdc
, lpitem
->item_text
+ i
+ 1, -1, &rect
,
545 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
551 /***********************************************************************
554 * Paint a popup menu.
556 static void MENU_DrawPopupMenu( HWND hwnd
, HDC hdc
, HMENU hmenu
)
563 GetClientRect( hwnd
, &rect
);
564 FillRect( hdc
, &rect
, sysColorObjects
.hbrushMenu
);
565 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
566 if (!menu
|| !menu
->nItems
) return;
567 item
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
568 for (i
= menu
->nItems
; i
> 0; i
--, item
++)
569 MENU_DrawMenuItem( hdc
, item
, menu
->Height
, FALSE
);
573 /***********************************************************************
576 * Paint a menu bar. Returns the height of the menu bar.
578 WORD
MENU_DrawMenuBar(HDC hDC
, LPRECT lprect
, HWND hwnd
, BOOL suppress_draw
)
583 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
585 lppop
= (LPPOPUPMENU
) USER_HEAP_ADDR( wndPtr
->wIDmenu
);
586 if (lppop
== NULL
|| lprect
== NULL
) return SYSMETRICS_CYMENU
;
587 dprintf_menu(stddeb
,"MENU_DrawMenuBar(%04X, %p, %p); !\n",
589 if (lppop
->Height
== 0) MENU_MenuBarCalcSize(hDC
, lprect
, lppop
, hwnd
);
590 lprect
->bottom
= lprect
->top
+ lppop
->Height
;
591 if (suppress_draw
) return lppop
->Height
;
593 FillRect(hDC
, lprect
, sysColorObjects
.hbrushMenu
);
594 SelectObject( hDC
, sysColorObjects
.hpenWindowFrame
);
595 MoveTo( hDC
, lprect
->left
, lprect
->bottom
);
596 LineTo( hDC
, lprect
->right
, lprect
->bottom
);
598 if (lppop
->nItems
== 0) return SYSMETRICS_CYMENU
;
599 lpitem
= (MENUITEM
*) USER_HEAP_ADDR( lppop
->hItems
);
600 for (i
= 0; i
< lppop
->nItems
; i
++, lpitem
++)
602 MENU_DrawMenuItem( hDC
, lpitem
, lppop
->Height
, TRUE
);
604 return lppop
->Height
;
608 /***********************************************************************
611 * Display a popup menu.
613 static BOOL
MENU_ShowPopup(HWND hwndOwner
, HMENU hmenu
, WORD id
, int x
, int y
)
617 if (!(menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
))) return FALSE
;
618 if (menu
->FocusedItem
!= NO_SELECTED_ITEM
)
620 MENUITEM
*item
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
621 item
[menu
->FocusedItem
].item_flags
&= ~(MF_HILITE
| MF_MOUSESELECT
);
622 menu
->FocusedItem
= NO_SELECTED_ITEM
;
624 SendMessage( hwndOwner
, WM_INITMENUPOPUP
, hmenu
,
625 MAKELONG( id
, (menu
->wFlags
& MF_POPUP
) ? 1 : 0 ));
626 MENU_PopupMenuCalcSize( menu
, hwndOwner
);
629 WND
*wndPtr
= WIN_FindWndPtr( hwndOwner
);
630 if (!wndPtr
) return FALSE
;
631 menu
->hWnd
= CreateWindow( POPUPMENU_CLASS_NAME
, "",
632 WS_POPUP
| WS_BORDER
, x
, y
,
633 menu
->Width
+ 2*SYSMETRICS_CXBORDER
,
634 menu
->Height
+ 2*SYSMETRICS_CYBORDER
,
635 0, 0, wndPtr
->hInstance
,
636 (LPSTR
)(DWORD
)hmenu
);
637 if (!menu
->hWnd
) return FALSE
;
639 else SetWindowPos( menu
->hWnd
, 0, x
, y
,
640 menu
->Width
+ 2*SYSMETRICS_CXBORDER
,
641 menu
->Height
+ 2*SYSMETRICS_CYBORDER
,
642 SWP_NOACTIVATE
| SWP_NOZORDER
);
644 /* Display the window */
646 SetWindowPos( menu
->hWnd
, HWND_TOP
, 0, 0, 0, 0,
647 SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
648 UpdateWindow( menu
->hWnd
);
653 /***********************************************************************
656 static void MENU_SelectItem( HMENU hmenu
, WORD wIndex
)
662 lppop
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
663 if (!lppop
->nItems
) return;
664 items
= (MENUITEM
*) USER_HEAP_ADDR( lppop
->hItems
);
665 if ((wIndex
!= NO_SELECTED_ITEM
) &&
666 (wIndex
!= SYSMENU_SELECTED
) &&
667 (items
[wIndex
].item_flags
& MF_SEPARATOR
))
668 wIndex
= NO_SELECTED_ITEM
;
669 if (lppop
->FocusedItem
== wIndex
) return;
670 if (lppop
->wFlags
& MF_POPUP
) hdc
= GetDC( lppop
->hWnd
);
671 else hdc
= GetDCEx( lppop
->hWnd
, 0, DCX_CACHE
| DCX_WINDOW
);
673 /* Clear previous highlighted item */
674 if (lppop
->FocusedItem
!= NO_SELECTED_ITEM
)
676 if (lppop
->FocusedItem
== SYSMENU_SELECTED
)
677 NC_DrawSysButton( lppop
->hWnd
, hdc
, FALSE
);
680 items
[lppop
->FocusedItem
].item_flags
&=~(MF_HILITE
|MF_MOUSESELECT
);
681 MENU_DrawMenuItem( hdc
, &items
[lppop
->FocusedItem
], lppop
->Height
,
682 !(lppop
->wFlags
& MF_POPUP
) );
686 /* Highlight new item (if any) */
687 lppop
->FocusedItem
= wIndex
;
688 if (lppop
->FocusedItem
!= NO_SELECTED_ITEM
)
690 if (lppop
->FocusedItem
== SYSMENU_SELECTED
)
691 NC_DrawSysButton( lppop
->hWnd
, hdc
, TRUE
);
694 items
[lppop
->FocusedItem
].item_flags
|= MF_HILITE
;
695 MENU_DrawMenuItem( hdc
, &items
[lppop
->FocusedItem
], lppop
->Height
,
696 !(lppop
->wFlags
& MF_POPUP
) );
697 SendMessage(lppop
->hWnd
, WM_MENUSELECT
,
698 items
[lppop
->FocusedItem
].item_id
,
699 MAKELONG( hmenu
, items
[lppop
->FocusedItem
].item_flags
));
702 ReleaseDC( lppop
->hWnd
, hdc
);
706 /***********************************************************************
707 * MENU_SelectNextItem
709 static void MENU_SelectNextItem( HMENU hmenu
)
715 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
716 if (!menu
->nItems
) return;
717 items
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
718 if ((menu
->FocusedItem
!= NO_SELECTED_ITEM
) &&
719 (menu
->FocusedItem
!= SYSMENU_SELECTED
))
721 for (i
= menu
->FocusedItem
+1; i
< menu
->nItems
; i
++)
723 if (!(items
[i
].item_flags
& MF_SEPARATOR
))
725 MENU_SelectItem( hmenu
, i
);
729 if (MENU_HasSysMenu( menu
))
731 MENU_SelectItem( hmenu
, SYSMENU_SELECTED
);
735 for (i
= 0; i
< menu
->nItems
; i
++)
737 if (!(items
[i
].item_flags
& MF_SEPARATOR
))
739 MENU_SelectItem( hmenu
, i
);
743 if (MENU_HasSysMenu( menu
)) MENU_SelectItem( hmenu
, SYSMENU_SELECTED
);
747 /***********************************************************************
748 * MENU_SelectPrevItem
750 static void MENU_SelectPrevItem( HMENU hmenu
)
756 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
757 if (!menu
->nItems
) return;
758 items
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
759 if ((menu
->FocusedItem
!= NO_SELECTED_ITEM
) &&
760 (menu
->FocusedItem
!= SYSMENU_SELECTED
))
762 for (i
= menu
->FocusedItem
- 1; i
>= 0; i
--)
764 if (!(items
[i
].item_flags
& MF_SEPARATOR
))
766 MENU_SelectItem( hmenu
, i
);
770 if (MENU_HasSysMenu( menu
))
772 MENU_SelectItem( hmenu
, SYSMENU_SELECTED
);
776 for (i
= menu
->nItems
- 1; i
> 0; i
--)
778 if (!(items
[i
].item_flags
& MF_SEPARATOR
))
780 MENU_SelectItem( hmenu
, i
);
784 if (MENU_HasSysMenu( menu
)) MENU_SelectItem( hmenu
, SYSMENU_SELECTED
);
788 /***********************************************************************
791 * Return the handle of the selected sub-popup menu (if any).
793 static HMENU
MENU_GetSubPopup( HMENU hmenu
)
798 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
799 if (menu
->FocusedItem
== NO_SELECTED_ITEM
) return 0;
800 else if (menu
->FocusedItem
== SYSMENU_SELECTED
)
801 return GetSystemMenu( menu
->hWnd
, FALSE
);
803 item
= ((MENUITEM
*)USER_HEAP_ADDR( menu
->hItems
)) + menu
->FocusedItem
;
804 if (!(item
->item_flags
& MF_POPUP
) || !(item
->item_flags
& MF_MOUSESELECT
))
806 return item
->item_id
;
810 /***********************************************************************
813 * Hide the sub-popup menus of this menu.
815 static void MENU_HideSubPopups( HMENU hmenu
)
818 POPUPMENU
*menu
, *submenu
;
821 if (!(menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
))) return;
822 if (menu
->FocusedItem
== NO_SELECTED_ITEM
) return;
823 if (menu
->FocusedItem
== SYSMENU_SELECTED
)
825 hsubmenu
= GetSystemMenu( menu
->hWnd
, FALSE
);
829 item
= ((MENUITEM
*)USER_HEAP_ADDR(menu
->hItems
)) + menu
->FocusedItem
;
830 if (!(item
->item_flags
& MF_POPUP
) ||
831 !(item
->item_flags
& MF_MOUSESELECT
)) return;
832 item
->item_flags
&= ~MF_MOUSESELECT
;
833 hsubmenu
= item
->item_id
;
835 submenu
= (POPUPMENU
*) USER_HEAP_ADDR( hsubmenu
);
836 MENU_HideSubPopups( hsubmenu
);
837 if (submenu
->hWnd
) ShowWindow( submenu
->hWnd
, SW_HIDE
);
838 MENU_SelectItem( hsubmenu
, NO_SELECTED_ITEM
);
842 /***********************************************************************
845 * Display the sub-menu of the selected item of this menu.
846 * Return the handle of the submenu, or hmenu if no submenu to display.
848 static HMENU
MENU_ShowSubPopup( HWND hwndOwner
, HMENU hmenu
, BOOL selectFirst
)
854 if (!(menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
))) return hmenu
;
855 if (!(wndPtr
= WIN_FindWndPtr( menu
->hWnd
))) return hmenu
;
856 if (menu
->FocusedItem
== NO_SELECTED_ITEM
) return hmenu
;
857 if (menu
->FocusedItem
== SYSMENU_SELECTED
)
859 MENU_ShowPopup(hwndOwner
, wndPtr
->hSysMenu
, 0, wndPtr
->rectClient
.left
,
860 wndPtr
->rectClient
.top
- menu
->Height
- 2*SYSMETRICS_CYBORDER
);
861 if (selectFirst
) MENU_SelectNextItem( wndPtr
->hSysMenu
);
862 return wndPtr
->hSysMenu
;
864 item
= ((MENUITEM
*)USER_HEAP_ADDR( menu
->hItems
)) + menu
->FocusedItem
;
865 if (!(item
->item_flags
& MF_POPUP
) ||
866 (item
->item_flags
& (MF_GRAYED
| MF_DISABLED
))) return hmenu
;
867 item
->item_flags
|= MF_MOUSESELECT
;
868 if (menu
->wFlags
& MF_POPUP
)
870 MENU_ShowPopup( hwndOwner
, (HMENU
)item
->item_id
, menu
->FocusedItem
,
871 wndPtr
->rectWindow
.left
+ item
->rect
.right
-arrow_bitmap_width
,
872 wndPtr
->rectWindow
.top
+ item
->rect
.top
);
876 MENU_ShowPopup( hwndOwner
, (HMENU
)item
->item_id
, menu
->FocusedItem
,
877 wndPtr
->rectWindow
.left
+ item
->rect
.left
,
878 wndPtr
->rectWindow
.top
+ item
->rect
.bottom
);
880 if (selectFirst
) MENU_SelectNextItem( (HMENU
)item
->item_id
);
881 return (HMENU
)item
->item_id
;
885 /***********************************************************************
886 * MENU_FindMenuByCoords
888 * Find the menu containing a given point (in screen coords).
890 static HMENU
MENU_FindMenuByCoords( HMENU hmenu
, POINT pt
)
895 if (!(hwnd
= WindowFromPoint( pt
))) return 0;
898 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
899 if (menu
->hWnd
== hwnd
)
901 if (!(menu
->wFlags
& MF_POPUP
))
903 /* Make sure it's in the menu bar (or in system menu) */
904 WND
*wndPtr
= WIN_FindWndPtr( menu
->hWnd
);
905 if ((pt
.x
< wndPtr
->rectClient
.left
) ||
906 (pt
.x
>= wndPtr
->rectClient
.right
) ||
907 (pt
.y
>= wndPtr
->rectClient
.top
)) return 0;
908 if (pt
.y
< wndPtr
->rectClient
.top
- menu
->Height
)
910 if (!MENU_IsInSysMenu( menu
, pt
)) return 0;
912 /* else it's in the menu bar */
916 hmenu
= MENU_GetSubPopup( hmenu
);
922 /***********************************************************************
923 * MENU_ExecFocusedItem
925 * Execute a menu item (for instance when user pressed Enter).
926 * Return TRUE if we can go on with menu tracking.
928 static BOOL
MENU_ExecFocusedItem( HWND hwndOwner
, HMENU hmenu
,
929 HMENU
*hmenuCurrent
)
932 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
933 if (!menu
|| !menu
->nItems
|| (menu
->FocusedItem
== NO_SELECTED_ITEM
) ||
934 (menu
->FocusedItem
== SYSMENU_SELECTED
)) return TRUE
;
935 item
= ((MENUITEM
*)USER_HEAP_ADDR( menu
->hItems
)) + menu
->FocusedItem
;
936 if (!(item
->item_flags
& MF_POPUP
))
938 if (!(item
->item_flags
& (MF_GRAYED
| MF_DISABLED
)))
940 PostMessage( hwndOwner
, (menu
->wFlags
& MF_SYSMENU
) ?
941 WM_SYSCOMMAND
: WM_COMMAND
, item
->item_id
, 0 );
948 *hmenuCurrent
= MENU_ShowSubPopup( hwndOwner
, hmenu
, TRUE
);
954 /***********************************************************************
957 * Handle a button-down event in a menu. Point is in screen coords.
958 * hmenuCurrent is the top-most visible popup.
959 * Return TRUE if we can go on with menu tracking.
961 static BOOL
MENU_ButtonDown( HWND hwndOwner
, HMENU hmenu
, HMENU
*hmenuCurrent
,
968 if (!hmenu
) return FALSE
; /* Outside all menus */
969 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
970 item
= MENU_FindItemByCoords( menu
, pt
.x
, pt
.y
, &id
);
971 if (!item
) /* Maybe in system menu */
973 if (!MENU_IsInSysMenu( menu
, pt
)) return FALSE
;
974 id
= SYSMENU_SELECTED
;
977 if (menu
->FocusedItem
== id
)
979 if (id
== SYSMENU_SELECTED
) return FALSE
;
980 if (item
->item_flags
& MF_POPUP
)
982 if (item
->item_flags
& MF_MOUSESELECT
)
984 if (menu
->wFlags
& MF_POPUP
)
986 MENU_HideSubPopups( hmenu
);
987 *hmenuCurrent
= hmenu
;
991 else *hmenuCurrent
= MENU_ShowSubPopup( hwndOwner
, hmenu
, FALSE
);
996 MENU_HideSubPopups( hmenu
);
997 MENU_SelectItem( hmenu
, id
);
998 *hmenuCurrent
= MENU_ShowSubPopup( hwndOwner
, hmenu
, FALSE
);
1004 /***********************************************************************
1007 * Handle a button-up event in a menu. Point is in screen coords.
1008 * hmenuCurrent is the top-most visible popup.
1009 * Return TRUE if we can go on with menu tracking.
1011 static BOOL
MENU_ButtonUp( HWND hwndOwner
, HMENU hmenu
, HMENU
*hmenuCurrent
,
1019 if (!hmenu
) return FALSE
; /* Outside all menus */
1020 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
1021 item
= MENU_FindItemByCoords( menu
, pt
.x
, pt
.y
, &id
);
1022 if (!item
) /* Maybe in system menu */
1024 if (!MENU_IsInSysMenu( menu
, pt
)) return FALSE
;
1025 id
= SYSMENU_SELECTED
;
1026 hsubmenu
= GetSystemMenu( menu
->hWnd
, FALSE
);
1029 if (menu
->FocusedItem
!= id
) return FALSE
;
1031 if (id
!= SYSMENU_SELECTED
)
1033 if (!(item
->item_flags
& MF_POPUP
))
1035 return MENU_ExecFocusedItem( hwndOwner
, hmenu
, hmenuCurrent
);
1037 hsubmenu
= item
->item_id
;
1039 /* Select first item of sub-popup */
1040 MENU_SelectItem( hsubmenu
, NO_SELECTED_ITEM
);
1041 MENU_SelectNextItem( hsubmenu
);
1046 /***********************************************************************
1049 * Handle a motion event in a menu. Point is in screen coords.
1050 * hmenuCurrent is the top-most visible popup.
1051 * Return TRUE if we can go on with menu tracking.
1053 static BOOL
MENU_MouseMove( HWND hwndOwner
, HMENU hmenu
, HMENU
*hmenuCurrent
,
1057 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
1058 WORD id
= NO_SELECTED_ITEM
;
1062 item
= MENU_FindItemByCoords( menu
, pt
.x
, pt
.y
, &id
);
1063 if (!item
) /* Maybe in system menu */
1065 if (!MENU_IsInSysMenu( menu
, pt
))
1066 id
= NO_SELECTED_ITEM
; /* Outside all items */
1067 else id
= SYSMENU_SELECTED
;
1070 if (id
== NO_SELECTED_ITEM
)
1072 MENU_SelectItem( *hmenuCurrent
, NO_SELECTED_ITEM
);
1074 else if (menu
->FocusedItem
!= id
)
1076 MENU_HideSubPopups( hmenu
);
1077 MENU_SelectItem( hmenu
, id
);
1078 *hmenuCurrent
= MENU_ShowSubPopup( hwndOwner
, hmenu
, FALSE
);
1084 /***********************************************************************
1087 * Handle a VK_LEFT key event in a menu.
1088 * hmenuCurrent is the top-most visible popup.
1090 static void MENU_KeyLeft( HWND hwndOwner
, HMENU hmenu
, HMENU
*hmenuCurrent
)
1093 HMENU hmenutmp
, hmenuprev
;
1095 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
1096 hmenuprev
= hmenutmp
= hmenu
;
1097 while (hmenutmp
!= *hmenuCurrent
)
1099 hmenutmp
= MENU_GetSubPopup( hmenuprev
);
1100 if (hmenutmp
!= *hmenuCurrent
) hmenuprev
= hmenutmp
;
1102 MENU_HideSubPopups( hmenuprev
);
1104 if ((hmenuprev
== hmenu
) && !(menu
->wFlags
& MF_POPUP
))
1106 /* Select previous item on the menu bar */
1107 MENU_SelectPrevItem( hmenu
);
1108 if (*hmenuCurrent
!= hmenu
)
1110 /* A popup menu was displayed -> display the next one */
1111 *hmenuCurrent
= MENU_ShowSubPopup( hwndOwner
, hmenu
, TRUE
);
1114 else *hmenuCurrent
= hmenuprev
;
1118 /***********************************************************************
1121 * Handle a VK_RIGHT key event in a menu.
1122 * hmenuCurrent is the top-most visible popup.
1124 static void MENU_KeyRight( HWND hwndOwner
, HMENU hmenu
, HMENU
*hmenuCurrent
)
1129 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
1131 if ((menu
->wFlags
& MF_POPUP
) || (*hmenuCurrent
!= hmenu
))
1133 /* If already displaying a popup, try to display sub-popup */
1134 hmenutmp
= MENU_ShowSubPopup( hwndOwner
, *hmenuCurrent
, TRUE
);
1135 if (hmenutmp
!= *hmenuCurrent
) /* Sub-popup displayed */
1137 *hmenuCurrent
= hmenutmp
;
1142 /* If on menu-bar, go to next item */
1143 if (!(menu
->wFlags
& MF_POPUP
))
1145 MENU_HideSubPopups( hmenu
);
1146 MENU_SelectNextItem( hmenu
);
1147 if (*hmenuCurrent
!= hmenu
)
1149 /* A popup menu was displayed -> display the next one */
1150 *hmenuCurrent
= MENU_ShowSubPopup( hwndOwner
, hmenu
, TRUE
);
1153 else if (*hmenuCurrent
!= hmenu
) /* Hide last level popup */
1156 hmenuprev
= hmenutmp
= hmenu
;
1157 while (hmenutmp
!= *hmenuCurrent
)
1159 hmenutmp
= MENU_GetSubPopup( hmenuprev
);
1160 if (hmenutmp
!= *hmenuCurrent
) hmenuprev
= hmenutmp
;
1162 MENU_HideSubPopups( hmenuprev
);
1163 *hmenuCurrent
= hmenuprev
;
1168 /***********************************************************************
1171 * Menu tracking code.
1172 * If 'x' and 'y' are not 0, we simulate a button-down event at (x,y)
1173 * before beginning tracking. This is to help menu-bar tracking.
1175 static BOOL
MENU_TrackMenu( HMENU hmenu
, WORD wFlags
, int x
, int y
,
1176 HWND hwnd
, LPRECT lprect
)
1180 HMENU hmenuCurrent
= hmenu
;
1181 BOOL fClosed
= FALSE
;
1184 fEndMenuCalled
= FALSE
;
1185 if (!(menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
))) return FALSE
;
1188 POINT pt
= { x
, y
};
1189 MENU_ButtonDown( hwnd
, hmenu
, &hmenuCurrent
, pt
);
1195 if (!MSG_InternalGetMessage( &msg
, 0, hwnd
, MSGF_MENU
, 0, TRUE
))
1198 if ((msg
.message
>= WM_MOUSEFIRST
) && (msg
.message
<= WM_MOUSELAST
))
1200 /* Find the sub-popup for this mouse event (if any) */
1201 HMENU hsubmenu
= MENU_FindMenuByCoords( hmenu
, msg
.pt
);
1205 case WM_RBUTTONDOWN
:
1206 case WM_NCRBUTTONDOWN
:
1207 if (!(wFlags
& TPM_RIGHTBUTTON
)) break;
1209 case WM_LBUTTONDOWN
:
1210 case WM_NCLBUTTONDOWN
:
1211 fClosed
= !MENU_ButtonDown( hwnd
, hsubmenu
,
1212 &hmenuCurrent
, msg
.pt
);
1216 case WM_NCRBUTTONUP
:
1217 if (!(wFlags
& TPM_RIGHTBUTTON
)) break;
1220 case WM_NCLBUTTONUP
:
1221 /* If outside all menus but inside lprect, ignore it */
1222 if (!hsubmenu
&& lprect
&& PtInRect( lprect
, msg
.pt
)) break;
1223 fClosed
= !MENU_ButtonUp( hwnd
, hsubmenu
,
1224 &hmenuCurrent
, msg
.pt
);
1228 case WM_NCMOUSEMOVE
:
1229 if ((msg
.wParam
& MK_LBUTTON
) ||
1230 ((wFlags
& TPM_RIGHTBUTTON
) && (msg
.wParam
& MK_RBUTTON
)))
1232 fClosed
= !MENU_MouseMove( hwnd
, hsubmenu
,
1233 &hmenuCurrent
, msg
.pt
);
1238 else if ((msg
.message
>= WM_KEYFIRST
) && (msg
.message
<= WM_KEYLAST
))
1246 MENU_SelectItem( hmenuCurrent
, NO_SELECTED_ITEM
);
1247 MENU_SelectNextItem( hmenuCurrent
);
1251 MENU_SelectItem( hmenuCurrent
, NO_SELECTED_ITEM
);
1252 MENU_SelectPrevItem( hmenuCurrent
);
1256 MENU_SelectPrevItem( hmenuCurrent
);
1260 /* If on menu bar, pull-down the menu */
1261 if (!(menu
->wFlags
& MF_POPUP
) && (hmenuCurrent
== hmenu
))
1262 hmenuCurrent
= MENU_ShowSubPopup( hwnd
, hmenu
, TRUE
);
1264 MENU_SelectNextItem( hmenuCurrent
);
1268 MENU_KeyLeft( hwnd
, hmenu
, &hmenuCurrent
);
1272 MENU_KeyRight( hwnd
, hmenu
, &hmenuCurrent
);
1277 fClosed
= !MENU_ExecFocusedItem( hwnd
, hmenuCurrent
,
1288 break; /* WM_KEYDOWN */
1298 break; /* WM_SYSKEYDOWN */
1302 /* Hack to avoid control chars. */
1303 /* We will find a better way real soon... */
1304 if ((msg
.wParam
<= 32) || (msg
.wParam
>= 127)) break;
1305 pos
= MENU_FindItemByKey( hwnd
, hmenuCurrent
, msg
.wParam
);
1306 if (pos
== (WORD
)-2) fClosed
= TRUE
;
1307 else if (pos
== (WORD
)-1) MessageBeep(0);
1310 MENU_SelectItem( hmenuCurrent
, pos
);
1311 fClosed
= !MENU_ExecFocusedItem( hwnd
, hmenuCurrent
,
1316 break; /* WM_CHAR */
1317 } /* switch(msg.message) */
1321 DispatchMessage( &msg
);
1323 if (fEndMenuCalled
) fClosed
= TRUE
;
1325 if (!fClosed
) /* Remove the message from the queue */
1326 PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
);
1329 MENU_HideSubPopups( hmenu
);
1330 if (menu
->wFlags
& MF_POPUP
) ShowWindow( menu
->hWnd
, SW_HIDE
);
1331 MENU_SelectItem( hmenu
, NO_SELECTED_ITEM
);
1332 fEndMenuCalled
= FALSE
;
1337 /***********************************************************************
1338 * MENU_TrackMouseMenuBar
1340 * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
1342 void MENU_TrackMouseMenuBar( HWND hwnd
, POINT pt
)
1344 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1345 SendMessage( hwnd
, WM_ENTERMENULOOP
, 0, 0 );
1346 MENU_TrackMenu( (HMENU
)wndPtr
->wIDmenu
, TPM_LEFTALIGN
| TPM_LEFTBUTTON
,
1347 pt
.x
, pt
.y
, hwnd
, NULL
);
1348 SendMessage( hwnd
, WM_EXITMENULOOP
, 0, 0 );
1352 /***********************************************************************
1353 * MENU_TrackKbdMenuBar
1355 * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
1357 void MENU_TrackKbdMenuBar( HWND hwnd
, WORD wParam
)
1359 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1360 if (!wndPtr
->wIDmenu
) return;
1361 SendMessage( hwnd
, WM_ENTERMENULOOP
, 0, 0 );
1362 /* Select first selectable item */
1363 MENU_SelectItem( wndPtr
->wIDmenu
, NO_SELECTED_ITEM
);
1364 MENU_SelectNextItem( (HMENU
)wndPtr
->wIDmenu
);
1365 MENU_TrackMenu( (HMENU
)wndPtr
->wIDmenu
, TPM_LEFTALIGN
| TPM_LEFTBUTTON
,
1367 SendMessage( hwnd
, WM_EXITMENULOOP
, 0, 0 );
1371 /**********************************************************************
1372 * TrackPopupMenu [USER.416]
1374 BOOL
TrackPopupMenu( HMENU hMenu
, WORD wFlags
, short x
, short y
,
1375 short nReserved
, HWND hWnd
, LPRECT lpRect
)
1377 if (!MENU_ShowPopup( hWnd
, hMenu
, 0, x
, y
)) return FALSE
;
1378 return MENU_TrackMenu( hMenu
, wFlags
, 0, 0, hWnd
, lpRect
);
1382 /***********************************************************************
1385 LONG
PopupMenuWndProc( HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
1391 CREATESTRUCT
*createStruct
= (CREATESTRUCT
*)lParam
;
1392 HMENU hmenu
= (HMENU
) ((int)createStruct
->lpCreateParams
& 0xffff);
1393 SetWindowWord( hwnd
, 0, hmenu
);
1397 case WM_MOUSEACTIVATE
: /* We don't want to be activated */
1398 return MA_NOACTIVATE
;
1403 BeginPaint( hwnd
, &ps
);
1404 MENU_DrawPopupMenu( hwnd
, ps
.hdc
,
1405 (HMENU
)GetWindowWord( hwnd
, 0 ) );
1406 EndPaint( hwnd
, &ps
);
1411 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
1417 /***********************************************************************
1418 * MENU_GetMenuBarHeight
1420 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
1422 WORD
MENU_GetMenuBarHeight( HWND hwnd
, WORD menubarWidth
, int orgX
, int orgY
)
1429 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
1430 if (!(lppop
= (LPPOPUPMENU
)USER_HEAP_ADDR( wndPtr
->wIDmenu
))) return 0;
1431 hdc
= GetDC( hwnd
);
1432 SetRect( &rectBar
, orgX
, orgY
, orgX
+menubarWidth
, orgY
+SYSMETRICS_CYMENU
);
1433 MENU_MenuBarCalcSize( hdc
, &rectBar
, lppop
, hwnd
);
1434 ReleaseDC( hwnd
, hdc
);
1435 return lppop
->Height
;
1439 /**********************************************************************
1440 * ChangeMenu [USER.153]
1442 BOOL
ChangeMenu(HMENU hMenu
, WORD nPos
, LPSTR lpNewItem
,
1443 WORD wItemID
, WORD wFlags
)
1445 if (wFlags
& MF_APPEND
)
1446 return AppendMenu(hMenu
, wFlags
, wItemID
, lpNewItem
);
1447 if (wFlags
& MF_DELETE
)
1448 return DeleteMenu(hMenu
, wItemID
, wFlags
);
1449 if (wFlags
& MF_INSERT
)
1450 return InsertMenu(hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1451 if (wFlags
& MF_CHANGE
)
1452 return ModifyMenu(hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1453 if (wFlags
& MF_REMOVE
)
1454 return RemoveMenu(hMenu
, wItemID
, wFlags
);
1459 /**********************************************************************
1460 * CheckMenuItem [USER.154]
1462 BOOL
CheckMenuItem(HMENU hMenu
, WORD wItemID
, WORD wFlags
)
1465 dprintf_menu(stddeb
,"CheckMenuItem (%04X, %04X, %04X) !\n",
1466 hMenu
, wItemID
, wFlags
);
1467 if (!(lpitem
= MENU_FindItem(&hMenu
, &wItemID
, wFlags
))) return FALSE
;
1468 if (wFlags
& MF_CHECKED
) lpitem
->item_flags
|= MF_CHECKED
;
1469 else lpitem
->item_flags
&= ~MF_CHECKED
;
1474 /**********************************************************************
1475 * EnableMenuItem [USER.155]
1477 BOOL
EnableMenuItem(HMENU hMenu
, WORD wItemID
, WORD wFlags
)
1480 dprintf_menu(stddeb
,"EnableMenuItem (%04X, %04X, %04X) !\n",
1481 hMenu
, wItemID
, wFlags
);
1482 if (!(lpitem
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return FALSE
;
1484 /* We can't have MF_GRAYED and MF_DISABLED together */
1485 if (wFlags
& MF_GRAYED
)
1487 lpitem
->item_flags
= (lpitem
->item_flags
& ~MF_DISABLED
) | MF_GRAYED
;
1489 else if (wFlags
& MF_DISABLED
)
1491 lpitem
->item_flags
= (lpitem
->item_flags
& ~MF_GRAYED
) | MF_DISABLED
;
1493 else /* MF_ENABLED */
1495 lpitem
->item_flags
&= ~(MF_GRAYED
| MF_DISABLED
);
1501 /**********************************************************************
1502 * GetMenuString [USER.161]
1504 int GetMenuString(HMENU hMenu
, WORD wItemID
,
1505 LPSTR str
, short nMaxSiz
, WORD wFlags
)
1509 dprintf_menu(stddeb
,"GetMenuString(%04X, %04X, %p, %d, %04X);\n",
1510 hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
1511 if (str
== NULL
) return FALSE
;
1512 lpitem
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
);
1513 if (lpitem
!= NULL
) {
1514 if (lpitem
->item_text
!= NULL
) {
1515 maxsiz
= min(nMaxSiz
- 1, strlen(lpitem
->item_text
));
1516 strncpy(str
, lpitem
->item_text
, maxsiz
+ 1);
1520 dprintf_menu(stddeb
,"GetMenuString // Found !\n");
1527 /**********************************************************************
1528 * HiliteMenuItem [USER.162]
1530 BOOL
HiliteMenuItem(HWND hWnd
, HMENU hMenu
, WORD wItemID
, WORD wHilite
)
1534 dprintf_menu(stddeb
,"HiliteMenuItem(%04X, %04X, %04X, %04X);\n",
1535 hWnd
, hMenu
, wItemID
, wHilite
);
1536 if (!(lpitem
= MENU_FindItem( &hMenu
, &wItemID
, wHilite
))) return FALSE
;
1537 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
))) return FALSE
;
1538 if (menu
->FocusedItem
== wItemID
) return TRUE
;
1539 MENU_HideSubPopups( hMenu
);
1540 MENU_SelectItem( hMenu
, wItemID
);
1545 /**********************************************************************
1546 * GetMenuState [USER.250]
1548 WORD
GetMenuState(HMENU hMenu
, WORD wItemID
, WORD wFlags
)
1551 dprintf_menu(stddeb
,"GetMenuState(%04X, %04X, %04X);\n",
1552 hMenu
, wItemID
, wFlags
);
1553 if (!(lpitem
= MENU_FindItem( &hMenu
, &wItemID
, wFlags
))) return -1;
1554 if (lpitem
->item_flags
& MF_POPUP
)
1556 POPUPMENU
*menu
= (POPUPMENU
*) USER_HEAP_ADDR( lpitem
->item_id
);
1557 if (!menu
) return -1;
1558 else return (menu
->nItems
<< 8) | (menu
->wFlags
& 0xff);
1560 else return lpitem
->item_flags
;
1564 /**********************************************************************
1565 * GetMenuItemCount [USER.263]
1567 WORD
GetMenuItemCount(HMENU hMenu
)
1570 dprintf_menu(stddeb
,"GetMenuItemCount(%04X);\n", hMenu
);
1571 menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
);
1572 if (menu
== NULL
) return (WORD
)-1;
1573 dprintf_menu(stddeb
,"GetMenuItemCount(%04X) return %d \n",
1574 hMenu
, menu
->nItems
);
1575 return menu
->nItems
;
1579 /**********************************************************************
1580 * GetMenuItemID [USER.264]
1582 WORD
GetMenuItemID(HMENU hMenu
, int nPos
)
1587 dprintf_menu(stddeb
,"GetMenuItemID(%04X, %d);\n", hMenu
, nPos
);
1588 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
))) return -1;
1589 if ((nPos
< 0) || (nPos
>= menu
->nItems
)) return -1;
1590 item
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
1591 if (item
[nPos
].item_flags
& MF_POPUP
) return -1;
1592 return item
[nPos
].item_id
;
1596 /**********************************************************************
1597 * InsertMenu [USER.410]
1599 BOOL
InsertMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
, WORD wItemID
, LPSTR lpNewItem
)
1602 MENUITEM
*lpitem
, *newItems
;
1605 if (IS_STRING_ITEM(wFlags
))
1607 dprintf_menu(stddeb
,"InsertMenu (%04X, %04X, %04X, %04X, '%s') !\n",
1608 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1611 dprintf_menu(stddeb
,"InsertMenu (%04X, %04X, %04X, %04X, %p) !\n",
1612 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1614 /* Find where to insert new item */
1616 if ((wFlags
& MF_BYPOSITION
) && (nPos
== (WORD
)-1))
1618 /* Special case: append to menu */
1619 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
))) return FALSE
;
1620 nPos
= menu
->nItems
;
1624 if (!MENU_FindItem( &hMenu
, &nPos
, wFlags
)) return FALSE
;
1625 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
))) return FALSE
;
1628 /* Create new items array */
1630 hNewItems
= USER_HEAP_ALLOC( GMEM_MOVEABLE
,
1631 sizeof(MENUITEM
) * (menu
->nItems
+1) );
1632 if (!hNewItems
) return FALSE
;
1633 newItems
= (MENUITEM
*) USER_HEAP_ADDR( hNewItems
);
1634 if (menu
->nItems
> 0)
1636 /* Copy the old array into the new */
1637 MENUITEM
*oldItems
= (MENUITEM
*) USER_HEAP_ADDR( menu
->hItems
);
1638 if (nPos
> 0) memcpy( newItems
, oldItems
, nPos
* sizeof(MENUITEM
) );
1639 if (nPos
< menu
->nItems
) memcpy( &newItems
[nPos
+1], &oldItems
[nPos
],
1640 (menu
->nItems
-nPos
)*sizeof(MENUITEM
) );
1642 USER_HEAP_FREE( menu
->hItems
);
1644 menu
->hItems
= hNewItems
;
1647 /* Store the new item data */
1649 lpitem
= &newItems
[nPos
];
1650 lpitem
->item_flags
= wFlags
& ~(MF_HILITE
| MF_MOUSESELECT
);
1651 lpitem
->item_id
= wItemID
;
1653 if (IS_STRING_ITEM(wFlags
))
1655 /* Item beginning with a backspace is a help item */
1656 if (lpNewItem
[0] == '\b')
1658 lpitem
->item_flags
|= MF_HELP
;
1661 lpitem
->hText
= USER_HEAP_ALLOC( GMEM_MOVEABLE
, strlen(lpNewItem
)+1 );
1662 lpitem
->item_text
= (char *)USER_HEAP_ADDR( lpitem
->hText
);
1663 strcpy( lpitem
->item_text
, lpNewItem
);
1665 else if (wFlags
& MF_BITMAP
) lpitem
->hText
= LOWORD((DWORD
)lpNewItem
);
1666 else lpitem
->item_text
= lpNewItem
;
1668 if (wFlags
& MF_POPUP
) /* Set the MF_POPUP flag on the popup-menu */
1669 ((POPUPMENU
*)USER_HEAP_ADDR(wItemID
))->wFlags
|= MF_POPUP
;
1671 SetRectEmpty( &lpitem
->rect
);
1672 lpitem
->hCheckBit
= hStdCheck
;
1673 lpitem
->hUnCheckBit
= 0;
1678 /**********************************************************************
1679 * AppendMenu [USER.411]
1681 BOOL
AppendMenu(HMENU hMenu
, WORD wFlags
, WORD wItemID
, LPSTR lpNewItem
)
1683 return InsertMenu( hMenu
, -1, wFlags
| MF_BYPOSITION
, wItemID
, lpNewItem
);
1687 /**********************************************************************
1688 * RemoveMenu [USER.412]
1690 BOOL
RemoveMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
)
1694 dprintf_menu(stddeb
,"RemoveMenu (%04X, %04X, %04X) !\n",
1695 hMenu
, nPos
, wFlags
);
1696 if (!(lpitem
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
1697 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
))) return FALSE
;
1701 if (IS_STRING_ITEM(lpitem
->item_flags
)) USER_HEAP_FREE( lpitem
->hText
);
1702 if (--menu
->nItems
== 0)
1704 USER_HEAP_FREE( menu
->hItems
);
1709 while(nPos
< menu
->nItems
)
1711 *lpitem
= *(lpitem
+1);
1715 menu
->hItems
= USER_HEAP_REALLOC( menu
->hItems
,
1716 menu
->nItems
* sizeof(MENUITEM
),
1723 /**********************************************************************
1724 * DeleteMenu [USER.413]
1726 BOOL
DeleteMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
)
1728 MENUITEM
*item
= MENU_FindItem( &hMenu
, &nPos
, wFlags
);
1729 if (!item
) return FALSE
;
1730 if (item
->item_flags
& MF_POPUP
) DestroyMenu( item
->item_id
);
1731 /* nPos is now the position of the item */
1732 RemoveMenu( hMenu
, nPos
, wFlags
| MF_BYPOSITION
);
1737 /**********************************************************************
1738 * ModifyMenu [USER.414]
1740 BOOL
ModifyMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
, WORD wItemID
, LPSTR lpNewItem
)
1743 if (IS_STRING_ITEM(wFlags
))
1744 dprintf_menu(stddeb
,"ModifyMenu (%04X, %04X, %04X, %04X, '%s') !\n",
1745 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1747 dprintf_menu(stddeb
,"ModifyMenu (%04X, %04X, %04X, %04X, %p) !\n",
1748 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1749 if (!(lpitem
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
1751 if (IS_STRING_ITEM(lpitem
->item_flags
)) USER_HEAP_FREE( lpitem
->hText
);
1752 lpitem
->item_flags
= wFlags
& ~(MF_HILITE
| MF_MOUSESELECT
);
1753 lpitem
->item_id
= wItemID
;
1755 if (IS_STRING_ITEM(wFlags
))
1757 lpitem
->hText
= USER_HEAP_ALLOC( GMEM_MOVEABLE
, strlen(lpNewItem
)+1 );
1758 lpitem
->item_text
= (char *)USER_HEAP_ADDR( lpitem
->hText
);
1759 strcpy( lpitem
->item_text
, lpNewItem
);
1761 else if (wFlags
& MF_BITMAP
) lpitem
->hText
= LOWORD((DWORD
)lpNewItem
);
1762 else lpitem
->item_text
= lpNewItem
;
1763 SetRectEmpty( &lpitem
->rect
);
1768 /**********************************************************************
1769 * CreatePopupMenu [USER.415]
1771 HMENU
CreatePopupMenu()
1776 if (!(hmenu
= CreateMenu())) return 0;
1777 menu
= (POPUPMENU
*) USER_HEAP_ADDR( hmenu
);
1778 menu
->wFlags
|= MF_POPUP
;
1783 /**********************************************************************
1784 * GetMenuCheckMarkDimensions [USER.417]
1786 DWORD
GetMenuCheckMarkDimensions()
1788 return MAKELONG( check_bitmap_width
, check_bitmap_height
);
1792 /**********************************************************************
1793 * SetMenuItemBitmaps [USER.418]
1795 BOOL
SetMenuItemBitmaps(HMENU hMenu
, WORD nPos
, WORD wFlags
,
1796 HBITMAP hNewCheck
, HBITMAP hNewUnCheck
)
1799 dprintf_menu(stddeb
,"SetMenuItemBitmaps (%04X, %04X, %04X, %04X, %08X) !\n",
1800 hMenu
, nPos
, wFlags
, hNewCheck
, hNewUnCheck
);
1801 if (!(lpitem
= MENU_FindItem( &hMenu
, &nPos
, wFlags
))) return FALSE
;
1803 if (!hNewCheck
&& !hNewUnCheck
)
1805 /* If both are NULL, restore default bitmaps */
1806 lpitem
->hCheckBit
= hStdCheck
;
1807 lpitem
->hUnCheckBit
= 0;
1808 lpitem
->item_flags
&= ~MF_USECHECKBITMAPS
;
1810 else /* Install new bitmaps */
1812 lpitem
->hCheckBit
= hNewCheck
;
1813 lpitem
->hUnCheckBit
= hNewUnCheck
;
1814 lpitem
->item_flags
|= MF_USECHECKBITMAPS
;
1820 /**********************************************************************
1821 * CreateMenu [USER.151]
1827 dprintf_menu(stddeb
,"CreateMenu !\n");
1828 if (!(hMenu
= USER_HEAP_ALLOC( GMEM_MOVEABLE
, sizeof(POPUPMENU
) )))
1830 menu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
);
1833 menu
->wMagic
= MENU_MAGIC
;
1840 menu
->FocusedItem
= NO_SELECTED_ITEM
;
1841 dprintf_menu(stddeb
,"CreateMenu // return %04X\n", hMenu
);
1846 /**********************************************************************
1847 * DestroyMenu [USER.152]
1849 BOOL
DestroyMenu(HMENU hMenu
)
1852 dprintf_menu(stddeb
,"DestroyMenu (%04X) !\n", hMenu
);
1853 if (hMenu
== 0) return FALSE
;
1854 lppop
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
);
1855 if (lppop
== NULL
) return FALSE
;
1856 if ((lppop
->wFlags
& MF_POPUP
) && lppop
->hWnd
)
1857 DestroyWindow( lppop
->hWnd
);
1862 MENUITEM
*item
= (MENUITEM
*) USER_HEAP_ADDR( lppop
->hItems
);
1863 for (i
= lppop
->nItems
; i
> 0; i
--, item
++)
1865 if (item
->item_flags
& MF_POPUP
)
1866 DestroyMenu( item
->item_id
);
1868 USER_HEAP_FREE( lppop
->hItems
);
1870 USER_HEAP_FREE( hMenu
);
1871 dprintf_menu(stddeb
,"DestroyMenu (%04X) // End !\n", hMenu
);
1875 /**********************************************************************
1876 * GetSystemMenu [USER.156]
1878 HMENU
GetSystemMenu(HWND hWnd
, BOOL bRevert
)
1881 wndPtr
= WIN_FindWndPtr(hWnd
);
1883 return wndPtr
->hSysMenu
;
1886 DestroyMenu(wndPtr
->hSysMenu
);
1887 wndPtr
->hSysMenu
= CopySysMenu();
1889 return wndPtr
->hSysMenu
;
1892 /**********************************************************************
1893 * SetSystemMenu [USER.280]
1895 BOOL
SetSystemMenu(HWND hWnd
, HMENU newHmenu
)
1899 if ((wndPtr
= WIN_FindWndPtr(hWnd
)) != NULL
) wndPtr
->hSysMenu
= newHmenu
;
1904 /**********************************************************************
1905 * GetMenu [USER.157]
1907 HMENU
GetMenu(HWND hWnd
)
1909 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
1910 if (wndPtr
== NULL
) return 0;
1911 return wndPtr
->wIDmenu
;
1915 /**********************************************************************
1916 * SetMenu [USER.158]
1918 BOOL
SetMenu(HWND hWnd
, HMENU hMenu
)
1921 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
1922 if (wndPtr
== NULL
) {
1923 fprintf(stderr
,"SetMenu(%04X, %04X) // Bad window handle !\n",
1927 dprintf_menu(stddeb
,"SetMenu(%04X, %04X);\n", hWnd
, hMenu
);
1928 if (GetCapture() == hWnd
) ReleaseCapture();
1929 wndPtr
->wIDmenu
= hMenu
;
1932 lpmenu
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
);
1933 if (lpmenu
== NULL
) {
1934 fprintf(stderr
,"SetMenu(%04X, %04X) // Bad menu handle !\n",
1938 lpmenu
->hWnd
= hWnd
;
1939 lpmenu
->wFlags
&= ~MF_POPUP
; /* Can't be a popup */
1940 lpmenu
->Height
= 0; /* Make sure we recalculate the size */
1942 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
1943 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1949 /**********************************************************************
1950 * GetSubMenu [USER.159]
1952 HMENU
GetSubMenu(HMENU hMenu
, short nPos
)
1956 dprintf_menu(stddeb
,"GetSubMenu (%04X, %04X) !\n", hMenu
, nPos
);
1957 if (!(lppop
= (LPPOPUPMENU
) USER_HEAP_ADDR(hMenu
))) return 0;
1958 if ((WORD
)nPos
>= lppop
->nItems
) return 0;
1959 lpitem
= (MENUITEM
*) USER_HEAP_ADDR( lppop
->hItems
);
1960 if (!(lpitem
[nPos
].item_flags
& MF_POPUP
)) return 0;
1961 return lpitem
[nPos
].item_id
;
1965 /**********************************************************************
1966 * DrawMenuBar [USER.160]
1968 void DrawMenuBar(HWND hWnd
)
1972 dprintf_menu(stddeb
,"DrawMenuBar (%04X)\n", hWnd
);
1973 wndPtr
= WIN_FindWndPtr(hWnd
);
1974 if (wndPtr
!= NULL
&& (wndPtr
->dwStyle
& WS_CHILD
) == 0 &&
1975 wndPtr
->wIDmenu
!= 0) {
1976 dprintf_menu(stddeb
,"DrawMenuBar wIDmenu=%04X \n",
1978 lppop
= (LPPOPUPMENU
) USER_HEAP_ADDR(wndPtr
->wIDmenu
);
1979 if (lppop
== NULL
) return;
1981 lppop
->Height
= 0; /* Make sure we call MENU_MenuBarCalcSize */
1982 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
1983 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1988 /***********************************************************************
1989 * EndMenu (USER.187)
1993 /* Note: this won't work when we have multiple tasks... */
1994 fEndMenuCalled
= TRUE
;
1998 /***********************************************************************
1999 * LookupMenuHandle (USER.217)
2001 HMENU
LookupMenuHandle( HMENU hmenu
, INT id
)
2003 if (!MENU_FindItem( &hmenu
, &id
, MF_BYCOMMAND
)) return 0;
2008 /**********************************************************************
2009 * LoadMenuIndirect [USER.220]
2011 HMENU
LoadMenuIndirect(LPSTR menu_template
)
2014 MENU_HEADER
*menu_desc
;
2015 dprintf_menu(stddeb
,"LoadMenuIndirect: menu_template '%p'\n",
2017 hMenu
= CreateMenu();
2018 menu_desc
= (MENU_HEADER
*)menu_template
;
2019 ParseMenuResource((WORD
*)(menu_desc
+ 1), 0, hMenu
);
2024 /**********************************************************************
2025 * CopySysMenu (Internal)
2031 extern unsigned char sysres_MENU_SYSMENU
[];
2033 hMenu
=LoadMenuIndirect(sysres_MENU_SYSMENU
);
2035 dprintf_menu(stddeb
,"No SYSMENU\n");
2038 menu
= (POPUPMENU
*) USER_HEAP_ADDR(hMenu
);
2039 menu
->wFlags
|= MF_SYSMENU
|MF_POPUP
;
2040 dprintf_menu(stddeb
,"CopySysMenu hMenu=%04X !\n", hMenu
);
2045 /**********************************************************************
2046 * ParseMenuResource (from Resource or Template)
2048 WORD
* ParseMenuResource(WORD
*first_item
, int level
, HMENU hMenu
)
2056 next_item
= first_item
;
2061 if (*item
& MF_POPUP
) {
2062 MENU_POPUPITEM
*popup_item
= (MENU_POPUPITEM
*) item
;
2063 next_item
= (WORD
*) (popup_item
->item_text
+
2064 strlen(popup_item
->item_text
) + 1);
2065 hSubMenu
= CreatePopupMenu();
2066 next_item
= ParseMenuResource(next_item
, level
, hSubMenu
);
2067 AppendMenu(hMenu
, popup_item
->item_flags
,
2068 hSubMenu
, popup_item
->item_text
);
2071 MENUITEMTEMPLATE
*normal_item
= (MENUITEMTEMPLATE
*) item
;
2072 next_item
= (WORD
*) (normal_item
->item_text
+
2073 strlen(normal_item
->item_text
) + 1);
2074 if (strlen(normal_item
->item_text
) == 0 && normal_item
->item_id
== 0)
2075 normal_item
->item_flags
|= MF_SEPARATOR
;
2076 AppendMenu(hMenu
, normal_item
->item_flags
,
2077 normal_item
->item_id
, normal_item
->item_text
);
2080 while (!(*item
& MF_END
));
2085 /**********************************************************************
2088 BOOL
IsMenu( HMENU hmenu
)
2091 if (!(menu
= (LPPOPUPMENU
) USER_HEAP_ADDR( hmenu
))) return FALSE
;
2092 return (menu
->wMagic
== MENU_MAGIC
);