void CHoverButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC); CPoint point(0,0); CGumpPtr pDib = m_pDib[NORMAL]; UINT state = lpDrawItemStruct->itemState; if (!IsCheckbox()) { if (state & ODS_DISABLED) pDib = m_pDib[NORMAL]; else if (state & ODS_SELECTED) pDib = m_pDib[PRESSED]; else if (m_bHover) pDib = m_pDib[HOVER]; } else { if (m_bClick) pDib = m_pDib[PRESSED]; } if (pDib) pDib->DrawTransparent(pDC, CPoint(0,0), RGB(255,255,255)); CString strText; GetWindowText(strText); CRect rcItem(lpDrawItemStruct->rcItem); if (lpDrawItemStruct->itemState & ODS_SELECTED) rcItem += CPoint(2,2); SetTextColor(lpDrawItemStruct->hDC, m_bHover ? RGB(255,255,0) : RGB(255,255,255)); DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE); }
void CHoverButton::OnBnClicked() { // TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다. if (IsCheckbox()) { m_bClick = !m_bClick; Invalidate(); } }
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::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); }