// invoked when child control is about to be drawn. prepare the pDC for drawing the // control using the correct system colors. HBRUSH CCustomListRowWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT32 nCtlColor) { HBRUSH hbr = CWnd::OnCtlColor(pDC, pWnd, nCtlColor); COLORREF text = m_Selected ? GetSysColor(COLOR_HIGHLIGHTTEXT) : GetSysColor(COLOR_WINDOWTEXT); pDC->SetTextColor(text); pDC->SetBkMode(TRANSPARENT); return GetBackgroundBrush(); }
MsgRouting AwtList::WmCtlColor(HDC hDC, HWND hCtrl, UINT ctlColor, HBRUSH& retBrush) { DASSERT(ctlColor == CTLCOLOR_LISTBOX); DASSERT(hCtrl == GetListHandle()); ::SetBkColor(hDC, GetBackgroundColor()); ::SetTextColor(hDC, GetColor()); retBrush = GetBackgroundBrush(); return mrConsume; }
void AwtLabel::DoPaint(HDC hDC, RECT& r) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if ((r.right-r.left) > 0 && (r.bottom-r.top) > 0 && m_peerObject != NULL && m_callbacksEnabled) { if (env->EnsureLocalCapacity(3) < 0) return; long x,y; SIZE size; /* self is sun.awt.windows.WLabelPeer */ jobject self = GetPeer(env); DASSERT(self); /* target is java.awt.Label */ jobject target = env->GetObjectField(self, AwtObject::targetID); jobject font = GET_FONT(target, self); jstring text = (jstring)env->GetObjectField(target, AwtLabel::textID); size = AwtFont::getMFStringSize(hDC, font, text); ::SetTextColor(hDC, GetColor()); /* Redraw whole label to eliminate display noise during resizing. */ VERIFY(::GetClientRect(GetHWnd(), &r)); VERIFY(::FillRect (hDC, &r, GetBackgroundBrush())); y = (r.top + r.bottom - size.cy) / 2; jint alignment = env->GetIntField(target, AwtLabel::alignmentID); switch (alignment) { case java_awt_Label_CENTER: x = (r.left + r.right - size.cx) / 2; break; case java_awt_Label_RIGHT: x = r.right - 2 - size.cx; break; case java_awt_Label_LEFT: default: x = r.left + 2; break; } /* draw string */ if (isEnabled()) { AwtComponent::DrawWindowText(hDC, font, text, x, y); } else { AwtComponent::DrawGrayText(hDC, font, text, x, y); } DoCallback("handlePaint", "(IIII)V", r.left, r.top, r.right-r.left, r.bottom-r.top); env->DeleteLocalRef(target); env->DeleteLocalRef(font); env->DeleteLocalRef(text); } }
LOCAL void Palette_HandleFocus(HWND hWindow, BOOL fSetFocus) /***********************************************************************/ { LPPALETTE lpPalette; RECT ClientRect; HDC hDC; HBRUSH hBrush; if ( !(GetWindowLong( hWindow, GWL_STYLE ) & WS_TABSTOP) ) return; bHasFocus = fSetFocus; lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE); if (!lpPalette) return; hDC = GetDC( hWindow ); GetClientRect( hWindow, &ClientRect ); InflateRect(&ClientRect, -1, -1); hBrush = GetBackgroundBrush( hDC, hWindow, CTLCOLOR_CUSTOM ); FrameRect( hDC, &ClientRect, (bHasFocus ? (HBRUSH)GetStockObject(BLACK_BRUSH) : hBrush) ); ReleaseDC( hWindow, hDC ); }
Bool GWinControl::CreateClass() { WNDCLASS wc; ZeroMemory(&wc,sizeof(wc)); wc.style = ClassStyle(); wc.lpfnWndProc = Win32CallBack; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GApp::g_HInstance; wc.hIcon = GetIconHandle(); wc.hCursor = NULL;//LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = GetBackgroundBrush(); wc.lpszMenuName = NULL; wc.lpszClassName = ClassName(); if (!RegisterClass(&wc)) { GDebug::CheckWin32Error(); return FALSE; } return TRUE; }
// Draw all tabs void wxTabView::Draw(wxDC& dc) { // Don't draw anything if there are no tabs. if (GetNumberOfTabs() == 0) return; // Draw top margin area (beneath tabs and above view area) if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) { dc.SetPen(*wxTRANSPARENT_PEN); if(GetBackgroundBrush()) dc.SetBrush(*GetBackgroundBrush()); // Add 1 because the pen is transparent. Under Motif, may be different. dc.DrawRectangle( m_tabViewRect.x, (m_tabViewRect.y - m_topMargin), (m_tabViewRect.width + 1), (m_topMargin + 1) ); } // Draw layers in reverse order wxTabLayerList::compatibility_iterator node = m_layers.GetLast(); while (node) { wxTabLayer *layer = (wxTabLayer *)node->GetData(); wxList::compatibility_iterator node2 = layer->GetFirst(); while (node2) { wxTabControl *control = (wxTabControl *)node2->GetData(); control->OnDraw(dc, (!node2->GetNext())); node2 = node2->GetNext(); } node = node->GetPrevious(); } #ifndef wxUSE_NEW_METHOD if (GetTabStyle() & wxTAB_STYLE_DRAW_BOX) { dc.SetPen(* GetShadowPen()); // Draw bottom line dc.DrawLine( (GetViewRect().x + 1), (GetViewRect().y + GetViewRect().height), (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y + GetViewRect().height) ); // Draw right line dc.DrawLine( (GetViewRect().x + GetViewRect().width), (GetViewRect().y - GetTopMargin() + 1), (GetViewRect().x + GetViewRect().width), (GetViewRect().y + GetViewRect().height) ); dc.SetPen(* wxBLACK_PEN); // Draw bottom line dc.DrawLine( (GetViewRect().x), (GetViewRect().y + GetViewRect().height + 1), #if defined(__WXMOTIF__) (GetViewRect().x + GetViewRect().width + 1), #else (GetViewRect().x + GetViewRect().width + 2), #endif (GetViewRect().y + GetViewRect().height + 1) ); // Draw right line dc.DrawLine( (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y - GetTopMargin()), (GetViewRect().x + GetViewRect().width + 1), (GetViewRect().y + GetViewRect().height + 1) ); } #endif }
MsgRouting AwtCheckbox::OwnerDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT& drawInfo) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(4) < 0) { return mrConsume; } jobject self = GetPeer(env); jobject target = env->GetObjectField(self, AwtObject::targetID); HDC hDC = drawInfo.hDC; RECT rect = drawInfo.rcItem; int checkSize; UINT nState; SIZE size; jobject font = GET_FONT(target, self); jstring str = (jstring)env->GetObjectField(target, AwtCheckbox::labelID); size = AwtFont::getMFStringSize(hDC, font, str); jobject group = env->GetObjectField(target, AwtCheckbox::groupID); if (group != NULL) nState = DFCS_BUTTONRADIO; else nState = DFCS_BUTTONCHECK; if (GetState()) nState |= DFCS_CHECKED; else nState &= ~DFCS_CHECKED; if (drawInfo.itemState & ODS_SELECTED) nState |= DFCS_PUSHED; if (drawInfo.itemAction & ODA_DRAWENTIRE) { VERIFY(::FillRect (hDC, &rect, GetBackgroundBrush())); } /* draw check mark */ checkSize = GetCheckSize(); RECT boxRect; boxRect.left = (GetRTL()) ? rect.right - checkSize : rect.left; boxRect.top = (rect.bottom - rect.top - checkSize)/2; boxRect.right = boxRect.left + checkSize; boxRect.bottom = boxRect.top + checkSize; ::DrawFrameControl(hDC, &boxRect, DFC_BUTTON, nState); /* * draw string * * 4 is a heuristic number */ rect.left = rect.left + checkSize + checkSize/4; if (drawInfo.itemAction & ODA_DRAWENTIRE) { BOOL bEnabled = isEnabled(); int x = (GetRTL()) ? rect.right - (checkSize + checkSize / 4 + size.cx) : rect.left; int y = (rect.top + rect.bottom - size.cy) / 2; if (bEnabled) { AwtComponent::DrawWindowText(hDC, font, str, x, y); } else { AwtComponent::DrawGrayText(hDC, font, str, x, y); } } /* Draw focus rect */ RECT focusRect; const int margin = 2; /* 2 is a heuristic number */ focusRect.left = (GetRTL()) ? rect.right - checkSize - checkSize / 4 - 2 * margin - size.cx : rect.left - margin; focusRect.top = (rect.top+rect.bottom-size.cy)/2; focusRect.right = (GetRTL()) ? rect.right - checkSize - checkSize / 4 + margin : focusRect.left + size.cx + 2 * margin; focusRect.bottom = focusRect.top + size.cy; /* draw focus rect */ if ((drawInfo.itemState & ODS_FOCUS) && ((drawInfo.itemAction & ODA_FOCUS)|| (drawInfo.itemAction &ODA_DRAWENTIRE))) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } /* erase focus rect */ else if (!(drawInfo.itemState & ODS_FOCUS) && (drawInfo.itemAction & ODA_FOCUS)) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } /* Notify any subclasses */ rect = drawInfo.rcItem; DoCallback("handlePaint", "(IIII)V", rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top); env->DeleteLocalRef(target); env->DeleteLocalRef(font); env->DeleteLocalRef(str); env->DeleteLocalRef(group); return mrConsume; }
MsgRouting AwtCheckbox::WmDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT far& drawInfo) { JNIEnv *env; /* associate JNIEnv with the current thread */ if (JVM -> AttachCurrentThread((void**) &env, 0) != 0) { return mrDoDefault; // CHECK: is this the right return type?? } CriticalSection::Lock l(GetLock()); jobject self = GetPeer(); jobject target = env -> GetObjectField(self, WCachedIDs.PPCObjectPeer_targetFID); HDC hDC = drawInfo.hDC; RECT rect = drawInfo.rcItem; int checkSize; UINT nState; SIZE size; jobject hJavaFont; jstring hJavaString; hJavaFont = GET_FONT(target); hJavaString = (jstring)env->CallObjectMethod(target, WCachedIDs.java_awt_Checkbox_getLabelMID); size = AwtFont::getMFStringSize(hDC,hJavaFont,hJavaString); if (env->CallObjectMethod(target, WCachedIDs.java_awt_Checkbox_getCheckboxGroupMID) != NULL) nState = DFCS_BUTTONRADIO; else nState = DFCS_BUTTONCHECK; if (GetState()) nState |= DFCS_CHECKED; else nState &= ~DFCS_CHECKED; if (drawInfo.itemState & ODS_SELECTED) nState |= DFCS_PUSHED; if (drawInfo.itemAction & ODA_DRAWENTIRE) { VERIFY(::FillRect (hDC, &rect, GetBackgroundBrush())); } //draw check mark checkSize = GetCheckSize(); RECT boxRect; boxRect.left = rect.left; boxRect.top = (rect.bottom - rect.top - checkSize)/2; boxRect.right = boxRect.left + checkSize; boxRect.bottom = boxRect.top + checkSize; ::DrawFrameControl(hDC, &boxRect, DFC_BUTTON, nState); //draw string rect.left = rect.left + checkSize + checkSize/4; //4 is a heuristic number if (drawInfo.itemAction & ODA_DRAWENTIRE) { BOOL bEnabled = isEnabled(); int x = rect.left; int y = (rect.top+rect.bottom-size.cy)/2; if (bEnabled) { AwtComponent::DrawWindowText(hDC, hJavaFont, hJavaString, x, y); } else { AwtComponent::DrawGrayText(hDC, hJavaFont, hJavaString, x, y); } } //Draw focus rect RECT focusRect; const int margin = 2; // 2 is a heuristic number focusRect.left = rect.left - margin; focusRect.top = (rect.top+rect.bottom-size.cy)/2; focusRect.right = focusRect.left + size.cx + 2*margin; focusRect.bottom = focusRect.top + size.cy; // draw focus rect if ((drawInfo.itemState & ODS_FOCUS) && ((drawInfo.itemAction & ODA_FOCUS)|| (drawInfo.itemAction &ODA_DRAWENTIRE))) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } // erase focus rect else if (!(drawInfo.itemState & ODS_FOCUS) && (drawInfo.itemAction & ODA_FOCUS)) { VERIFY(::DrawFocusRect(hDC, &focusRect)); } // Notify any subclasses rect = drawInfo.rcItem; env -> CallVoidMethod(GetPeer(), WCachedIDs.PPCComponentPeer_handlePaintMID, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top); return mrConsume; }
bool GameApplication::InitWindow(int showFlag) { const TCHAR *CLASSNAME = TEXT ( "EIAPPCLASS" ); WNDCLASS wc; ZeroMemory( &wc, sizeof(wc) ); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = GetAppInstance (); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = GetBackgroundBrush(); wc.lpszClassName = CLASSNAME; ATOM rc = RegisterClass ( &wc ); assert(rc); long WinStyle, WinStyleEx; WinStyleEx = 0; WinStyle = WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_CAPTION; RECT rect; rect.left = rect.top = 0; long w, h; GetWindowDims( w, h ); rect.right = w; rect.bottom = h; AdjustWindowRectEx ( &rect, WinStyle, false, WinStyleEx ); long width = rect.right - rect.left; long height = rect.bottom - rect.top; appWindow = CreateWindowEx ( WinStyleEx, CLASSNAME, GetTitle(), WinStyle, 0, 0, width, height, NULL, 0, GetAppInstance (), NULL ); if ( !appWindow ) return false; long left = ( GetSystemMetrics ( SM_CXSCREEN ) - width ) / 2; long top = ( GetSystemMetrics ( SM_CYSCREEN ) - height ) / 2; MoveWindow ( appWindow, left, top, width, height, TRUE ); ShowWindow ( appWindow, showFlag ); UpdateWindow ( appWindow ); return true; }