4 static char RCSId
[] = "$Id$";
5 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
15 #include "sysmetrics.h"
16 #include "prototypes.h"
22 #define SC_ABOUTWINE SC_SCREENSAVE+1
23 #define SC_SYSMENU SC_SCREENSAVE+2
24 #define SC_ABOUTWINEDLG SC_SCREENSAVE+3
26 /* Dimension of the menu bitmaps */
27 static WORD check_bitmap_width
= 0, check_bitmap_height
= 0;
28 static WORD arrow_bitmap_width
= 0, arrow_bitmap_height
= 0;
30 /* Space between 2 menu bar items */
31 #define MENU_BAR_ITEMS_SPACE 16
33 /* Height of a separator item */
34 #define SEPARATOR_HEIGHT 5
36 extern HINSTANCE hSysRes
;
38 HBITMAP hStdCheck
= 0;
39 HBITMAP hStdMnArrow
= 0;
40 static BOOL MenuHasFocus
= FALSE
;
42 LPPOPUPMENU
PopupMenuGetStorageHeader(HWND hwnd
);
43 LPPOPUPMENU
PopupMenuGetWindowAndStorage(HWND hwnd
, WND
**wndPtr
);
44 void StdDrawMenuBar(HDC hDC
, LPRECT lprect
, LPPOPUPMENU lppop
,
46 BOOL
MenuButtonDown(HWND hWnd
, LPPOPUPMENU lppop
, int x
, int y
);
47 void MenuButtonUp(HWND hWnd
, LPPOPUPMENU lppop
, int x
, int y
);
48 void MenuMouseMove(HWND hWnd
, LPPOPUPMENU lppop
, WORD wParam
, int x
, int y
);
49 void StdDrawPopupMenu(HWND hwnd
);
50 void ResetHiliteFlags(LPPOPUPMENU lppop
);
51 void SelectPrevItem(LPPOPUPMENU lppop
);
52 void SelectNextItem(LPPOPUPMENU lppop
);
53 BOOL
ExecFocusedMenuItem(HWND hWnd
, LPPOPUPMENU lppop
);
54 void MenuItemSelect(HWND hWnd
, LPPOPUPMENU lppop
, WORD wIndex
);
55 LPMENUITEM
MenuFindItem(LPPOPUPMENU lppop
, int x
, int y
, WORD
*lpRet
);
56 LPMENUITEM
MenuFindItemBySelKey(LPPOPUPMENU lppop
, WORD key
, WORD
*lpRet
);
57 BOOL
ActivateMenuBarFocus(HWND hWnd
);
58 BOOL
MenuFocusLoop(HWND hWnd
, LPPOPUPMENU lpmenu
);
59 LPMENUITEM
FindMenuItem(HMENU hMenu
, WORD nPos
, WORD wFlags
);
60 LPMENUITEM
GetMenuItemPtr(LPPOPUPMENU menu
, WORD nPos
);
61 WORD
GetSelectionKey(LPSTR str
);
62 LPSTR
GetShortCutString(LPSTR str
);
63 int GetShortCutPos(LPSTR str
);
64 BOOL
HideAllSubPopupMenu(LPPOPUPMENU menu
);
65 void InitStdBitmaps();
67 WORD
* ParseMenuResource(WORD
*first_item
, int level
, HMENU hMenu
);
68 void SetMenuLogicalParent(HMENU hMenu
, HWND hWnd
);
70 BOOL FAR PASCAL
AboutWine_Proc(HWND hDlg
, WORD msg
, WORD wParam
, LONG lParam
);
73 /***********************************************************************
76 * Calculate the size of the menu item and store it in lpitem->rect.
78 static void MENU_CalcItemSize( HDC hdc
, LPMENUITEM lpitem
,
79 int orgX
, int orgY
, BOOL menuBar
)
82 SetRect( &lpitem
->rect
, orgX
, orgY
, orgX
, orgY
);
84 if (lpitem
->item_flags
& MF_SEPARATOR
)
86 lpitem
->rect
.bottom
+= SEPARATOR_HEIGHT
;
90 if (!menuBar
) lpitem
->rect
.right
+= check_bitmap_width
+arrow_bitmap_width
;
92 if (lpitem
->item_flags
& MF_BITMAP
)
95 HBITMAP hbitmap
= (HBITMAP
)LOWORD((LONG
)lpitem
->item_text
);
96 GetObject(hbitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
97 lpitem
->rect
.right
+= bm
.bmWidth
;
98 lpitem
->rect
.bottom
+= bm
.bmHeight
;
102 /* If we get here, then it is a text item */
104 if (menuBar
) lpitem
->rect
.right
+= MENU_BAR_ITEMS_SPACE
;
105 dwSize
= GetTextExtent( hdc
, lpitem
->item_text
, strlen(lpitem
->item_text
));
106 lpitem
->rect
.right
+= LOWORD(dwSize
);
107 lpitem
->rect
.bottom
+= max( HIWORD(dwSize
), SYSMETRICS_CYMENU
);
111 /***********************************************************************
112 * MENU_PopupMenuCalcSize
114 * Calculate the size of a popup menu.
116 static void MENU_PopupMenuCalcSize( HWND hwnd
)
119 LPMENUITEM lpitem
, lpitemStart
, lptmp
;
122 int orgX
, orgY
, maxX
;
124 if (!(lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
))) return;
125 SetRect( &lppop
->rect
, 0, 0, 0, 0 );
126 lppop
->Width
= lppop
->Height
= 0;
127 if (lppop
->nItems
== 0) return;
130 lpitemStart
= lppop
->firstItem
;
131 while (lpitemStart
!= NULL
)
136 /* Parse items until column break or end of menu */
137 for (lpitem
= lpitemStart
; lpitem
!= NULL
; lpitem
= lpitem
->next
)
139 if ((lpitem
!= lpitemStart
) &&
140 (lpitem
->item_flags
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
141 MENU_CalcItemSize( hdc
, lpitem
, orgX
, orgY
, FALSE
);
142 maxX
= max( maxX
, lpitem
->rect
.right
);
143 orgY
= lpitem
->rect
.bottom
;
146 /* Finish the column (set all items to the largest width found) */
147 for (lptmp
= lpitemStart
; lptmp
!= lpitem
; lptmp
= lptmp
->next
)
149 lptmp
->rect
.right
= maxX
;
152 /* And go to the next column */
153 lppop
->Height
= max( lppop
->Height
, orgY
);
154 lpitemStart
= lpitem
;
158 SetRect( &lppop
->rect
, 0, 0, lppop
->Width
, lppop
->Height
);
159 ReleaseDC( hwnd
, hdc
);
163 /***********************************************************************
164 * MENU_MenuBarCalcSize
166 * Calculate the size of the menu bar.
168 static void MENU_MenuBarCalcSize( HDC hdc
, LPRECT lprect
, LPPOPUPMENU lppop
)
170 LPMENUITEM lpitem
, lpitemStart
, lptmp
;
171 int orgX
, orgY
, maxY
;
173 if ((lprect
== NULL
) || (lppop
== NULL
)) return;
174 if (lppop
->nItems
== 0) return;
175 #ifdef DEBUG_MENUCALC
176 printf("MenuBarCalcSize left=%d top=%d right=%d bottom=%d !\n",
177 lprect
->left
, lprect
->top
, lprect
->right
, lprect
->bottom
);
179 lppop
->Width
= lprect
->right
- lprect
->left
;
183 lpitemStart
= lppop
->firstItem
;
184 while (lpitemStart
!= NULL
)
189 /* Parse items until line break or end of menu */
190 for (lpitem
= lpitemStart
; lpitem
!= NULL
; lpitem
= lpitem
->next
)
192 if ((lpitem
!= lpitemStart
) &&
193 (lpitem
->item_flags
& (MF_MENUBREAK
| MF_MENUBARBREAK
))) break;
194 MENU_CalcItemSize( hdc
, lpitem
, orgX
, orgY
, TRUE
);
195 if (lpitem
->rect
.right
> lprect
->right
)
197 if (lpitem
!= lpitemStart
) break;
198 else lpitem
->rect
.right
= lprect
->right
;
200 maxY
= max( maxY
, lpitem
->rect
.bottom
);
201 orgX
= lpitem
->rect
.right
;
204 /* Finish the line (set all items to the largest height found) */
205 for (lptmp
= lpitemStart
; lptmp
!= lpitem
; lptmp
= lptmp
->next
)
207 lptmp
->rect
.bottom
= maxY
;
210 /* And go to the next line */
211 lpitemStart
= lpitem
;
214 lprect
->bottom
= maxY
;
215 lppop
->Height
= lprect
->bottom
- lprect
->top
;
216 CopyRect( &lppop
->rect
, lprect
);
220 /***********************************************************************
223 * Draw a single menu item.
225 static void MENU_DrawMenuItem( HDC hdc
, LPMENUITEM lpitem
,
226 LPRECT menuRect
, BOOL menuBar
)
230 if (menuBar
&& (lpitem
->item_flags
& MF_SEPARATOR
)) return;
233 /* Draw the background */
235 if (lpitem
->item_flags
& MF_HILITE
)
236 FillRect( hdc
, &rect
, sysColorObjects
.hbrushHighlight
);
237 else FillRect( hdc
, &rect
, sysColorObjects
.hbrushMenu
);
238 SetBkMode( hdc
, TRANSPARENT
);
240 /* Draw the separator bar (if any) */
242 if (!menuBar
&& (lpitem
->item_flags
& MF_MENUBARBREAK
))
244 SelectObject( hdc
, sysColorObjects
.hpenWindowFrame
);
245 MoveTo( hdc
, rect
.left
, menuRect
->top
);
246 LineTo( hdc
, rect
.left
, menuRect
->bottom
);
248 if (lpitem
->item_flags
& MF_SEPARATOR
)
250 SelectObject( hdc
, sysColorObjects
.hpenWindowFrame
);
251 MoveTo( hdc
, rect
.left
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
252 LineTo( hdc
, rect
.right
, rect
.top
+ SEPARATOR_HEIGHT
/2 );
257 /* Draw the check mark */
259 if (lpitem
->item_flags
& MF_CHECKED
)
261 HDC hMemDC
= CreateCompatibleDC( hdc
);
262 if (lpitem
->hCheckBit
== 0) SelectObject(hMemDC
, hStdCheck
);
263 else SelectObject(hMemDC
, lpitem
->hCheckBit
);
264 BitBlt( hdc
, rect
.left
,
265 (rect
.top
+ rect
.bottom
- check_bitmap_height
) / 2,
266 check_bitmap_width
, check_bitmap_height
,
267 hMemDC
, 0, 0, SRCCOPY
);
270 else /* Not checked */
272 if (lpitem
->hUnCheckBit
!= 0)
274 HDC hMemDC
= CreateCompatibleDC( hdc
);
275 SelectObject(hMemDC
, lpitem
->hUnCheckBit
);
276 BitBlt( hdc
, rect
.left
,
277 (rect
.top
+ rect
.bottom
- check_bitmap_height
) / 2,
278 check_bitmap_width
, check_bitmap_height
,
279 hMemDC
, 0, 0, SRCCOPY
);
284 /* Draw the popup-menu arrow */
286 if (lpitem
->item_flags
& MF_POPUP
)
288 HDC hMemDC
= CreateCompatibleDC( hdc
);
289 SelectObject(hMemDC
, hStdMnArrow
);
290 BitBlt( hdc
, rect
.right
-arrow_bitmap_width
,
291 (rect
.top
+ rect
.bottom
- arrow_bitmap_height
) / 2,
292 arrow_bitmap_width
, arrow_bitmap_height
,
293 hMemDC
, 0, 0, SRCCOPY
);
297 rect
.left
+= check_bitmap_width
;
298 rect
.right
-= arrow_bitmap_width
;
303 if (lpitem
->item_flags
& MF_HILITE
)
305 SetTextColor( hdc
, GetSysColor( COLOR_HIGHLIGHTTEXT
) );
306 SetBkColor( hdc
, GetSysColor( COLOR_HIGHLIGHT
) );
310 if (lpitem
->item_flags
& MF_GRAYED
)
311 SetTextColor( hdc
, GetSysColor( COLOR_GRAYTEXT
) );
313 SetTextColor( hdc
, GetSysColor( COLOR_MENUTEXT
) );
314 SetBkColor( hdc
, GetSysColor( COLOR_MENU
) );
317 /* Draw the item text or bitmap */
319 if (lpitem
->item_flags
& MF_BITMAP
)
321 HBITMAP hbitmap
= (HBITMAP
)LOWORD((LONG
)lpitem
->item_text
);
322 HDC hMemDC
= CreateCompatibleDC( hdc
);
323 SelectObject( hMemDC
, hbitmap
);
324 BitBlt( hdc
, rect
.left
, rect
.top
,
325 rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
326 hMemDC
, 0, 0, SRCCOPY
);
332 int x
= GetShortCutPos(lpitem
->item_text
);
335 rect
.left
+= MENU_BAR_ITEMS_SPACE
/ 2;
336 rect
.right
-= MENU_BAR_ITEMS_SPACE
/ 2;
340 DrawText( hdc
, lpitem
->item_text
, x
, &rect
,
341 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
342 DrawText( hdc
, lpitem
->item_text
+ x
, -1, &rect
,
343 DT_RIGHT
| DT_VCENTER
| DT_SINGLELINE
);
345 else DrawText( hdc
, lpitem
->item_text
, -1, &rect
,
346 DT_LEFT
| DT_VCENTER
| DT_SINGLELINE
);
351 /***********************************************************************
354 LONG
PopupMenuWndProc( HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
356 CREATESTRUCT
*createStruct
;
360 LPPOPUPMENU lppop
, lppop2
;
361 LPMENUITEM lpitem
, lpitem2
;
369 printf("PopupMenu WM_CREATE lParam=%08X !\n", lParam
);
371 createStruct
= (CREATESTRUCT
*)lParam
;
372 lppop
= (LPPOPUPMENU
)createStruct
->lpCreateParams
;
373 if (lppop
== NULL
) break;
374 wndPtr
= WIN_FindWndPtr(hwnd
);
375 *((LPPOPUPMENU
*)&wndPtr
->wExtra
[1]) = lppop
;
377 printf("PopupMenu WM_CREATE lppop=%08X !\n", lppop
);
381 printf("PopupMenu End of WM_CREATE !\n");
383 ResetHiliteFlags(lppop
);
386 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
388 printf("PopupMenu WM_DESTROY %lX !\n", lppop
);
393 printf("PopupMenuWndProc // WM_COMMAND received !\n");
395 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
396 if (lppop
== NULL
) break;
397 if (lppop
->SysFlag
) {
398 MenuHasFocus
= FALSE
;
399 if (wParam
== SC_ABOUTWINE
) {
400 printf("SysMenu // Show 'About Wine ...' !\n");
401 /* DialogBox(hSysRes, MAKEINTRESOURCE(SC_ABOUTWINEDLG), */
402 DialogBox(hSysRes
, MAKEINTRESOURCE(2),
403 GetParent(hwnd
), (FARPROC
)AboutWine_Proc
);
407 printf("PopupMenuWndProc // push to Owner WM_SYSCOMMAND !\n");
409 PostMessage(lppop
->ownerWnd
, WM_SYSCOMMAND
, wParam
, lParam
);
414 printf("PopupMenuWndProc // push to Owner WM_COMMAND !\n");
416 MenuHasFocus
= FALSE
;
417 PostMessage(lppop
->hWndParent
, WM_COMMAND
, wParam
, lParam
);
421 printf("PopupMenuWndProc // WM_SHOWWINDOW received !\n");
423 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
424 if (lppop
== NULL
) break;
425 if (wParam
== 0 && lParam
== 0L) {
426 ResetHiliteFlags(lppop
);
427 HideAllSubPopupMenu(lppop
);
429 printf("PopupMenuWndProc hWnd=%04X WM_SHOWWINDOW -> HIDE!\n", hwnd
);
431 if (lppop
->SysFlag
) MenuHasFocus
= FALSE
;
432 SetFocus(lppop
->hWndPrev
);
433 if (GetCapture() != 0) ReleaseCapture();
436 lppop
->FocusedItem
= (WORD
)-1;
439 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
440 if (lppop
== NULL
) break;
442 MenuButtonDown(hwnd
, lppop
, LOWORD(lParam
), HIWORD(lParam
));
445 lppop
= PopupMenuGetStorageHeader(hwnd
);
446 if (lppop
== NULL
) break;
448 MenuButtonUp(hwnd
, lppop
, LOWORD(lParam
), HIWORD(lParam
));
451 lppop
= PopupMenuGetStorageHeader(hwnd
);
452 if (lppop
== NULL
) break;
453 MenuMouseMove(hwnd
, lppop
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
458 printf("PopupMenuWndProc hWnd=%04X WM_KEYUP w=%04X l=%08X !\n",
459 hwnd
, wParam
, lParam
);
464 printf("PopupMenuWndProc hWnd=%04X WM_KEYDOWN w=%04X l=%08X !\n",
465 hwnd
, wParam
, lParam
);
467 if (lParam
< 0L) break;
468 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
469 if (lppop
== NULL
) break;
472 if (lppop
->FocusedItem
== 0) break;
473 MenuItemSelect(hwnd
, lppop
, 0);
476 if (lppop
->BarFlag
) break;
477 SelectPrevItem(lppop
);
480 if (lppop
->BarFlag
) goto ProceedSPACE
;
481 SelectNextItem(lppop
);
484 if (lppop
->SysFlag
!= 0) {
485 ShowWindow(hwnd
, SW_HIDE
);
486 hwnd
= lppop
->hWndParent
;
487 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
488 printf("VK_LEFT // try to put focus on MenuBar %08X !\n", lppop
);
489 if (lppop
== NULL
) break;
490 MenuItemSelect(hwnd
, lppop
, lppop
->nItems
- 1);
493 if (lppop
->BarFlag
) {
494 if (lppop
->FocusedItem
< 1) {
495 MenuItemSelect(hwnd
, lppop
, -1);
496 NC_TrackSysMenu(hwnd
);
499 if (HideAllSubPopupMenu(lppop
)) {
500 MenuItemSelect(hwnd
, lppop
, lppop
->FocusedItem
- 1);
504 if (lppop
->hWndParent
!= 0) {
505 PostMessage(lppop
->hWndParent
, WM_KEYDOWN
, wParam
, lParam
);
508 MenuItemSelect(hwnd
, lppop
, lppop
->FocusedItem
- 1);
511 if (lppop
->SysFlag
!= 0) {
512 ShowWindow(hwnd
, SW_HIDE
);
513 hwnd
= lppop
->hWndParent
;
514 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
515 printf("VK_RIGHT // try to put focus on MenuBar %08X !\n", lppop
);
516 if (lppop
== NULL
) break;
517 MenuItemSelect(hwnd
, lppop
, 0);
520 if (lppop
->BarFlag
) {
521 if (lppop
->FocusedItem
>= lppop
->nItems
- 1) {
522 MenuItemSelect(hwnd
, lppop
, -1);
523 NC_TrackSysMenu(hwnd
);
526 if (HideAllSubPopupMenu(lppop
)) {
527 MenuItemSelect(hwnd
, lppop
, lppop
->FocusedItem
+ 1);
531 if (lppop
->hWndParent
!= 0) {
532 PostMessage(lppop
->hWndParent
, WM_KEYDOWN
, wParam
, lParam
);
535 MenuItemSelect(hwnd
, lppop
, lppop
->FocusedItem
+ 1);
543 printf("PopupMenuWndProc hWnd=%04X WM_CHAR wParam=%04X !\n", hwnd
, wParam
);
545 if (lParam
< 0L) break;
547 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
548 if (lppop
== NULL
) break;
552 ProceedSPACE
: lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
553 ExecFocusedMenuItem(hwnd
, lppop
);
556 if (lppop
->BarFlag
) {
558 printf("VK_ESCAPE // Unselect all MenuBar's Items !\n");
560 if (lppop
->FocusedItem
!= (WORD
)-1)
561 MenuItemSelect(hwnd
, lppop
, -1);
563 if (lppop
->SysFlag
) {
565 printf("VK_ESCAPE // SysMenu !\n");
567 ShowWindow(hwnd
, SW_HIDE
);
570 if (lppop
->hWndParent
!= 0) {
572 printf("VK_ESCAPE // Hide only SubPopup !\n");
574 lppop2
= PopupMenuGetWindowAndStorage(lppop
->hWndParent
, &wndPtr
);
575 if (lppop2
== NULL
) break;
576 HideAllSubPopupMenu(lppop2
);
581 printf("VK_ESCAPE // Hide Root Popup !\n");
583 ShowWindow(hwnd
, SW_HIDE
);
584 MenuHasFocus
= FALSE
;
588 if (wParam
>= 'a' && wParam
<= 'z') wParam
-= 'a' - 'A';
589 lpitem
= MenuFindItemBySelKey(lppop
, wParam
, &wRet
);
590 if (lpitem
!= NULL
) {
591 printf("ShortKey Found wRet=%d !\n", wRet
);
592 MenuItemSelect(hwnd
, lppop
, wRet
);
593 lppop
->FocusedItem
= wRet
;
596 printf("ShortKey Not Found wParam=%04X wRet=%d lpitem=%08X !\n",
597 wParam
, wRet
, lpitem
);
598 if (lppop
->hWndParent
!= (HWND
)NULL
)
599 SendMessage(lppop
->hWndParent
, WM_MENUCHAR
, wParam
,
602 SendMessage(lppop
->ownerWnd
, WM_MENUCHAR
, wParam
,
609 printf("PopupMenuWndProc // WM_PAINT received !\n");
611 StdDrawPopupMenu(hwnd
);
614 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
620 BOOL
ExecFocusedMenuItem(HWND hWnd
, LPPOPUPMENU lppop
)
627 lpitem
= GetMenuItemPtr(lppop
, lppop
->FocusedItem
);
628 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
) {
629 hSubMenu
= (HMENU
)lpitem
->item_id
;
630 lppop2
= (LPPOPUPMENU
) GlobalLock(hSubMenu
);
631 if (lppop2
== NULL
) return FALSE
;
632 lppop2
->hWndParent
= hWnd
;
633 GetClientRect(hWnd
, &rect
);
634 if (lppop
->BarFlag
) {
635 GetWindowRect(hWnd
, &rect
);
636 y
= rect
.top
+ lpitem
->rect
.bottom
;
637 TrackPopupMenu(hSubMenu
, TPM_LEFTBUTTON
,
638 rect
.left
+ lpitem
->rect
.left
,
639 y
, 0, lppop
->ownerWnd
, (LPRECT
)NULL
);
642 x
= lppop
->rect
.right
;
643 GetWindowRect(hWnd
, &rect
);
645 TrackPopupMenu(hSubMenu
, TPM_LEFTBUTTON
,
646 x
, rect
.top
+ lpitem
->rect
.top
,
647 0, lppop
->ownerWnd
, (LPRECT
)NULL
);
649 GlobalUnlock(hSubMenu
);
652 if (((lpitem
->item_flags
& MF_SEPARATOR
) != MF_SEPARATOR
) &&
653 ((lpitem
->item_flags
& MF_POPUP
) != MF_POPUP
)) {
654 MenuHasFocus
= FALSE
;
655 if (lppop
->BarFlag
) {
656 PostMessage(lppop
->ownerWnd
, WM_COMMAND
, lpitem
->item_id
, 0L);
659 ShowWindow(lppop
->hWnd
, SW_HIDE
);
660 SendMessage(lppop
->hWnd
, WM_COMMAND
, lpitem
->item_id
, 0L);
668 BOOL
MenuButtonDown(HWND hWnd
, LPPOPUPMENU lppop
, int x
, int y
)
671 LPMENUITEM lpitem
, lpitem2
;
676 if (lppop
== NULL
) return;
677 lpitem
= MenuFindItem(lppop
, x
, y
, &wRet
);
679 printf("MenuButtonDown hWnd=%04X x=%d y=%d // wRet=%d lpitem=%08X !\n",
680 hWnd
, x
, y
, wRet
, lpitem
);
682 if (lpitem
!= NULL
) {
683 if (lppop
->FocusedItem
!= (WORD
)-1 && wRet
== lppop
->FocusedItem
) {
684 lpitem2
= GetMenuItemPtr(lppop
, lppop
->FocusedItem
);
685 if ((lpitem2
->item_flags
& MF_POPUP
) == MF_POPUP
) {
686 hSubMenu
= (HMENU
)lpitem2
->item_id
;
687 lppop2
= (LPPOPUPMENU
) GlobalLock(hSubMenu
);
688 if (lppop2
== NULL
) return FALSE
;
689 if (IsWindowVisible(lppop2
->hWnd
)) {
690 ShowWindow(lppop2
->hWnd
, SW_HIDE
);
695 MenuItemSelect(hWnd
, lppop
, wRet
);
696 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
) {
697 hSubMenu
= (HMENU
)lpitem
->item_id
;
698 lppop2
= (LPPOPUPMENU
) GlobalLock(hSubMenu
);
699 if (lppop2
== NULL
) return FALSE
;
700 lppop2
->hWndParent
= hWnd
;
701 if (lppop
->BarFlag
) {
702 GetWindowRect(hWnd
, &rect
);
703 y
= rect
.top
+ lpitem
->rect
.bottom
;
706 TrackPopupMenu(hSubMenu
, TPM_LEFTBUTTON
,
707 rect
.left
+ lpitem
->rect
.left
,
708 y
, 0, lppop
->ownerWnd
, (LPRECT
)NULL
);
712 TrackPopupMenu(hSubMenu
, TPM_LEFTBUTTON
,
713 rect
.left
+ lpitem
->rect
.left
,
714 y
, 0, lppop
->ownerWnd
, (LPRECT
)NULL
);
715 MenuHasFocus
= FALSE
;
716 MenuFocusLoop(hWnd
, lppop
);
721 x
= lppop
->rect
.right
;
722 GetWindowRect(hWnd
, &rect
);
724 TrackPopupMenu(hSubMenu
, TPM_LEFTBUTTON
,
725 x
, rect
.top
+ lpitem
->rect
.top
,
726 0, lppop
->ownerWnd
, (LPRECT
)NULL
);
728 GlobalUnlock(hSubMenu
);
731 if (lppop
->BarFlag
&& !MenuHasFocus
) {
732 MenuFocusLoop(hWnd
, lppop
);
736 printf("MenuButtonDown // x=%d y=%d // Not Found !\n", x
, y
);
737 if (GetCapture() != 0) ReleaseCapture();
738 MenuHasFocus
= FALSE
;
739 ShowWindow(lppop
->hWnd
, SW_HIDE
);
745 void MenuButtonUp(HWND hWnd
, LPPOPUPMENU lppop
, int x
, int y
)
748 LPMENUITEM lpitem
, lpitem2
;
753 if (lppop
== NULL
) return;
754 lpitem
= MenuFindItem(lppop
, x
, y
, &wRet
);
756 printf("MenuButtonUp // x=%d y=%d // wRet=%d lpitem=%08X !\n",
759 if (lpitem
!= NULL
) {
760 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
) {
763 if (((lpitem
->item_flags
& MF_SEPARATOR
) != MF_SEPARATOR
) &&
764 ((lpitem
->item_flags
& MF_POPUP
) != MF_POPUP
)) {
765 MenuHasFocus
= FALSE
;
766 if (lppop
->BarFlag
) {
767 PostMessage(lppop
->ownerWnd
, WM_COMMAND
, lpitem
->item_id
, 0L);
770 ShowWindow(lppop
->hWnd
, SW_HIDE
);
771 SendMessage(lppop
->hWnd
, WM_COMMAND
, lpitem
->item_id
, 0L);
776 if (lppop
->FocusedItem
!= (WORD
)-1) {
777 MenuItemSelect(hWnd
, lppop
, lppop
->FocusedItem
);
783 void MenuMouseMove(HWND hWnd
, LPPOPUPMENU lppop
, WORD wParam
, int x
, int y
)
788 LPMENUITEM lpitem
, lpitem2
;
792 if (GetKeyState(VK_LBUTTON
) != 0)
794 lpitem
= MenuFindItem(lppop
, x
, y
, &wRet
);
796 printf("MenuMouseMove // x=%d y=%d // wRet=%d lpitem=%08X !\n",
799 if ((lpitem
!= NULL
) && (lppop
->FocusedItem
!= wRet
))
801 lpitem2
= GetMenuItemPtr(lppop
, lppop
->FocusedItem
);
802 hDC
= GetWindowDC(hWnd
);
803 if ((lpitem2
!= NULL
) &&
804 (lpitem2
->item_flags
& MF_POPUP
) == MF_POPUP
)
806 HideAllSubPopupMenu(lppop
);
808 MenuItemSelect(hWnd
, lppop
, wRet
);
809 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
)
811 hSubMenu
= (HMENU
)lpitem
->item_id
;
812 lppop2
= (LPPOPUPMENU
) GlobalLock(hSubMenu
);
815 ReleaseDC(hWnd
, hDC
);
820 lppop2
->hWndParent
= hWnd
;
821 GetWindowRect(hWnd
, &rect
);
822 rect
.top
+= lpitem
->rect
.bottom
;
823 TrackPopupMenu(hSubMenu
, TPM_LEFTBUTTON
,
824 rect
.left
+ lpitem
->rect
.left
, rect
.top
,
825 0, lppop
->ownerWnd
, (LPRECT
)NULL
);
827 GlobalUnlock(hSubMenu
);
829 ReleaseDC(hWnd
, hDC
);
835 void SelectPrevItem(LPPOPUPMENU lppop
)
839 if (lppop
== NULL
) return;
840 nIndex
= lppop
->FocusedItem
;
845 nIndex
= lppop
->nItems
- 1;
846 lpitem
= GetMenuItemPtr(lppop
, nIndex
);
850 lpitem
= GetMenuItemPtr(lppop
, nIndex
);
852 while (lpitem
!= NULL
&& lpitem
->item_flags
& MF_SEPARATOR
) {
854 lpitem
= GetMenuItemPtr(lppop
, nIndex
);
856 MenuItemSelect(lppop
->hWnd
, lppop
, nIndex
);
860 void SelectNextItem(LPPOPUPMENU lppop
)
864 if (lppop
== NULL
) return;
865 nIndex
= lppop
->FocusedItem
;
866 if ((nIndex
== -1) || (nIndex
>= lppop
->nItems
- 1)) {
868 lpitem
= GetMenuItemPtr(lppop
, nIndex
);
872 lpitem
= GetMenuItemPtr(lppop
, nIndex
);
874 while (lpitem
!= NULL
&& (lpitem
->item_flags
& MF_SEPARATOR
)) {
876 lpitem
= GetMenuItemPtr(lppop
, nIndex
);
878 MenuItemSelect(lppop
->hWnd
, lppop
, nIndex
);
882 void ResetHiliteFlags(LPPOPUPMENU lppop
)
887 printf("ResetHiliteFlags lppop=%08X\n", lppop
);
889 if (lppop
== NULL
) return;
890 lpitem
= lppop
->firstItem
;
891 for(i
= 0; i
< lppop
->nItems
; i
++) {
892 if (lpitem
== NULL
) return;
893 lpitem
->item_flags
&= ~MF_HILITE
;
894 lpitem
= (LPMENUITEM
)lpitem
->next
;
899 void MenuItemSelect(HWND hWnd
, LPPOPUPMENU lppop
, WORD wIndex
)
904 if (lppop
== NULL
) return;
905 if (lppop
->BarFlag
) hdc
= GetDCEx( hWnd
, 0, DCX_CACHE
| DCX_WINDOW
);
906 else hdc
= GetDC( hWnd
);
908 /* Clear previous highlighted item */
909 if (lppop
->FocusedItem
!= (WORD
)-1)
911 if ((lpitem
= GetMenuItemPtr(lppop
, lppop
->FocusedItem
)) != NULL
)
913 lpitem
->item_flags
&= ~MF_HILITE
;
914 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
)
915 HideAllSubPopupMenu(lppop
);
916 MENU_DrawMenuItem( hdc
, lpitem
, &lppop
->rect
, lppop
->BarFlag
);
920 /* Highlight new item (if any) */
921 lppop
->FocusedItem
= wIndex
;
922 if (lppop
->FocusedItem
!= (WORD
)-1)
924 if ((lpitem
= GetMenuItemPtr(lppop
, lppop
->FocusedItem
)) != NULL
)
926 lpitem
->item_flags
|= MF_HILITE
;
927 MENU_DrawMenuItem( hdc
, lpitem
, &lppop
->rect
, lppop
->BarFlag
);
928 SendMessage(hWnd
, WM_MENUSELECT
, lpitem
->item_id
,
929 MAKELONG(0, lpitem
->item_flags
));
932 ReleaseDC( hWnd
, hdc
);
936 LPPOPUPMENU
PopupMenuGetWindowAndStorage(HWND hwnd
, WND
**wndPtr
)
940 *(wndPtr
) = Ptr
= WIN_FindWndPtr(hwnd
);
942 printf("PopupMenuGetWindowAndStorage // Bad Window handle !\n");
945 lppop
= *((LPPOPUPMENU
*)&Ptr
->wExtra
[1]);
947 lppop
= (LPPOPUPMENU
) GlobalLock(Ptr
->wIDmenu
);
949 printf("PopupMenuGetWindowAndStorage // Bad Menu Handle !\n");
957 LPPOPUPMENU
PopupMenuGetStorageHeader(HWND hwnd
)
961 Ptr
= WIN_FindWndPtr(hwnd
);
963 printf("Bad Window handle on PopupMenu !\n");
966 lppop
= *((LPPOPUPMENU
*)&Ptr
->wExtra
[1]);
971 void SetMenuLogicalParent(HMENU hMenu
, HWND hWnd
)
974 lppop
= (LPPOPUPMENU
)GlobalLock(hMenu
);
975 lppop
->hWndParent
= hWnd
;
980 void StdDrawPopupMenu(HWND hwnd
)
989 hDC
= BeginPaint(hwnd
, &ps
);
990 GetClientRect(hwnd
, &rect
);
991 FillRect(hDC
, &rect
, sysColorObjects
.hbrushMenu
);
993 lppop
= PopupMenuGetWindowAndStorage(hwnd
, &wndPtr
);
994 for (lpitem
= lppop
->firstItem
; lpitem
!= NULL
; lpitem
= lpitem
->next
)
996 MENU_DrawMenuItem( hDC
, lpitem
, &rect
, FALSE
);
998 EndPaint( hwnd
, &ps
);
1002 void StdDrawMenuBar(HDC hDC
, LPRECT lprect
, LPPOPUPMENU lppop
,
1006 if (lppop
== NULL
|| lprect
== NULL
) return;
1008 printf("StdDrawMenuBar(%04X, %08X, %08X); !\n", hDC
, lprect
, lppop
);
1010 if (lppop
->Height
== 0) MENU_MenuBarCalcSize(hDC
, lprect
, lppop
);
1011 if (suppress_draw
) return;
1013 FillRect(hDC
, lprect
, sysColorObjects
.hbrushMenu
);
1014 SelectObject( hDC
, sysColorObjects
.hpenWindowFrame
);
1015 MoveTo( hDC
, lprect
->left
, lprect
->bottom
);
1016 LineTo( hDC
, lprect
->right
, lprect
->bottom
);
1018 if (lppop
->nItems
== 0) return;
1019 for (lpitem
= lppop
->firstItem
; lpitem
!= NULL
; lpitem
= lpitem
->next
)
1021 MENU_DrawMenuItem( hDC
, lpitem
, lprect
, TRUE
);
1027 LPMENUITEM
MenuFindItem(LPPOPUPMENU lppop
, int x
, int y
, WORD
*lpRet
)
1031 if (lpRet
!= NULL
) *lpRet
= 0;
1032 if (lppop
== NULL
) return NULL
;
1033 if (lppop
->nItems
== 0) return NULL
;
1034 lpitem
= lppop
->firstItem
;
1035 for(i
= 0; i
< lppop
->nItems
; i
++) {
1036 if (lpitem
== NULL
) return NULL
;
1037 #ifdef DEBUG_MENUFINDITEM
1038 printf("FindItem // left=%d top=%d right=%d bottom=%d\n",
1039 lpitem
->rect
.left
, lpitem
->rect
.top
,
1040 lpitem
->rect
.right
, lpitem
->rect
.bottom
);
1042 if (x
> lpitem
->rect
.left
&& x
< lpitem
->rect
.right
&&
1043 y
> lpitem
->rect
.top
&& y
< lpitem
->rect
.bottom
) {
1044 if (lpRet
!= NULL
) *lpRet
= i
;
1047 lpitem
= (LPMENUITEM
)lpitem
->next
;
1053 LPMENUITEM
MenuFindItemBySelKey(LPPOPUPMENU lppop
, WORD key
, WORD
*lpRet
)
1057 if (lppop
== NULL
) return NULL
;
1059 if (lppop
->nItems
== 0) return NULL
;
1060 lpitem
= lppop
->firstItem
;
1061 for(i
= 0; i
< lppop
->nItems
; i
++) {
1062 if (lpitem
== NULL
) return NULL
;
1063 #ifdef DEBUG_MENUFINDITEM
1064 printf("FindItemBySelKey // key=%04X lpitem->sel_key=%04X\n",
1065 key
, lpitem
->sel_key
);
1067 if (key
== lpitem
->sel_key
) {
1068 if (lpRet
!= NULL
) *lpRet
= i
;
1071 lpitem
= (LPMENUITEM
)lpitem
->next
;
1081 /***********************************************************************
1082 * MENU_GetMenuBarHeight
1084 * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
1086 WORD
MENU_GetMenuBarHeight( HWND hwnd
, WORD menubarWidth
, int orgX
, int orgY
)
1093 if (!(lppop
= PopupMenuGetWindowAndStorage( hwnd
, &wndPtr
))) return 0;
1094 if (!wndPtr
) return 0;
1095 hdc
= GetDC( hwnd
);
1096 SetRect( &rectBar
, orgX
, orgY
, orgX
+menubarWidth
, orgY
+SYSMETRICS_CYMENU
);
1097 MENU_MenuBarCalcSize( hdc
, &rectBar
, lppop
);
1098 ReleaseDC( hwnd
, hdc
);
1099 printf( "MENU_GetMenuBarHeight: returning %d\n", lppop
->Height
);
1100 return lppop
->Height
;
1104 /***********************************************************************
1107 LPMENUITEM
FindMenuItem(HMENU hMenu
, WORD nPos
, WORD wFlags
)
1112 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1114 GlobalUnlock(hMenu
);
1117 lpitem
= menu
->firstItem
;
1118 if (wFlags
& MF_BYPOSITION
) {
1119 for (i
= 0; i
< nPos
; i
++, lpitem
= lpitem
->next
)
1120 if (lpitem
== NULL
) return NULL
;
1123 for (i
= 0; i
< menu
->nItems
&& lpitem
!= NULL
; i
++) {
1124 if (lpitem
->item_id
== nPos
) return lpitem
;
1125 lpitem
= lpitem
->next
;
1133 LPMENUITEM
GetMenuItemPtr(LPPOPUPMENU menu
, WORD nPos
)
1137 if (menu
== NULL
) return NULL
;
1138 lpitem
= menu
->firstItem
;
1139 for (i
= 0; i
< menu
->nItems
; i
++) {
1140 if (lpitem
== NULL
) return NULL
;
1141 if (i
== nPos
) return(lpitem
);
1142 lpitem
= (LPMENUITEM
)lpitem
->next
;
1148 WORD
GetSelectionKey(LPSTR str
)
1152 for (i
= 0; i
< strlen(str
); i
++) {
1153 if (str
[i
] == '&' && str
[i
+ 1] != '&') {
1154 sel_key
= str
[i
+ 1];
1155 if (sel_key
>= 'a' && sel_key
<= 'z') sel_key
-= 'a' - 'A';
1157 printf("GetSelectionKey // %04X\n", sel_key
);
1163 printf("GetSelectionKey NULL \n");
1170 LPSTR
GetShortCutString(LPSTR str
)
1174 for (i
= 0; i
< strlen(str
); i
++) {
1175 if (str
[i
] == '\t' && str
[i
+ 1] != '\t') {
1177 #ifdef DEBUG_MENUSHORTCUT
1178 printf("GetShortCutString // '%s' \n", str2
);
1183 #ifdef DEBUG_MENUSHORTCUT
1184 printf("GetShortCutString NULL \n");
1191 int GetShortCutPos(LPSTR str
)
1194 for (i
= 0; i
< strlen(str
); i
++) {
1195 if (str
[i
] == '\t' && str
[i
+ 1] != '\t') {
1196 #ifdef DEBUG_MENUSHORTCUT
1197 printf("GetShortCutPos = %d \n", i
);
1202 #ifdef DEBUG_MENUSHORTCUT
1203 printf("GetShortCutString NULL \n");
1210 BOOL
HideAllSubPopupMenu(LPPOPUPMENU menu
)
1212 LPPOPUPMENU submenu
;
1214 BOOL someClosed
= FALSE
;
1216 if (menu
== NULL
) return;
1217 lpitem
= menu
->firstItem
;
1218 for (i
= 0; i
< menu
->nItems
; i
++) {
1219 if (lpitem
== NULL
) return;
1220 if (lpitem
->item_flags
& MF_POPUP
) {
1221 submenu
= (LPPOPUPMENU
) GlobalLock((HMENU
)lpitem
->item_id
);
1222 if (submenu
!= NULL
) {
1223 if (IsWindowVisible(submenu
->hWnd
)) {
1224 ShowWindow(submenu
->hWnd
, SW_HIDE
);
1227 GlobalUnlock((HMENU
)lpitem
->item_id
);
1230 lpitem
= (LPMENUITEM
)lpitem
->next
;
1238 /**********************************************************************
1239 * ChangeMenu [USER.153]
1241 BOOL
ChangeMenu(HMENU hMenu
, WORD nPos
, LPSTR lpNewItem
,
1242 WORD wItemID
, WORD wFlags
)
1244 if (wFlags
& MF_APPEND
)
1245 return AppendMenu(hMenu
, wFlags
, wItemID
, lpNewItem
);
1246 if (wFlags
& MF_DELETE
)
1247 return DeleteMenu(hMenu
, wItemID
, wFlags
);
1248 if (wFlags
& MF_INSERT
)
1249 return InsertMenu(hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1250 if (wFlags
& MF_CHANGE
)
1251 return ModifyMenu(hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1252 if (wFlags
& MF_REMOVE
)
1253 return RemoveMenu(hMenu
, wItemID
, wFlags
);
1258 /**********************************************************************
1259 * CheckMenuItem [USER.154]
1261 BOOL
CheckMenuItem(HMENU hMenu
, WORD wItemID
, WORD wFlags
)
1265 printf("CheckMenuItem (%04X, %04X, %04X) !\n", hMenu
, wItemID
, wFlags
);
1267 lpitem
= FindMenuItem(hMenu
, wItemID
, wFlags
);
1268 if (lpitem
!= NULL
) {
1269 if ((wFlags
& MF_CHECKED
) == MF_CHECKED
)
1270 lpitem
->item_flags
|= MF_CHECKED
;
1272 lpitem
->item_flags
&= ((WORD
)-1 ^ MF_CHECKED
);
1274 printf("CheckMenuItem // Found !\n");
1282 /**********************************************************************
1283 * EnableMenuItem [USER.155]
1285 BOOL
EnableMenuItem(HMENU hMenu
, WORD wItemID
, WORD wFlags
)
1289 printf("EnableMenuItem (%04X, %04X, %04X) !\n", hMenu
, wItemID
, wFlags
);
1291 if (!(lpitem
= FindMenuItem(hMenu
, wItemID
, wFlags
))) return FALSE
;
1293 /* We can't have MF_GRAYED and MF_DISABLED together */
1294 if (wFlags
& MF_GRAYED
)
1296 lpitem
->item_flags
= (lpitem
->item_flags
& ~MF_DISABLED
) | MF_GRAYED
;
1298 else if (wFlags
& MF_DISABLED
)
1300 lpitem
->item_flags
= (lpitem
->item_flags
& ~MF_GRAYED
) | MF_DISABLED
;
1302 else /* MF_ENABLED */
1304 lpitem
->item_flags
&= ~(MF_GRAYED
| MF_DISABLED
);
1310 /**********************************************************************
1311 * GetMenuString [USER.161]
1313 int GetMenuString(HMENU hMenu
, WORD wItemID
,
1314 LPSTR str
, short nMaxSiz
, WORD wFlags
)
1319 printf("GetMenuString(%04X, %04X, %08X, %d, %04X);\n",
1320 hMenu
, wItemID
, str
, nMaxSiz
, wFlags
);
1322 if (str
== NULL
) return FALSE
;
1323 lpitem
= FindMenuItem(hMenu
, wItemID
, wFlags
);
1324 if (lpitem
!= NULL
) {
1325 if (lpitem
->item_text
!= NULL
) {
1326 maxsiz
= min(nMaxSiz
- 1, strlen(lpitem
->item_text
));
1327 strncpy(str
, lpitem
->item_text
, maxsiz
+ 1);
1332 printf("GetMenuString // Found !\n");
1340 /**********************************************************************
1341 * HiliteMenuItem [USER.162]
1343 BOOL
HiliteMenuItem(HWND hWnd
, HMENU hMenu
, WORD wItemID
, WORD wHilite
)
1348 printf("HiliteMenuItem(%04X, %04X, %04X, %04X);\n",
1349 hWnd
, hMenu
, wItemID
, wHilite
);
1351 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1352 if (menu
== NULL
) return FALSE
;
1353 lpitem
= FindMenuItem(hMenu
, wItemID
, wHilite
);
1354 if (lpitem
== NULL
) return FALSE
;
1359 /**********************************************************************
1360 * GetMenuState [USER.250]
1362 WORD
GetMenuState(HMENU hMenu
, WORD wItemID
, WORD wFlags
)
1367 printf("GetMenuState(%04X, %04X, %04X);\n", hMenu
, wItemID
, wFlags
);
1369 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1370 if (menu
== NULL
) return -1;
1371 lpitem
= FindMenuItem(hMenu
, wItemID
, wFlags
);
1372 if (lpitem
== NULL
) return -1;
1373 return lpitem
->item_flags
;
1377 /**********************************************************************
1378 * GetMenuItemCount [USER.263]
1380 WORD
GetMenuItemCount(HMENU hMenu
)
1384 printf("GetMenuItemCount(%04X);\n", hMenu
);
1386 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1387 if (menu
== NULL
) return (WORD
)-1;
1389 printf("GetMenuItemCount(%04X) return %d \n", hMenu
, menu
->nItems
);
1391 return menu
->nItems
;
1395 /**********************************************************************
1396 * GetMenuItemID [USER.264]
1398 WORD
GetMenuItemID(HMENU hMenu
, int nPos
)
1403 printf("GetMenuItemID(%04X, %d);\n", hMenu
, nPos
);
1404 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1405 if (menu
== NULL
) return -1;
1406 lpitem
= menu
->firstItem
;
1407 for (i
= 0; i
< menu
->nItems
; i
++) {
1408 if (lpitem
== NULL
) break;
1411 printf("GetMenuItemID // Found !\n");
1413 return lpitem
->item_id
;
1415 lpitem
= (LPMENUITEM
)lpitem
->next
;
1421 /**********************************************************************
1422 * InsertMenu [USER.410]
1424 BOOL
InsertMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
, WORD wItemID
, LPSTR lpNewItem
)
1428 LPMENUITEM lpitem
, lpitem2
;
1430 if ((wFlags
& (MF_BITMAP
| MF_SEPARATOR
| MF_MENUBREAK
| MF_OWNERDRAW
)) == 0)
1431 printf("InsertMenu (%04X, %04X, %04X, '%s') !\n",
1432 hMenu
, wFlags
, wItemID
, lpNewItem
);
1434 printf("InsertMenu (%04X, %04X, %04X, %04X, %08X) !\n",
1435 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1437 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1438 if (menu
== NULL
) return FALSE
;
1439 lpitem
= FindMenuItem(hMenu
, nPos
, wFlags
);
1440 if (lpitem
== NULL
) lpitem
= menu
->firstItem
;
1441 hNewItem
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(MENUITEM
));
1442 if (hNewItem
== 0) {
1443 GlobalUnlock(hMenu
);
1446 lpitem2
= (LPMENUITEM
)GlobalLock(hNewItem
);
1447 if (lpitem2
== NULL
) {
1448 GlobalFree(hNewItem
);
1449 GlobalUnlock(hMenu
);
1452 lpitem2
->hItem
= hNewItem
;
1453 lpitem2
->item_flags
= wFlags
;
1454 lpitem2
->item_id
= wItemID
;
1455 if (!(wFlags
& (MF_BITMAP
| MF_OWNERDRAW
| MF_MENUBARBREAK
|
1456 MF_MENUBREAK
| MF_SEPARATOR
))) {
1457 lpitem2
->hText
= GlobalAlloc(GMEM_MOVEABLE
, strlen(lpNewItem
) + 1);
1458 lpitem2
->item_text
= GlobalLock(lpitem2
->hText
);
1459 if (lpitem2
->item_text
!= NULL
)
1460 strcpy(lpitem2
->item_text
, lpNewItem
);
1462 printf("InsertMenu // Bad Alloc !\n");
1465 lpitem2
->sel_key
= GetSelectionKey(lpitem2
->item_text
);
1468 lpitem2
->item_text
= lpNewItem
;
1470 if (lpitem
== NULL
) {
1471 menu
->firstItem
= lpitem2
;
1472 lpitem2
->prev
= NULL
;
1473 lpitem2
->next
= NULL
;
1476 lpitem2
->prev
= lpitem
;
1477 lpitem2
->next
= lpitem
->next
;
1478 if (lpitem2
->next
!= NULL
) lpitem2
->next
->prev
= lpitem2
;
1479 lpitem
->next
= lpitem2
;
1482 GlobalUnlock(hMenu
);
1487 /**********************************************************************
1488 * AppendMenu [USER.411]
1490 BOOL
AppendMenu(HMENU hMenu
, WORD wFlags
, WORD wItemID
, LPSTR lpNewItem
)
1494 LPMENUITEM lpitem
, lpitem2
;
1496 if ((wFlags
& (MF_BITMAP
| MF_SEPARATOR
| MF_MENUBREAK
| MF_OWNERDRAW
)) == 0)
1497 printf("AppendMenu (%04X, %04X, %04X, '%s') !\n",
1498 hMenu
, wFlags
, wItemID
, lpNewItem
);
1500 printf("AppendMenu (%04X, %04X, %04X, %08X) !\n",
1501 hMenu
, wFlags
, wItemID
, lpNewItem
);
1503 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1504 if (menu
== NULL
) return FALSE
;
1505 lpitem
= menu
->firstItem
;
1506 if (lpitem
!= NULL
) {
1507 while (lpitem
->next
!= NULL
) {
1508 lpitem
= (LPMENUITEM
)lpitem
->next
;
1511 hNewItem
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(MENUITEM
));
1512 if (hNewItem
== 0) {
1513 GlobalUnlock(hMenu
);
1516 lpitem2
= (LPMENUITEM
)GlobalLock(hNewItem
);
1517 lpitem2
->hItem
= hNewItem
;
1518 if (lpitem2
== NULL
) {
1519 GlobalFree(hNewItem
);
1520 GlobalUnlock(hMenu
);
1523 lpitem2
->item_flags
= wFlags
;
1524 lpitem2
->item_id
= wItemID
;
1525 if (!(wFlags
& (MF_BITMAP
| MF_OWNERDRAW
| MF_MENUBARBREAK
|
1526 MF_MENUBREAK
| MF_SEPARATOR
))) {
1527 lpitem2
->hText
= GlobalAlloc(GMEM_MOVEABLE
, strlen(lpNewItem
) + 1);
1528 lpitem2
->item_text
= GlobalLock(lpitem2
->hText
);
1529 if (lpitem2
->item_text
!= NULL
)
1530 strcpy(lpitem2
->item_text
, lpNewItem
);
1532 printf("AppendMenu // Bad Alloc !\n");
1535 lpitem2
->sel_key
= GetSelectionKey(lpitem2
->item_text
);
1538 lpitem2
->item_text
= lpNewItem
;
1541 menu
->firstItem
= lpitem2
;
1543 lpitem
->next
= lpitem2
;
1544 lpitem2
->prev
= lpitem
;
1545 lpitem2
->next
= NULL
;
1546 lpitem2
->hCheckBit
= (HBITMAP
)NULL
;
1547 lpitem2
->hUnCheckBit
= (HBITMAP
)NULL
;
1549 GlobalUnlock(hMenu
);
1554 /**********************************************************************
1555 * RemoveMenu [USER.412]
1557 BOOL
RemoveMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
)
1563 printf("RemoveMenu (%04X, %04X, %04X) !\n", hMenu
, nPos
, wFlags
);
1565 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1566 if (menu
== NULL
) return FALSE
;
1567 lpitem
= menu
->firstItem
;
1568 for (i
= 0; i
< menu
->nItems
; i
++) {
1569 if (lpitem
== NULL
) break;
1571 lpitem
->prev
->next
= lpitem
->next
;
1572 lpitem
->next
->prev
= lpitem
->prev
;
1573 if (!(lpitem
->item_flags
&
1574 (MF_BITMAP
| MF_OWNERDRAW
| MF_MENUBARBREAK
|
1575 MF_MENUBREAK
| MF_SEPARATOR
))) {
1576 GlobalUnlock(lpitem
->hText
);
1577 GlobalFree(lpitem
->hText
);
1579 GlobalFree(lpitem
->hItem
);
1580 GlobalUnlock(hMenu
);
1583 lpitem
= (LPMENUITEM
)lpitem
->next
;
1584 printf("RemoveMenu // during loop items !\n");
1586 printf("RemoveMenu // after loop items !\n");
1587 GlobalUnlock(hMenu
);
1592 /**********************************************************************
1593 * DeleteMenu [USER.413]
1595 BOOL
DeleteMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
)
1601 printf("DeleteMenu (%04X, %04X, %04X) !\n", hMenu
, nPos
, wFlags
);
1603 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1605 GlobalUnlock(hMenu
);
1608 lpitem
= FindMenuItem(hMenu
, nPos
, wFlags
);
1609 if (lpitem
!= NULL
) {
1610 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
)
1611 DestroyMenu((HMENU
)lpitem
->item_id
);
1612 if (!(lpitem
->item_flags
&
1613 (MF_BITMAP
| MF_OWNERDRAW
| MF_MENUBARBREAK
|
1614 MF_MENUBREAK
| MF_SEPARATOR
))) {
1615 GlobalUnlock(lpitem
->hText
);
1616 GlobalFree(lpitem
->hText
);
1618 if (lpitem
->prev
) lpitem
->prev
->next
= lpitem
->next
;
1619 if (lpitem
->next
) lpitem
->next
->prev
= lpitem
->prev
;
1620 GlobalFree(lpitem
->hItem
);
1621 GlobalUnlock(hMenu
);
1624 GlobalUnlock(hMenu
);
1629 /**********************************************************************
1630 * ModifyMenu [USER.414]
1632 BOOL
ModifyMenu(HMENU hMenu
, WORD nPos
, WORD wFlags
, WORD wItemID
, LPSTR lpNewItem
)
1638 if ((wFlags
& (MF_BITMAP
| MF_SEPARATOR
| MF_MENUBREAK
| MF_OWNERDRAW
)) == 0)
1639 printf("ModifyMenu (%04X, %04X, %04X, %04X, '%s') !\n",
1640 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1642 printf("ModifyMenu (%04X, %04X, %04X, %04X, %08X) !\n",
1643 hMenu
, nPos
, wFlags
, wItemID
, lpNewItem
);
1645 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1646 if (menu
== NULL
) return FALSE
;
1647 lpitem
= menu
->firstItem
;
1648 for (i
= 0; i
< menu
->nItems
; i
++) {
1649 if (lpitem
== NULL
) break;
1651 lpitem
->item_flags
= wFlags
;
1652 lpitem
->item_id
= wItemID
;
1653 if (!(lpitem
->item_flags
&
1654 (MF_BITMAP
| MF_OWNERDRAW
| MF_MENUBARBREAK
|
1655 MF_MENUBREAK
| MF_SEPARATOR
))) {
1656 GlobalUnlock(lpitem
->hText
);
1657 GlobalFree(lpitem
->hText
);
1658 lpitem
->hText
= GlobalAlloc(GMEM_MOVEABLE
, strlen(lpNewItem
) + 1);
1659 lpitem
->item_text
= GlobalLock(lpitem
->hText
);
1660 printf("ModifyMenu %08X %08X '%s') !\n",
1661 lpitem
->item_text
, lpNewItem
, lpNewItem
);
1662 if (lpitem
->item_text
!= NULL
)
1663 strcpy(lpitem
->item_text
, lpNewItem
);
1665 printf("ModifyMenu // Bad Alloc !\n");
1668 lpitem
->item_text
= lpNewItem
;
1669 GlobalUnlock(hMenu
);
1672 lpitem
= (LPMENUITEM
)lpitem
->next
;
1674 GlobalUnlock(hMenu
);
1679 /**********************************************************************
1680 * CreatePopupMenu [USER.415]
1682 HMENU
CreatePopupMenu()
1688 printf("CreatePopupMenu !\n");
1690 hMenu
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(POPUPMENU
));
1691 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1697 menu
->firstItem
= NULL
;
1701 menu
->hWndParent
= 0;
1702 menu
->MouseFlags
= 0;
1703 menu
->BarFlag
= FALSE
;
1704 menu
->SysFlag
= FALSE
;
1705 menu
->ChildFlag
= TRUE
;
1708 GlobalUnlock(hMenu
);
1710 printf("CreatePopupMenu // return %04X\n", hMenu
);
1716 /**********************************************************************
1717 * TrackPopupMenu [USER.416]
1719 BOOL
TrackPopupMenu(HMENU hMenu
, WORD wFlags
, short x
, short y
,
1720 short nReserved
, HWND hWnd
, LPRECT lpRect
)
1726 printf("TrackPopupMenu (%04X, %04X, %d, %d, %04X, %04X, %08X) !\n",
1727 hMenu
, wFlags
, x
, y
, nReserved
, hWnd
, lpRect
);
1729 lppop
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1730 if (lppop
== NULL
) {
1731 printf("TrackPopupMenu // Bad menu handle %04X !\n", hMenu
);
1734 wndPtr
= WIN_FindWndPtr(hWnd
);
1735 if (wndPtr
== NULL
) {
1736 printf("TrackPopupMenu // Bad window handle %04X !\n", hWnd
);
1739 lppop
->ownerWnd
= hWnd
;
1740 lppop
->hWndPrev
= GetFocus();
1741 if (lppop
->hWnd
== (HWND
)NULL
) {
1742 lppop
->hWnd
= CreateWindow(POPUPMENU_CLASS_NAME
, "",
1743 WS_POPUP
| WS_BORDER
,
1744 x
, y
, lppop
->Width
, lppop
->Height
, (HWND
)NULL
, 0,
1745 wndPtr
->hInstance
, (LPSTR
)lppop
);
1746 if (lppop
->hWnd
== 0) {
1747 printf("TrackPopupMenu // Can't create PopupMenu window !\n");
1751 if (!lppop
->BarFlag
) {
1752 MENU_PopupMenuCalcSize(lppop
->hWnd
);
1754 printf("TrackPopupMenu // x=%d y=%d Width=%d Height=%d\n",
1755 x
, y
, lppop
->Width
, lppop
->Height
);
1757 SetWindowPos(lppop
->hWnd
, 0, x
, y
, lppop
->Width
+ 2, lppop
->Height
+ 2,
1758 SWP_NOACTIVATE
| SWP_NOZORDER
);
1760 ShowWindow(lppop
->hWnd
, SW_SHOWNOACTIVATE
);
1761 SetFocus(lppop
->hWnd
);
1762 if (!MenuHasFocus
) {
1764 printf("TrackPopupMenu // before MenuFocusLoop !\n");
1766 MenuFocusLoop(hWnd
, NULL
);
1768 printf("TrackPopupMenu // after MenuFocusLoop !\n");
1771 GlobalUnlock(hMenu
);
1776 BOOL
ActivateMenuBarFocus(HWND hWnd
)
1782 if (MenuHasFocus
) return FALSE
;
1783 wndPtr
= WIN_FindWndPtr(hWnd
);
1784 if (wndPtr
== NULL
) return FALSE
;
1786 printf("ActivateMenuBarFocus (%04X) !\n", hWnd
);
1788 while((wndPtr
->dwStyle
& WS_CHILD
) == WS_CHILD
) {
1789 hWnd
= GetParent(hWnd
);
1790 printf("ActivateMenuBarFocus // next Parent=%04X !\n", hWnd
);
1791 wndPtr
= WIN_FindWndPtr(hWnd
);
1792 if (wndPtr
== NULL
) return FALSE
;
1794 if ((wndPtr
->dwStyle
& WS_CHILD
) == 0 && wndPtr
->wIDmenu
!= 0) {
1795 lpmenu
= (LPPOPUPMENU
) GlobalLock(wndPtr
->wIDmenu
);
1796 if (lpmenu
== NULL
) return FALSE
;
1797 lpmenu
->hWndPrev
= GetFocus();
1799 MenuItemSelect(hWnd
, lpmenu
, 0);
1800 bRet
= MenuFocusLoop(hWnd
, lpmenu
);
1801 GlobalUnlock(wndPtr
->wIDmenu
);
1808 BOOL
MenuFocusLoop(HWND hWnd
, LPPOPUPMENU lpmenu
)
1812 printf("Enter in Menu Focus Loop !\n");
1814 MenuHasFocus
= TRUE
;
1816 if (!MenuHasFocus
) break;
1817 if (!GetMessage(&msg
, (HWND
)NULL
, 0, 0)) break;
1818 TranslateMessage(&msg
);
1819 if (hWnd
== msg
.hwnd
&& lpmenu
!= NULL
) {
1820 if ((msg
.message
== WM_SYSKEYDOWN
&& msg
.wParam
== VK_MENU
) ||
1821 (msg
.message
== WM_CHAR
&& msg
.wParam
== VK_ESCAPE
)) {
1822 HideAllSubPopupMenu(lpmenu
);
1825 ScreenToClient(hWnd
, &msg
.pt
);
1826 msg
.pt
.y
+= lpmenu
->rect
.bottom
;
1827 switch(msg
.message
) {
1828 case WM_LBUTTONDOWN
:
1829 case WM_NCLBUTTONDOWN
:
1831 MenuButtonDown(hWnd
, lpmenu
, msg
.pt
.x
, msg
.pt
.y
);
1834 case WM_NCLBUTTONUP
:
1835 MenuButtonUp(hWnd
, lpmenu
, msg
.pt
.x
, msg
.pt
.y
);
1839 case WM_NCMOUSEMOVE
:
1840 MenuMouseMove(hWnd
, lpmenu
, msg
.wParam
, msg
.pt
.x
, msg
.pt
.y
);
1845 PopupMenuWndProc(hWnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
1847 DispatchMessage(&msg
);
1851 DispatchMessage(&msg
);
1854 MenuHasFocus
= FALSE
;
1855 if (lpmenu
!= NULL
) MenuItemSelect(hWnd
, lpmenu
, -1);
1857 printf("End of Menu Focus Loop !\n");
1863 /**********************************************************************
1864 * NC_TrackSysMenu [Internal]
1866 void NC_TrackSysMenu(HWND hWnd
)
1870 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1872 printf("NC_TrackSysMenu hWnd=%04X !\n", hWnd
);
1874 if (!wndPtr
) return;
1875 lpsys
= (LPPOPUPMENU
)GlobalLock(wndPtr
->hSysMenu
);
1877 printf("NC_TrackSysMenu wndPtr->hSysMenu=%04X !\n", wndPtr
->hSysMenu
);
1879 if (lpsys
== NULL
) return;
1881 printf("NC_TrackSysMenu wndPtr->hSysMenu=%04X !\n", wndPtr
->hSysMenu
);
1883 lpsys
->BarFlag
= FALSE
;
1884 lpsys
->SysFlag
= TRUE
;
1885 lpsys
->ChildFlag
= FALSE
;
1886 lpsys
->hWndParent
= hWnd
;
1887 if (!IsWindowVisible(lpsys
->hWnd
)) {
1888 GetWindowRect(hWnd
, &rect
);
1890 printf("NC_TrackSysMenu lpsys->hWnd=%04X !\n", lpsys
->hWnd
);
1893 TrackPopupMenu(wndPtr
->hSysMenu
, TPM_LEFTBUTTON
,
1894 rect
.left
, rect
.top
+ SYSMETRICS_CYSIZE
,
1895 0, hWnd
, (LPRECT
)NULL
);
1898 MenuHasFocus
= TRUE
;
1899 TrackPopupMenu(wndPtr
->hSysMenu
, TPM_LEFTBUTTON
,
1900 rect
.left
, rect
.top
+ SYSMETRICS_CYSIZE
,
1901 0, hWnd
, (LPRECT
)NULL
);
1902 MenuHasFocus
= FALSE
;
1904 printf("NC_TrackSysMenu // before MenuFocusLoop !\n");
1906 MenuFocusLoop(hWnd
, NULL
);
1908 printf("NC_TrackSysMenu // after MenuFocusLoop !\n");
1913 ShowWindow(lpsys
->hWnd
, SW_HIDE
);
1915 GlobalUnlock(wndPtr
->hSysMenu
);
1919 /**********************************************************************
1920 * GetMenuCheckMarkDimensions [USER.417]
1922 DWORD
GetMenuCheckMarkDimensions()
1925 return MAKELONG( check_bitmap_width
, check_bitmap_height
);
1929 /**********************************************************************
1930 * SetMenuItemBitmaps [USER.418]
1932 BOOL
SetMenuItemBitmaps(HMENU hMenu
, WORD nPos
, WORD wFlags
,
1933 HBITMAP hNewCheck
, HBITMAP hNewUnCheck
)
1939 printf("SetMenuItemBitmaps (%04X, %04X, %04X, %04X, %08X) !\n",
1940 hMenu
, nPos
, wFlags
, hNewCheck
, hNewUnCheck
);
1942 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1943 if (menu
== NULL
) return FALSE
;
1944 lpitem
= menu
->firstItem
;
1945 for (i
= 0; i
< menu
->nItems
; i
++) {
1946 if (lpitem
== NULL
) break;
1948 lpitem
->hCheckBit
= hNewCheck
;
1949 lpitem
->hUnCheckBit
= hNewUnCheck
;
1950 GlobalUnlock(hMenu
);
1953 lpitem
= (LPMENUITEM
)lpitem
->next
;
1955 GlobalUnlock(hMenu
);
1960 /**********************************************************************
1961 * CreateMenu [USER.151]
1969 printf("CreateMenu !\n");
1971 hMenu
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(POPUPMENU
));
1972 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
1978 menu
->firstItem
= NULL
;
1982 menu
->hWndParent
= 0;
1983 menu
->MouseFlags
= 0;
1984 menu
->BarFlag
= TRUE
;
1985 menu
->SysFlag
= FALSE
;
1986 menu
->ChildFlag
= TRUE
;
1989 GlobalUnlock(hMenu
);
1991 printf("CreateMenu // return %04X\n", hMenu
);
1997 /**********************************************************************
1998 * DestroyMenu [USER.152]
2000 BOOL
DestroyMenu(HMENU hMenu
)
2003 LPMENUITEM lpitem
, lpitem2
;
2005 printf("DestroyMenu (%04X) !\n", hMenu
);
2007 if (hMenu
== 0) return FALSE
;
2008 lppop
= (LPPOPUPMENU
) GlobalLock(hMenu
);
2009 if (lppop
== NULL
) return FALSE
;
2010 if (lppop
->hWnd
) DestroyWindow (lppop
->hWnd
);
2011 lpitem
= lppop
->firstItem
;
2012 while (lpitem
!= NULL
) {
2014 printf("DestroyMenu (%04X) // during loop items !\n", hMenu
);
2016 if ((lpitem
->item_flags
& MF_POPUP
) == MF_POPUP
) {
2017 DestroyMenu((HMENU
)lpitem
->item_id
);
2019 lpitem
= (LPMENUITEM
)lpitem
->next
;
2021 GlobalUnlock(hMenu
);
2024 printf("DestroyMenu (%04X) // End !\n", hMenu
);
2030 /**********************************************************************
2031 * LoadMenu [USER.150]
2033 HMENU
LoadMenu(HINSTANCE instance
, char *menu_name
)
2037 MENU_HEADER
*menu_desc
;
2039 if ((LONG
)menu_name
& 0xFFFF0000L
)
2040 printf("LoadMenu: instance %02x, menu '%s'\n", instance
, menu_name
);
2042 printf("LoadMenu: instance %02x, menu '%04X'\n", instance
, menu_name
);
2044 if (instance
== (HANDLE
)NULL
) instance
= hSysRes
;
2045 if (menu_name
== NULL
||
2046 (hMenu_desc
= RSC_LoadMenu(instance
, menu_name
)) == 0 ||
2047 (menu_desc
= (MENU_HEADER
*) GlobalLock(hMenu_desc
)) == NULL
) {
2050 hMenu
= LoadMenuIndirect((LPSTR
)menu_desc
);
2055 /**********************************************************************
2056 * GetSystemMenu [USER.156]
2058 HMENU
GetSystemMenu(HWND hWnd
, BOOL bRevert
)
2061 wndPtr
= WIN_FindWndPtr(hWnd
);
2063 return wndPtr
->hSysMenu
;
2066 DestroyMenu(wndPtr
->hSysMenu
);
2067 wndPtr
->hSysMenu
= CopySysMenu();
2069 return wndPtr
->hSysMenu
;
2072 /**********************************************************************
2073 * SetSystemMenu [USER.280]
2075 BOOL
SetSystemMenu(HWND hWnd
, HMENU newHmenu
)
2079 if ((wndPtr
= WIN_FindWndPtr(hWnd
)) != NULL
)
2080 wndPtr
->hSysMenu
= newHmenu
;
2084 /**********************************************************************
2085 * GetMenu [USER.157]
2087 HMENU
GetMenu(HWND hWnd
)
2089 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
2090 if (wndPtr
== NULL
) return 0;
2091 return wndPtr
->wIDmenu
;
2094 /**********************************************************************
2095 * SetMenu [USER.158]
2097 BOOL
SetMenu(HWND hWnd
, HMENU hMenu
)
2102 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
2103 if (wndPtr
== NULL
) {
2104 printf("SetMenu(%04X, %04X) // Bad window handle !\n", hWnd
, hMenu
);
2108 printf("SetMenu(%04X, %04X);\n", hWnd
, hMenu
);
2110 if (GetCapture() == hWnd
) ReleaseCapture();
2111 wndPtr
->wIDmenu
= hMenu
;
2114 lpmenu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
2115 if (lpmenu
== NULL
) {
2116 printf("SetMenu(%04X, %04X) // Bad menu handle !\n", hWnd
, hMenu
);
2119 lpmenu
->ownerWnd
= hWnd
;
2120 lpmenu
->Height
= 0; /* Make sure we recalculate the size */
2121 ResetHiliteFlags(lpmenu
);
2122 GlobalUnlock(hMenu
);
2124 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
2125 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
2131 /**********************************************************************
2132 * GetSubMenu [USER.159]
2134 HMENU
GetSubMenu(HMENU hMenu
, short nPos
)
2141 printf("GetSubMenu (%04X, %04X) !\n", hMenu
, nPos
);
2143 if (hMenu
== 0) return 0;
2144 lppop
= (LPPOPUPMENU
) GlobalLock(hMenu
);
2145 if (lppop
== NULL
) return 0;
2146 lpitem
= lppop
->firstItem
;
2147 for (i
= 0; i
< lppop
->nItems
; i
++) {
2148 if (lpitem
== NULL
) break;
2151 printf(" found %04x\n", lpitem
->item_id
);
2153 if (lpitem
->item_flags
& MF_POPUP
)
2154 return lpitem
->item_id
;
2158 lpitem
= (LPMENUITEM
)lpitem
->next
;
2164 /**********************************************************************
2165 * DrawMenuBar [USER.160]
2167 void DrawMenuBar(HWND hWnd
)
2172 printf("DrawMenuBar (%04X)\n", hWnd
);
2174 wndPtr
= WIN_FindWndPtr(hWnd
);
2175 if (wndPtr
!= NULL
&& (wndPtr
->dwStyle
& WS_CHILD
) == 0 &&
2176 wndPtr
->wIDmenu
!= 0) {
2178 printf("DrawMenuBar wIDmenu=%04X \n", wndPtr
->wIDmenu
);
2180 lppop
= (LPPOPUPMENU
) GlobalLock(wndPtr
->wIDmenu
);
2181 if (lppop
== NULL
) return;
2183 lppop
->Height
= 0; /* Make sure we call MENU_MenuBarCalcSize */
2184 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
2185 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
2186 GlobalUnlock(wndPtr
->wIDmenu
);
2191 /**********************************************************************
2192 * LoadMenuIndirect [USER.220]
2194 HMENU
LoadMenuIndirect(LPSTR menu_template
)
2197 MENU_HEADER
*menu_desc
;
2200 printf("LoadMenuIndirect: menu_template '%08X'\n", menu_template
);
2202 hMenu
= CreateMenu();
2203 menu_desc
= (MENU_HEADER
*)menu_template
;
2204 ParseMenuResource((WORD
*)(menu_desc
+ 1), 0, hMenu
);
2205 lppop
= (LPPOPUPMENU
) GlobalLock(hMenu
);
2206 ResetHiliteFlags(lppop
);
2207 GlobalUnlock(hMenu
);
2212 /**********************************************************************
2213 * InitStdBitmaps (Internal)
2215 void InitStdBitmaps()
2218 if (hStdCheck
== (HBITMAP
)NULL
)
2220 hStdCheck
= LoadBitmap((HANDLE
)NULL
, (LPSTR
)OBM_CHECK
);
2221 GetObject( hStdCheck
, sizeof(BITMAP
), (LPSTR
)&bm
);
2222 check_bitmap_width
= bm
.bmWidth
;
2223 check_bitmap_height
= bm
.bmHeight
;
2225 if (hStdMnArrow
== (HBITMAP
)NULL
)
2227 hStdMnArrow
= LoadBitmap((HANDLE
)NULL
, (LPSTR
)OBM_MNARROW
);
2228 GetObject( hStdMnArrow
, sizeof(BITMAP
), (LPSTR
)&bm
);
2229 arrow_bitmap_width
= bm
.bmWidth
;
2230 arrow_bitmap_height
= bm
.bmHeight
;
2235 /**********************************************************************
2236 * CopySysMenu (Internal)
2242 LPPOPUPMENU sysmenu
;
2244 printf("CopySysMenu entry !\n");
2246 if (hSysMenu
== 0) {
2247 /* hSysMenu = LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(1)); */
2248 /* hSysMenu = LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(SC_SYSMENU));*/
2249 hSysMenu
= LoadMenu((HINSTANCE
)NULL
, "SYSMENU");
2250 if (hSysMenu
== 0) {
2251 printf("SysMenu not found in system resources !\n");
2256 printf("SysMenu loaded from system resources %04X !\n", hSysMenu
);
2259 hMenu
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(POPUPMENU
));
2260 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
2261 sysmenu
= (LPPOPUPMENU
) GlobalLock(hSysMenu
);
2262 if (menu
!= NULL
&& sysmenu
!= NULL
) {
2263 sysmenu
->BarFlag
= FALSE
;
2264 sysmenu
->SysFlag
= TRUE
;
2265 memcpy(menu
, sysmenu
, sizeof(POPUPMENU
));
2268 printf("CopySysMenu // Bad SysMenu pointers !\n");
2270 GlobalUnlock(hMenu
);
2275 GlobalUnlock(hMenu
);
2276 GlobalUnlock(hSysMenu
);
2278 printf("CopySysMenu hMenu=%04X !\n", hMenu
);
2284 /**********************************************************************
2285 * ParseMenuResource (from Resource or Template)
2287 WORD
* ParseMenuResource(WORD
*first_item
, int level
, HMENU hMenu
)
2295 next_item
= first_item
;
2300 if (*item
& MF_POPUP
) {
2301 MENU_POPUPITEM
*popup_item
= (MENU_POPUPITEM
*) item
;
2302 next_item
= (WORD
*) (popup_item
->item_text
+
2303 strlen(popup_item
->item_text
) + 1);
2304 hSubMenu
= CreatePopupMenu();
2305 next_item
= ParseMenuResource(next_item
, level
, hSubMenu
);
2306 AppendMenu(hMenu
, popup_item
->item_flags
,
2307 hSubMenu
, popup_item
->item_text
);
2310 MENUITEMTEMPLATE
*normal_item
= (MENUITEMTEMPLATE
*) item
;
2311 next_item
= (WORD
*) (normal_item
->item_text
+
2312 strlen(normal_item
->item_text
) + 1);
2313 if (strlen(normal_item
->item_text
) == 0 && normal_item
->item_id
== 0)
2314 normal_item
->item_flags
|= MF_SEPARATOR
;
2315 AppendMenu(hMenu
, normal_item
->item_flags
,
2316 normal_item
->item_id
, normal_item
->item_text
);
2319 while (!(*item
& MF_END
));
2323 /**********************************************************************
2326 BOOL
IsMenu(HMENU hMenu
)
2330 menu
= (LPPOPUPMENU
) GlobalLock(hMenu
);
2334 GlobalUnlock(hMenu
);