Newer
Older
if (id == SYSMENU_SELECTED) return FALSE;
if (item->item_flags & MF_POPUP)
{
if (item->item_flags & MF_MOUSESELECT)
{
if (menu->wFlags & MF_POPUP)
{
MENU_HideSubPopups( hmenu );
*hmenuCurrent = hmenu;
else return FALSE;
}
else *hmenuCurrent = MENU_ShowSubPopup( hwndOwner, hmenu, FALSE );
}
}
else
{
MENU_HideSubPopups( hmenu );
MENU_SelectItem( hmenu, id );
*hmenuCurrent = MENU_ShowSubPopup( hwndOwner, hmenu, FALSE );
}
return TRUE;
/***********************************************************************
* MENU_ButtonUp
*
* Handle a button-up event in a menu. Point is in screen coords.
* hmenuCurrent is the top-most visible popup.
* Return TRUE if we can go on with menu tracking.
*/
static BOOL MENU_ButtonUp( HWND hwndOwner, HMENU hmenu, HMENU *hmenuCurrent,
POINT pt )
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
POPUPMENU *menu;
MENUITEM *item;
HMENU hsubmenu;
WORD id;
if (!hmenu) return FALSE; /* Outside all menus */
menu = (POPUPMENU *) USER_HEAP_ADDR( hmenu );
item = MENU_FindItemByCoords( menu, pt.x, pt.y, &id );
if (!item) /* Maybe in system menu */
{
if (!MENU_IsInSysMenu( menu, pt )) return FALSE;
id = SYSMENU_SELECTED;
hsubmenu = GetSystemMenu( menu->hWnd, FALSE );
}
if (menu->FocusedItem != id) return FALSE;
if (id != SYSMENU_SELECTED)
{
if (!(item->item_flags & MF_POPUP))
{
return MENU_ExecFocusedItem( hwndOwner, hmenu, hmenuCurrent );
}
hsubmenu = item->item_id;
}
/* Select first item of sub-popup */
MENU_SelectItem( hsubmenu, NO_SELECTED_ITEM );
MENU_SelectNextItem( hsubmenu );
return TRUE;
/***********************************************************************
* MENU_MouseMove
*
* Handle a motion event in a menu. Point is in screen coords.
* hmenuCurrent is the top-most visible popup.
* Return TRUE if we can go on with menu tracking.
*/
static BOOL MENU_MouseMove( HWND hwndOwner, HMENU hmenu, HMENU *hmenuCurrent,
POINT pt )
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
POPUPMENU *menu;
MENUITEM *item;
WORD id = NO_SELECTED_ITEM;
if (hmenu)
{
menu = (POPUPMENU *) USER_HEAP_ADDR( hmenu );
item = MENU_FindItemByCoords( menu, pt.x, pt.y, &id );
if (!item) /* Maybe in system menu */
{
if (!MENU_IsInSysMenu( menu, pt ))
id = NO_SELECTED_ITEM; /* Outside all items */
else id = SYSMENU_SELECTED;
}
}
if (id == NO_SELECTED_ITEM)
{
MENU_SelectItem( *hmenuCurrent, NO_SELECTED_ITEM );
}
else if (menu->FocusedItem != id)
{
MENU_HideSubPopups( hmenu );
MENU_SelectItem( hmenu, id );
*hmenuCurrent = MENU_ShowSubPopup( hwndOwner, hmenu, FALSE );
}
return TRUE;
/***********************************************************************
* MENU_KeyLeft
*
* Handle a VK_LEFT key event in a menu.
* hmenuCurrent is the top-most visible popup.
*/
static void MENU_KeyLeft( HWND hwndOwner, HMENU hmenu, HMENU *hmenuCurrent )
menu = (POPUPMENU *) USER_HEAP_ADDR( hmenu );
hmenuprev = hmenutmp = hmenu;
while (hmenutmp != *hmenuCurrent)
{
hmenutmp = MENU_GetSubPopup( hmenuprev );
if (hmenutmp != *hmenuCurrent) hmenuprev = hmenutmp;
}
MENU_HideSubPopups( hmenuprev );
if ((hmenuprev == hmenu) && !(menu->wFlags & MF_POPUP))
{
/* Select previous item on the menu bar */
MENU_SelectPrevItem( hmenu );
if (*hmenuCurrent != hmenu)
/* A popup menu was displayed -> display the next one */
*hmenuCurrent = MENU_ShowSubPopup( hwndOwner, hmenu, TRUE );
/***********************************************************************
* MENU_KeyRight
*
* Handle a VK_RIGHT key event in a menu.
* hmenuCurrent is the top-most visible popup.
*/
static void MENU_KeyRight( HWND hwndOwner, HMENU hmenu, HMENU *hmenuCurrent )
if ((menu->wFlags & MF_POPUP) || (*hmenuCurrent != hmenu))
{
/* If already displaying a popup, try to display sub-popup */
hmenutmp = MENU_ShowSubPopup( hwndOwner, *hmenuCurrent, TRUE );
if (hmenutmp != *hmenuCurrent) /* Sub-popup displayed */
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
/* If on menu-bar, go to next item */
if (!(menu->wFlags & MF_POPUP))
{
MENU_HideSubPopups( hmenu );
MENU_SelectNextItem( hmenu );
if (*hmenuCurrent != hmenu)
{
/* A popup menu was displayed -> display the next one */
*hmenuCurrent = MENU_ShowSubPopup( hwndOwner, hmenu, TRUE );
}
}
else if (*hmenuCurrent != hmenu) /* Hide last level popup */
{
HMENU hmenuprev;
hmenuprev = hmenutmp = hmenu;
while (hmenutmp != *hmenuCurrent)
{
hmenutmp = MENU_GetSubPopup( hmenuprev );
if (hmenutmp != *hmenuCurrent) hmenuprev = hmenutmp;
}
MENU_HideSubPopups( hmenuprev );
*hmenuCurrent = hmenuprev;
}
}
/***********************************************************************
* MENU_TrackMenu
*
* Menu tracking code.
* If 'x' and 'y' are not 0, we simulate a button-down event at (x,y)
* before beginning tracking. This is to help menu-bar tracking.
*/
static BOOL MENU_TrackMenu( HMENU hmenu, WORD wFlags, int x, int y,
HWND hwnd, LPRECT lprect )
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
MSG msg;
POPUPMENU *menu;
HMENU hmenuCurrent = hmenu;
BOOL fClosed = FALSE;
WORD pos;
fEndMenuCalled = FALSE;
if (!(menu = (POPUPMENU *) USER_HEAP_ADDR( hmenu ))) return FALSE;
if (x && y)
{
POINT pt = { x, y };
MENU_ButtonDown( hwnd, hmenu, &hmenuCurrent, pt );
}
SetCapture( hwnd );
while (!fClosed)
{
if (!MSG_InternalGetMessage( &msg, 0, hwnd, MSGF_MENU, 0, TRUE ))
break;
if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
{
/* Find the sub-popup for this mouse event (if any) */
HMENU hsubmenu = MENU_FindMenuByCoords( hmenu, msg.pt );
switch(msg.message)
{
case WM_RBUTTONDOWN:
case WM_NCRBUTTONDOWN:
if (!(wFlags & TPM_RIGHTBUTTON)) break;
/* fall through */
case WM_LBUTTONDOWN:
case WM_NCLBUTTONDOWN:
fClosed = !MENU_ButtonDown( hwnd, hsubmenu,
&hmenuCurrent, msg.pt );
break;
case WM_RBUTTONUP:
case WM_NCRBUTTONUP:
if (!(wFlags & TPM_RIGHTBUTTON)) break;
/* fall through */
case WM_LBUTTONUP:
case WM_NCLBUTTONUP:
/* If outside all menus but inside lprect, ignore it */
if (!hsubmenu && lprect && PtInRect( lprect, msg.pt )) break;
fClosed = !MENU_ButtonUp( hwnd, hsubmenu,
&hmenuCurrent, msg.pt );
break;
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
if ((msg.wParam & MK_LBUTTON) ||
((wFlags & TPM_RIGHTBUTTON) && (msg.wParam & MK_RBUTTON)))
{
fClosed = !MENU_MouseMove( hwnd, hsubmenu,
&hmenuCurrent, msg.pt );
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
break;
}
}
else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST))
{
switch(msg.message)
{
case WM_KEYDOWN:
switch(msg.wParam)
{
case VK_HOME:
MENU_SelectItem( hmenuCurrent, NO_SELECTED_ITEM );
MENU_SelectNextItem( hmenuCurrent );
break;
case VK_END:
MENU_SelectItem( hmenuCurrent, NO_SELECTED_ITEM );
MENU_SelectPrevItem( hmenuCurrent );
break;
case VK_UP:
MENU_SelectPrevItem( hmenuCurrent );
break;
case VK_DOWN:
/* If on menu bar, pull-down the menu */
if (!(menu->wFlags & MF_POPUP) && (hmenuCurrent == hmenu))
hmenuCurrent = MENU_ShowSubPopup( hwnd, hmenu, TRUE );
else
MENU_SelectNextItem( hmenuCurrent );
break;
case VK_LEFT:
MENU_KeyLeft( hwnd, hmenu, &hmenuCurrent );
break;
case VK_RIGHT:
MENU_KeyRight( hwnd, hmenu, &hmenuCurrent );
break;
case VK_SPACE:
case VK_RETURN:
fClosed = !MENU_ExecFocusedItem( hwnd, hmenuCurrent,
&hmenuCurrent );
break;
case VK_ESCAPE:
fClosed = TRUE;
break;
default:
break;
}
break; /* WM_KEYDOWN */
case WM_SYSKEYDOWN:
switch(msg.wParam)
{
case VK_MENU:
fClosed = TRUE;
break;
}
break; /* WM_SYSKEYDOWN */
case WM_CHAR:
{
/* Hack to avoid control chars. */
/* We will find a better way real soon... */
if ((msg.wParam <= 32) || (msg.wParam >= 127)) break;
pos = MENU_FindItemByKey( hwnd, hmenuCurrent, msg.wParam );
if (pos == (WORD)-2) fClosed = TRUE;
else if (pos == (WORD)-1) MessageBeep(0);
else
{
MENU_SelectItem( hmenuCurrent, pos );
fClosed = !MENU_ExecFocusedItem( hwnd, hmenuCurrent,
&hmenuCurrent );
}
}
break; /* WM_CHAR */
} /* switch(msg.message) */
}
else
{
DispatchMessage( &msg );
}
if (fEndMenuCalled) fClosed = TRUE;
if (!fClosed) /* Remove the message from the queue */
PeekMessage( &msg, 0, 0, 0, PM_REMOVE );
}
ReleaseCapture();
MENU_HideSubPopups( hmenu );
if (menu->wFlags & MF_POPUP) ShowWindow( menu->hWnd, SW_HIDE );
MENU_SelectItem( hmenu, NO_SELECTED_ITEM );
fEndMenuCalled = FALSE;
return TRUE;
/***********************************************************************
* MENU_TrackMouseMenuBar
*
* Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand().
*/
void MENU_TrackMouseMenuBar( HWND hwnd, POINT pt )
MENU_TrackMenu( (HMENU)wndPtr->wIDmenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
pt.x, pt.y, hwnd, NULL );
}
/***********************************************************************
* MENU_TrackKbdMenuBar
*
* Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand().
*/
void MENU_TrackKbdMenuBar( HWND hwnd, WORD wParam )
{
WND *wndPtr = WIN_FindWndPtr( hwnd );
/* Select first selectable item */
MENU_SelectItem( wndPtr->wIDmenu, NO_SELECTED_ITEM );
MENU_SelectNextItem( (HMENU)wndPtr->wIDmenu );
MENU_TrackMenu( (HMENU)wndPtr->wIDmenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
0, 0, hwnd, NULL );
/**********************************************************************
* TrackPopupMenu [USER.416]
*/
BOOL TrackPopupMenu( HMENU hMenu, WORD wFlags, short x, short y,
short nReserved, HWND hWnd, LPRECT lpRect )
{
if (!MENU_ShowPopup( hWnd, hMenu, 0, x, y )) return FALSE;
return MENU_TrackMenu( hMenu, wFlags, 0, 0, hWnd, lpRect );
}
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
/***********************************************************************
* PopupMenuWndProc
*/
LONG PopupMenuWndProc( HWND hwnd, WORD message, WORD wParam, LONG lParam )
{
switch(message)
{
case WM_CREATE:
{
CREATESTRUCT *createStruct = (CREATESTRUCT *)lParam;
HMENU hmenu = (HMENU) ((int)createStruct->lpCreateParams & 0xffff);
SetWindowWord( hwnd, 0, hmenu );
return 0;
}
case WM_MOUSEACTIVATE: /* We don't want to be activated */
return MA_NOACTIVATE;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint( hwnd, &ps );
MENU_DrawPopupMenu( hwnd, ps.hdc,
(HMENU)GetWindowWord( hwnd, 0 ) );
EndPaint( hwnd, &ps );
return 0;
}
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
/***********************************************************************
* MENU_GetMenuBarHeight
*
* Compute the size of the menu bar height. Used by NC_HandleNCCalcSize().
*/
WORD MENU_GetMenuBarHeight( HWND hwnd, WORD menubarWidth, int orgX, int orgY )
{
HDC hdc;
RECT rectBar;
WND *wndPtr;
LPPOPUPMENU lppop;
if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
if (!(lppop = (LPPOPUPMENU)USER_HEAP_ADDR( wndPtr->wIDmenu ))) return 0;
SetRect( &rectBar, orgX, orgY, orgX+menubarWidth, orgY+SYSMETRICS_CYMENU );
MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd );
ReleaseDC( hwnd, hdc );
return lppop->Height;
}
/**********************************************************************
BOOL ChangeMenu(HMENU hMenu, WORD nPos, LPSTR lpNewItem,
WORD wItemID, WORD wFlags)
if (wFlags & MF_APPEND)
return AppendMenu(hMenu, wFlags, wItemID, lpNewItem);
if (wFlags & MF_DELETE)
return DeleteMenu(hMenu, wItemID, wFlags);
if (wFlags & MF_INSERT)
return InsertMenu(hMenu, nPos, wFlags, wItemID, lpNewItem);
if (wFlags & MF_CHANGE)
return ModifyMenu(hMenu, nPos, wFlags, wItemID, lpNewItem);
if (wFlags & MF_REMOVE)
return RemoveMenu(hMenu, wItemID, wFlags);
return FALSE;
/**********************************************************************
* CheckMenuItem [USER.154]
*/
BOOL CheckMenuItem(HMENU hMenu, WORD wItemID, WORD wFlags)
{
dprintf_menu(stddeb,"CheckMenuItem (%04X, %04X, %04X) !\n",
hMenu, wItemID, wFlags);
if (!(lpitem = MENU_FindItem(&hMenu, &wItemID, wFlags))) return FALSE;
if (wFlags & MF_CHECKED) lpitem->item_flags |= MF_CHECKED;
else lpitem->item_flags &= ~MF_CHECKED;
return TRUE;
}
/**********************************************************************
* EnableMenuItem [USER.155]
*/
BOOL EnableMenuItem(HMENU hMenu, WORD wItemID, WORD wFlags)
{
dprintf_menu(stddeb,"EnableMenuItem (%04X, %04X, %04X) !\n",
hMenu, wItemID, wFlags);
if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return FALSE;
/* We can't have MF_GRAYED and MF_DISABLED together */
if (wFlags & MF_GRAYED)
{
lpitem->item_flags = (lpitem->item_flags & ~MF_DISABLED) | MF_GRAYED;
}
else if (wFlags & MF_DISABLED)
{
lpitem->item_flags = (lpitem->item_flags & ~MF_GRAYED) | MF_DISABLED;
}
else /* MF_ENABLED */
{
lpitem->item_flags &= ~(MF_GRAYED | MF_DISABLED);
}
return TRUE;
}
/**********************************************************************
* GetMenuString [USER.161]
*/
int GetMenuString(HMENU hMenu, WORD wItemID,
dprintf_menu(stddeb,"GetMenuString(%04X, %04X, %p, %d, %04X);\n",
hMenu, wItemID, str, nMaxSiz, wFlags);
if (str == NULL) return FALSE;
lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags );
if (lpitem != NULL) {
if (lpitem->item_text != NULL) {
maxsiz = min(nMaxSiz - 1, strlen(lpitem->item_text));
strncpy(str, lpitem->item_text, maxsiz + 1);
}
else
maxsiz = 0;
}
/**********************************************************************
BOOL HiliteMenuItem(HWND hWnd, HMENU hMenu, WORD wItemID, WORD wHilite)
dprintf_menu(stddeb,"HiliteMenuItem(%04X, %04X, %04X, %04X);\n",
hWnd, hMenu, wItemID, wHilite);
if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wHilite ))) return FALSE;
if (!(menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu))) return FALSE;
if (menu->FocusedItem == wItemID) return TRUE;
MENU_HideSubPopups( hMenu );
MENU_SelectItem( hMenu, wItemID );
return TRUE;
}
/**********************************************************************
WORD GetMenuState(HMENU hMenu, WORD wItemID, WORD wFlags)
dprintf_menu(stddeb,"GetMenuState(%04X, %04X, %04X);\n",
hMenu, wItemID, wFlags);
if (!(lpitem = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1;
if (lpitem->item_flags & MF_POPUP)
{
POPUPMENU *menu = (POPUPMENU *) USER_HEAP_ADDR( lpitem->item_id );
if (!menu) return -1;
else return (menu->nItems << 8) | (menu->wFlags & 0xff);
}
else return lpitem->item_flags;
}
/**********************************************************************
dprintf_menu(stddeb,"GetMenuItemCount(%04X);\n", hMenu);
menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu);
if (menu == NULL) return (WORD)-1;
dprintf_menu(stddeb,"GetMenuItemCount(%04X) return %d \n",
hMenu, menu->nItems);
}
/**********************************************************************
dprintf_menu(stddeb,"GetMenuItemID(%04X, %d);\n", hMenu, nPos);
if (!(menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu))) return -1;
if ((nPos < 0) || (nPos >= menu->nItems)) return -1;
item = (MENUITEM *) USER_HEAP_ADDR( menu->hItems );
if (item[nPos].item_flags & MF_POPUP) return -1;
return item[nPos].item_id;
}
/**********************************************************************
BOOL InsertMenu(HMENU hMenu, WORD nPos, WORD wFlags, WORD wItemID, LPSTR lpNewItem)
HANDLE hNewItems;
MENUITEM *lpitem, *newItems;
LPPOPUPMENU menu;
if (IS_STRING_ITEM(wFlags))
{
dprintf_menu(stddeb,"InsertMenu (%04X, %04X, %04X, %04X, '%s') !\n",
hMenu, nPos, wFlags, wItemID, lpNewItem);
}
dprintf_menu(stddeb,"InsertMenu (%04X, %04X, %04X, %04X, %p) !\n",
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
hMenu, nPos, wFlags, wItemID, lpNewItem);
/* Find where to insert new item */
if ((wFlags & MF_BYPOSITION) && (nPos == (WORD)-1))
{
/* Special case: append to menu */
if (!(menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu))) return FALSE;
nPos = menu->nItems;
}
else
{
if (!MENU_FindItem( &hMenu, &nPos, wFlags )) return FALSE;
if (!(menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu))) return FALSE;
}
/* Create new items array */
hNewItems = USER_HEAP_ALLOC( GMEM_MOVEABLE,
sizeof(MENUITEM) * (menu->nItems+1) );
if (!hNewItems) return FALSE;
newItems = (MENUITEM *) USER_HEAP_ADDR( hNewItems );
if (menu->nItems > 0)
{
/* Copy the old array into the new */
MENUITEM *oldItems = (MENUITEM *) USER_HEAP_ADDR( menu->hItems );
if (nPos > 0) memcpy( newItems, oldItems, nPos * sizeof(MENUITEM) );
if (nPos < menu->nItems) memcpy( &newItems[nPos+1], &oldItems[nPos],
(menu->nItems-nPos)*sizeof(MENUITEM) );
USER_HEAP_FREE( menu->hItems );
}
menu->hItems = hNewItems;
menu->nItems++;
/* Store the new item data */
lpitem = &newItems[nPos];
lpitem->item_flags = wFlags & ~(MF_HILITE | MF_MOUSESELECT);
lpitem->item_id = wItemID;
if (IS_STRING_ITEM(wFlags))
{
/* Item beginning with a backspace is a help item */
if (lpNewItem[0] == '\b')
{
lpitem->item_flags |= MF_HELP;
lpNewItem++;
}
lpitem->hText = USER_HEAP_ALLOC( GMEM_MOVEABLE, strlen(lpNewItem)+1 );
lpitem->item_text = (char *)USER_HEAP_ADDR( lpitem->hText );
strcpy( lpitem->item_text, lpNewItem );
}
else if (wFlags & MF_BITMAP) lpitem->hText = LOWORD((DWORD)lpNewItem);
if (wFlags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */
((POPUPMENU *)USER_HEAP_ADDR(wItemID))->wFlags |= MF_POPUP;
SetRectEmpty( &lpitem->rect );
lpitem->hCheckBit = hStdCheck;
lpitem->hUnCheckBit = 0;
return TRUE;
/**********************************************************************
* AppendMenu [USER.411]
*/
BOOL AppendMenu(HMENU hMenu, WORD wFlags, WORD wItemID, LPSTR lpNewItem)
return InsertMenu( hMenu, -1, wFlags | MF_BYPOSITION, wItemID, lpNewItem );
/**********************************************************************
* RemoveMenu [USER.412]
*/
BOOL RemoveMenu(HMENU hMenu, WORD nPos, WORD wFlags)
dprintf_menu(stddeb,"RemoveMenu (%04X, %04X, %04X) !\n",
hMenu, nPos, wFlags);
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
if (!(lpitem = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
if (!(menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu))) return FALSE;
/* Remove item */
if (IS_STRING_ITEM(lpitem->item_flags)) USER_HEAP_FREE( lpitem->hText );
if (--menu->nItems == 0)
{
USER_HEAP_FREE( menu->hItems );
menu->hItems = 0;
}
else
{
while(nPos < menu->nItems)
{
*lpitem = *(lpitem+1);
lpitem++;
nPos++;
}
menu->hItems = USER_HEAP_REALLOC( menu->hItems,
menu->nItems * sizeof(MENUITEM),
GMEM_MOVEABLE );
}
return TRUE;
/**********************************************************************
BOOL DeleteMenu(HMENU hMenu, WORD nPos, WORD wFlags)
MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags );
if (!item) return FALSE;
if (item->item_flags & MF_POPUP) DestroyMenu( item->item_id );
/* nPos is now the position of the item */
RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION );
return TRUE;
}
/**********************************************************************
* ModifyMenu [USER.414]
*/
BOOL ModifyMenu(HMENU hMenu, WORD nPos, WORD wFlags, WORD wItemID, LPSTR lpNewItem)
{
LPMENUITEM lpitem;
if (IS_STRING_ITEM(wFlags))
dprintf_menu(stddeb,"ModifyMenu (%04X, %04X, %04X, %04X, '%s') !\n",
hMenu, nPos, wFlags, wItemID, lpNewItem);
else
dprintf_menu(stddeb,"ModifyMenu (%04X, %04X, %04X, %04X, %p) !\n",
hMenu, nPos, wFlags, wItemID, lpNewItem);
if (!(lpitem = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
if (IS_STRING_ITEM(lpitem->item_flags)) USER_HEAP_FREE( lpitem->hText );
lpitem->item_flags = wFlags & ~(MF_HILITE | MF_MOUSESELECT);
lpitem->item_id = wItemID;
if (IS_STRING_ITEM(wFlags))
{
lpitem->hText = USER_HEAP_ALLOC( GMEM_MOVEABLE, strlen(lpNewItem)+1 );
lpitem->item_text = (char *)USER_HEAP_ADDR( lpitem->hText );
strcpy( lpitem->item_text, lpNewItem );
}
else if (wFlags & MF_BITMAP) lpitem->hText = LOWORD((DWORD)lpNewItem);
else lpitem->item_text = lpNewItem;
SetRectEmpty( &lpitem->rect );
return TRUE;
}
/**********************************************************************
* CreatePopupMenu [USER.415]
*/
HMENU CreatePopupMenu()
{
HMENU hmenu;
POPUPMENU *menu;
if (!(hmenu = CreateMenu())) return 0;
menu = (POPUPMENU *) USER_HEAP_ADDR( hmenu );
menu->wFlags |= MF_POPUP;
return hmenu;
}
/**********************************************************************
* GetMenuCheckMarkDimensions [USER.417]
*/
DWORD GetMenuCheckMarkDimensions()
{
return MAKELONG( check_bitmap_width, check_bitmap_height );
/**********************************************************************
* SetMenuItemBitmaps [USER.418]
*/
BOOL SetMenuItemBitmaps(HMENU hMenu, WORD nPos, WORD wFlags,
HBITMAP hNewCheck, HBITMAP hNewUnCheck)
{
dprintf_menu(stddeb,"SetMenuItemBitmaps (%04X, %04X, %04X, %04X, %08X) !\n",
hMenu, nPos, wFlags, hNewCheck, hNewUnCheck);
if (!(lpitem = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE;
if (!hNewCheck && !hNewUnCheck)
{
/* If both are NULL, restore default bitmaps */
lpitem->hCheckBit = hStdCheck;
lpitem->hUnCheckBit = 0;
lpitem->item_flags &= ~MF_USECHECKBITMAPS;
}
else /* Install new bitmaps */
{
lpitem->hCheckBit = hNewCheck;
lpitem->hUnCheckBit = hNewUnCheck;
lpitem->item_flags |= MF_USECHECKBITMAPS;
}
return TRUE;
/**********************************************************************
* CreateMenu [USER.151]
*/
HMENU CreateMenu()
{
if (!(hMenu = USER_HEAP_ALLOC( GMEM_MOVEABLE, sizeof(POPUPMENU) )))
return 0;
menu = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu);
menu->hNext = 0;
menu->wFlags = 0;
menu->wMagic = MENU_MAGIC;
menu->hTaskQ = 0;
menu->Width = 0;
menu->Height = 0;
menu->nItems = 0;
menu->hWnd = 0;
menu->hItems = 0;
menu->FocusedItem = NO_SELECTED_ITEM;
dprintf_menu(stddeb,"CreateMenu // return %04X\n", hMenu);
}
/**********************************************************************
* DestroyMenu [USER.152]
*/
BOOL DestroyMenu(HMENU hMenu)
{
dprintf_menu(stddeb,"DestroyMenu (%04X) !\n", hMenu);
if ((lppop->wFlags & MF_POPUP) && lppop->hWnd)
DestroyWindow( lppop->hWnd );
if (lppop->hItems)
{
int i;
MENUITEM *item = (MENUITEM *) USER_HEAP_ADDR( lppop->hItems );
for (i = lppop->nItems; i > 0; i--, item++)
{
if (item->item_flags & MF_POPUP)
}
USER_HEAP_FREE( lppop->hItems );
}
USER_HEAP_FREE( hMenu );
dprintf_menu(stddeb,"DestroyMenu (%04X) // End !\n", hMenu);
/**********************************************************************
* GetSystemMenu [USER.156]
*/
HMENU GetSystemMenu(HWND hWnd, BOOL bRevert)
{
WND *wndPtr;
wndPtr = WIN_FindWndPtr(hWnd);
if (!bRevert) {
return wndPtr->hSysMenu;
}
else {
DestroyMenu(wndPtr->hSysMenu);
wndPtr->hSysMenu = CopySysMenu();
}
/**********************************************************************
* SetSystemMenu [USER.280]
*/
BOOL SetSystemMenu(HWND hWnd, HMENU newHmenu)
{
if ((wndPtr = WIN_FindWndPtr(hWnd)) != NULL) wndPtr->hSysMenu = newHmenu;
return TRUE;
/**********************************************************************
* GetMenu [USER.157]
*/
HMENU GetMenu(HWND hWnd)
{
WND * wndPtr = WIN_FindWndPtr(hWnd);
if (wndPtr == NULL) return 0;
return wndPtr->wIDmenu;
/**********************************************************************
* SetMenu [USER.158]
*/
BOOL SetMenu(HWND hWnd, HMENU hMenu)
{
fprintf(stderr,"SetMenu(%04X, %04X) // Bad window handle !\n",
hWnd, hMenu);
dprintf_menu(stddeb,"SetMenu(%04X, %04X);\n", hWnd, hMenu);
wndPtr->wIDmenu = hMenu;
if (hMenu != 0)
{
fprintf(stderr,"SetMenu(%04X, %04X) // Bad menu handle !\n",
hWnd, hMenu);
lpmenu->hWnd = hWnd;
lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */
lpmenu->Height = 0; /* Make sure we recalculate the size */
}
SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
/**********************************************************************
* GetSubMenu [USER.159]
*/
HMENU GetSubMenu(HMENU hMenu, short nPos)
{
dprintf_menu(stddeb,"GetSubMenu (%04X, %04X) !\n", hMenu, nPos);
if (!(lppop = (LPPOPUPMENU) USER_HEAP_ADDR(hMenu))) return 0;
if ((WORD)nPos >= lppop->nItems) return 0;
lpitem = (MENUITEM *) USER_HEAP_ADDR( lppop->hItems );
if (!(lpitem[nPos].item_flags & MF_POPUP)) return 0;
return lpitem[nPos].item_id;
}
/**********************************************************************
* DrawMenuBar [USER.160]
wndPtr = WIN_FindWndPtr(hWnd);
if (wndPtr != NULL && (wndPtr->dwStyle & WS_CHILD) == 0 &&
wndPtr->wIDmenu != 0) {
dprintf_menu(stddeb,"DrawMenuBar wIDmenu=%04X \n",
wndPtr->wIDmenu);
lppop = (LPPOPUPMENU) USER_HEAP_ADDR(wndPtr->wIDmenu);