void AwtPopupMenu::Show(JNIEnv *env, jobject event, BOOL isTrayIconPopup) { /* * For not TrayIcon popup. * Convert the event's XY to absolute coordinates. The XY is * relative to the origin component, which is passed by PopupMenu * as the event's target. */ if (env->EnsureLocalCapacity(2) < 0) { return; } jobject origin = (env)->GetObjectField(event, AwtEvent::targetID); jobject peerOrigin = GetPeerForTarget(env, origin); PDATA pData; JNI_CHECK_PEER_GOTO(peerOrigin, done); { AwtComponent* awtOrigin = (AwtComponent*)pData; POINT pt; UINT flags = 0; pt.x = (env)->GetIntField(event, AwtEvent::xID); pt.y = (env)->GetIntField(event, AwtEvent::yID); if (!isTrayIconPopup) { ::MapWindowPoints(awtOrigin->GetHWnd(), 0, (LPPOINT)&pt, 1); // Adjust to account for the Inset values RECT rctInsets; awtOrigin->GetInsets(&rctInsets); pt.x -= rctInsets.left; pt.y -= rctInsets.top; flags = TPM_LEFTALIGN | TPM_RIGHTBUTTON; } else { ::SetForegroundWindow(awtOrigin->GetHWnd()); flags = TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_RIGHTBUTTON | TPM_BOTTOMALIGN; } /* Invoke the popup. */ ::TrackPopupMenu(GetHMenu(), flags, pt.x, pt.y, 0, awtOrigin->GetHWnd(), NULL); if (isTrayIconPopup) { ::PostMessage(awtOrigin->GetHWnd(), WM_NULL, 0, 0); } } done: env->DeleteLocalRef(origin); env->DeleteLocalRef(peerOrigin); }
AwtMenuItem* AwtMenuBar::GetItem(jobject target, long index) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(2) < 0) { return NULL; } jobject menu = env->CallObjectMethod(target, AwtMenuBar::getMenuMID,index); if (!menu) return NULL; // menu item was removed concurrently DASSERT(!safe_ExceptionOccurred(env)); jobject menuItemPeer = GetPeerForTarget(env, menu); PDATA pData; JNI_CHECK_PEER_GOTO(menuItemPeer, done); AwtMenuItem* awtMenuItem = (AwtMenuItem*)pData; done: env->DeleteLocalRef(menu); env->DeleteLocalRef(menuItemPeer); return awtMenuItem; }