void AwtPopupMenu::Enable(BOOL isEnabled) { AwtMenu *menu = GetMenuContainer(); if (menu != NULL) { AwtMenu::Enable(isEnabled); return; } JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(1) < 0) { return; } jobject target = GetTarget(env); int nCount = CountItem(target); for (int i = 0; i < nCount; ++i) { AwtMenuItem *item = GetItem(target,i); jobject jitem = item->GetTarget(env); BOOL bItemEnabled = isEnabled && (jboolean)env->GetBooleanField(jitem, AwtMenuItem::enabledID); jstring labelStr = static_cast<jstring>(env->GetObjectField(jitem, AwtMenuItem::labelID)); LPCWSTR labelStrW = JNU_GetStringPlatformChars(env, labelStr, NULL); if (labelStrW && wcscmp(labelStrW, L"-") != 0) { item->Enable(bItemEnabled); } JNU_ReleaseStringPlatformChars(env, labelStr, labelStrW); env->DeleteLocalRef(labelStr); env->DeleteLocalRef(jitem); } env->DeleteLocalRef(target); }
BOOL AwtPopupMenu::IsDisabledAndPopup() { if (GetMenuContainer() != NULL) return FALSE; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(1) < 0) { return FALSE; } jobject target = GetTarget(env); BOOL bEnabled = (jboolean)env->GetBooleanField(target, AwtMenuItem::enabledID); env->DeleteLocalRef(target); return !bEnabled; }
void AwtPopupMenu::AddItem(AwtMenuItem *item) { AwtMenu::AddItem(item); if (GetMenuContainer() != NULL) return; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(1) < 0) { return; } jobject target = GetTarget(env); if (!(jboolean)env->GetBooleanField(target, AwtMenuItem::enabledID)) { item->Enable(FALSE); } env->DeleteLocalRef(target); }
void AwtMenuItem::SetState(BOOL isChecked) { AwtMenu* menu = GetMenuContainer(); /* Fix for bug 4257944 by [email protected] * check parent */ if (menu == NULL) return; DASSERT(menu != NULL && GetID() >= 0); VERIFY(::CheckMenuItem(menu->GetHMenu(), GetID(), MF_BYCOMMAND | (isChecked ? MF_CHECKED : MF_UNCHECKED)) != 0xFFFFFFFF); // Redraw menu bar if it was affected. if (menu->GetMenuBar() == menu) { ::DrawMenuBar(menu->GetOwnerHWnd()); } }
void AwtMenuItem::DoCommand() { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); // peer is sun.awt.windows.WMenuItemPeer jobject peer = GetPeer(env); if (IsCheckbox()) { UINT nState = ::GetMenuState(GetMenuContainer()->GetHMenu(), GetID(), MF_BYCOMMAND); DASSERT(nState != 0xFFFFFFFF); DoCallback("handleAction", "(Z)V", ((nState & MF_CHECKED) == 0)); } else { DoCallback("handleAction", "(JI)V", TimeHelper::getMessageTimeUTC(), (jint)AwtComponent::GetJavaModifiers()); } }
void AwtMenuItem::SetLabel(LPCTSTR sb) { AwtMenu* menu = GetMenuContainer(); /* Fix for bug 4257944 by [email protected] * check parent */ if (menu == NULL) return; DASSERT(menu != NULL && GetID() >= 0); /* * SetMenuItemInfo is replaced by this code for fix bug 4261935 */ HMENU hMenu = menu->GetHMenu(); MENUITEMINFO mii, mii1; // get full information about menu item memset(&mii, 0, sizeof(MENUITEMINFO)); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; ::GetMenuItemInfo(hMenu, GetID(), FALSE, &mii); mii.fType = MFT_OWNERDRAW; mii.dwTypeData = (LPTSTR)(*sb); // find index by menu item id int nMenuItemCount = ::GetMenuItemCount(hMenu);; int idx; for (idx = 0; (idx < nMenuItemCount); idx++) { memset(&mii1, 0, sizeof(MENUITEMINFO)); mii1.cbSize = sizeof mii1; mii1.fMask = MIIM_ID; ::GetMenuItemInfo(hMenu, idx, TRUE, &mii1); if (mii.wID == mii1.wID) break; } ::RemoveMenu(hMenu, idx, MF_BYPOSITION); ::InsertMenuItem(hMenu, idx, TRUE, &mii); // Redraw menu bar if it was affected. if (menu->GetMenuBar() == menu) { ::DrawMenuBar(menu->GetOwnerHWnd()); } }
void AwtMenuItem::Enable(BOOL isEnabled) { AwtMenu* menu = GetMenuContainer(); /* Fix for bug 4257944 by [email protected] * check state of the parent */ if (menu == NULL) return; isEnabled = isEnabled && !menu->IsDisabledAndPopup(); DASSERT(menu != NULL && GetID() >= 0); VERIFY(::EnableMenuItem(menu->GetHMenu(), GetID(), MF_BYCOMMAND | (isEnabled ? MF_ENABLED : MF_GRAYED)) != 0xFFFFFFFF); // Redraw menu bar if it was affected. if (menu->GetMenuBar() == menu) { ::DrawMenuBar(menu->GetOwnerHWnd()); } }
void AwtMenuItem::DrawSelf(DRAWITEMSTRUCT& drawInfo) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(4) < 0) { return; } // self is sun.awt.windows.WMenuItemPeer jobject self = GetPeer(env); // target is java.awt.MenuItem jobject target = env->GetObjectField(self, AwtObject::targetID); HDC hDC = drawInfo.hDC; RECT rect = drawInfo.rcItem; RECT textRect = rect; SIZE size; DWORD crBack,crText; HBRUSH hbrBack; jobject font = GetFont(env); jstring text = GetJavaString(env); size = AwtFont::getMFStringSize(hDC, font, text); /* 4700350: If the font size is taller than the menubar, change to the * default font. Otherwise, menu text is painted over the title bar and * client area. -bchristi */ if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) { env->DeleteLocalRef(font); font = env->NewLocalRef(GetDefaultFont(env)); size = AwtFont::getMFStringSize(hDC, font, text); } /* Fix for bug 4257944 by [email protected] * check state of the parent */ AwtMenu* menu = GetMenuContainer(); DASSERT(menu != NULL && GetID() >= 0); //Check whether the MenuItem is disabled. BOOL bEnabled = (jboolean)env->GetBooleanField(target, AwtMenuItem::enabledID); if (menu != NULL) { bEnabled = bEnabled && !menu->IsDisabledAndPopup(); } if ((drawInfo.itemState) & (ODS_SELECTED)) { // Set background and text colors for selected item crBack = ::GetSysColor (COLOR_HIGHLIGHT); // Disabled text must be drawn in gray. crText = ::GetSysColor(bEnabled? COLOR_HIGHLIGHTTEXT : COLOR_GRAYTEXT); } else { // COLOR_MENUBAR is only defined on WindowsXP. Our binaries are // built on NT, hence the below ifdef. #ifndef COLOR_MENUBAR #define COLOR_MENUBAR 30 #endif // Set background and text colors for unselected item if (IS_WINXP && IsTopMenu() && AwtDesktopProperties::IsXPStyle()) { crBack = ::GetSysColor (COLOR_MENUBAR); } else { crBack = ::GetSysColor (COLOR_MENU); } // Disabled text must be drawn in gray. crText = ::GetSysColor (bEnabled ? COLOR_MENUTEXT : COLOR_GRAYTEXT); } // Fill item rectangle with background color hbrBack = ::CreateSolidBrush (crBack); DASSERT(hbrBack); VERIFY(::FillRect (hDC, &rect, hbrBack)); VERIFY(::DeleteObject (hbrBack)); // Set current background and text colors ::SetBkColor (hDC, crBack); ::SetTextColor (hDC, crText); int nOldBkMode = ::SetBkMode(hDC, OPAQUE); DASSERT(nOldBkMode != 0); //draw check mark int checkWidth = ::GetSystemMetrics(SM_CXMENUCHECK); // Workaround for CR#6401956 if (IS_WINVISTA) { AdjustCheckWidth(checkWidth); } if (IsCheckbox()) { // means that target is a java.awt.CheckboxMenuItem jboolean state = (jboolean)env->GetBooleanField(target, AwtMenuItem::stateID); if (state) { DASSERT(drawInfo.itemState & ODS_CHECKED); RECT checkRect; ::CopyRect(&checkRect, &textRect); if (GetRTL()) checkRect.left = checkRect.right - checkWidth; else checkRect.right = checkRect.left + checkWidth; DrawCheck(hDC, checkRect); } } ::SetBkMode(hDC, TRANSPARENT); int x = 0; //draw string if (!IsTopMenu()){ textRect.left += checkWidth; x = (GetRTL()) ? textRect.right - checkWidth - size.cx : textRect.left; } else { x = textRect.left = (textRect.left + textRect.right - size.cx) / 2; } int y = (textRect.top+textRect.bottom-size.cy)/2; // Text must be drawn in emboss if the Menu is disabled and not selected. BOOL bEmboss = !bEnabled && !(drawInfo.itemState & ODS_SELECTED); if (bEmboss) { ::SetTextColor(hDC, GetSysColor(COLOR_BTNHILIGHT)); AwtFont::drawMFString(hDC, font, text, x + 1, y + 1, GetCodePage()); ::SetTextColor(hDC, GetSysColor(COLOR_BTNSHADOW)); } AwtFont::drawMFString(hDC, font, text, x, y, GetCodePage()); jstring shortcutLabel = (jstring)env->GetObjectField(self, AwtMenuItem::shortcutLabelID); if (!IsTopMenu() && shortcutLabel != NULL) { UINT oldAlign = 0; if (GetRTL()){ oldAlign = ::SetTextAlign(hDC, TA_LEFT); AwtFont::drawMFString(hDC, font, shortcutLabel, textRect.left, y, GetCodePage()); } else { oldAlign = ::SetTextAlign(hDC, TA_RIGHT); AwtFont::drawMFString(hDC, font, shortcutLabel, textRect.right - checkWidth, y, GetCodePage()); } ::SetTextAlign(hDC, oldAlign); } VERIFY(::SetBkMode(hDC,nOldBkMode)); env->DeleteLocalRef(target); env->DeleteLocalRef(text); env->DeleteLocalRef(font); env->DeleteLocalRef(shortcutLabel); }