static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) { LONG state = get_button_state( hwnd ); DRAWITEMSTRUCT dis; LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID ); HWND parent; HFONT hFont, hPrevFont = 0; HRGN hrgn; dis.CtlType = ODT_BUTTON; dis.CtlID = id; dis.itemID = 0; dis.itemAction = action; dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) | ((state & BST_PUSHED) ? ODS_SELECTED : 0) | (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED); dis.hwndItem = hwnd; dis.hDC = hDC; dis.itemData = 0; GetClientRect( hwnd, &dis.rcItem ); if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); hrgn = set_control_clipping( hDC, &dis.rcItem ); SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis ); if (hPrevFont) SelectObject(hDC, hPrevFont); SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }
static void GB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc, rcFrame; HBRUSH hbr; HFONT hFont; UINT dtFlags; TEXTMETRICW tm; LONG style = GetWindowLongW( hwnd, GWL_STYLE ); HWND parent; HRGN hrgn; if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); /* GroupBox acts like static control, so it sends CTLCOLORSTATIC */ parent = GetParent(hwnd); if (!parent) parent = hwnd; hbr = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); if (!hbr) /* did the app forget to call defwindowproc ? */ hbr = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); GetClientRect( hwnd, &rc); rcFrame = rc; hrgn = set_control_clipping( hDC, &rc ); GetTextMetricsW (hDC, &tm); rcFrame.top += (tm.tmHeight / 2) - 1; DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT | ((style & BS_FLAT) ? BF_FLAT : 0)); InflateRect(&rc, -7, 1); dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rc); if (dtFlags != (UINT)-1) { /* Because buttons have CS_PARENTDC class style, there is a chance * that label will be drawn out of client rect. * But Windows doesn't clip label's rect, so do I. */ /* There is 1-pixel margin at the left, right, and bottom */ rc.left--; rc.right++; rc.bottom++; FillRect(hDC, &rc, hbr); rc.left++; rc.right--; rc.bottom--; BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rc); } SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }
static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rbox, rtext, client; HBRUSH hBrush; int delta; UINT dtFlags; HFONT hFont; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); HWND parent; HRGN hrgn; if (style & BS_PUSHLIKE) { PB_Paint( hwnd, hDC, action ); return; } GetClientRect(hwnd, &client); rbox = rtext = client; if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC); hrgn = set_control_clipping( hDC, &client ); if (style & BS_LEFTTEXT) { /* magic +4 is what CTL3D expects */ rtext.right -= checkBoxWidth + 4; rbox.left = rbox.right - checkBoxWidth; } else { rtext.left += checkBoxWidth + 4; rbox.right = checkBoxWidth; } /* Since WM_ERASEBKGND does nothing, first prepare background */ if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush ); if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush ); /* Draw label */ client = rtext; dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext); /* Only adjust rbox when rtext is valid */ if (dtFlags != (UINT)-1L) { rbox.top = rtext.top; rbox.bottom = rtext.bottom; } /* Draw the check-box bitmap */ if (action == ODA_DRAWENTIRE || action == ODA_SELECT) { UINT flags; if ((get_button_type(style) == BS_RADIOBUTTON) || (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO; else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE; else flags = DFCS_BUTTONCHECK; if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED; if (state & BST_PUSHED) flags |= DFCS_PUSHED; if (style & WS_DISABLED) flags |= DFCS_INACTIVE; /* rbox must have the correct height */ delta = rbox.bottom - rbox.top - checkBoxHeight; if (style & BS_TOP) { if (delta > 0) { rbox.bottom = rbox.top + checkBoxHeight; } else { rbox.top -= -delta/2 + 1; rbox.bottom = rbox.top + checkBoxHeight; } } else if (style & BS_BOTTOM) { if (delta > 0) { rbox.top = rbox.bottom - checkBoxHeight; } else { rbox.bottom += -delta/2 + 1; rbox.top = rbox.bottom - checkBoxHeight; } } else { /* Default */ if (delta > 0) { int ofs = (delta / 2); rbox.bottom -= ofs + 1; rbox.top = rbox.bottom - checkBoxHeight; } else if (delta < 0) { int ofs = (-delta / 2); rbox.top -= ofs + 1; rbox.bottom = rbox.top + checkBoxHeight; } } DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags ); } if (dtFlags == (UINT)-1L) /* Noting to draw */ return; if (action == ODA_DRAWENTIRE) BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext); /* ... and focus */ if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) { rtext.left--; rtext.right++; IntersectRect(&rtext, &rtext, &client); DrawFocusRect( hDC, &rtext ); } } SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }
/********************************************************************** * Push Button Functions */ static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc, r; UINT dtFlags, uState; HPEN hOldPen; HBRUSH hOldBrush; INT oldBkMode; COLORREF oldTxtColor; HFONT hFont; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); BOOL pushedState = (state & BST_PUSHED); HWND parent; HRGN hrgn; GetClientRect( hwnd, &rc ); /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); hrgn = set_control_clipping( hDC, &rc ); #ifdef __REACTOS__ hOldPen = SelectObject(hDC, GetStockObject(DC_PEN)); SetDCPenColor(hDC, GetSysColor(COLOR_WINDOWFRAME)); #else hOldPen = SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME)); #endif hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); oldBkMode = SetBkMode(hDC, TRANSPARENT); if (get_button_type(style) == BS_DEFPUSHBUTTON) { if (action != ODA_FOCUS) Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); InflateRect( &rc, -1, -1 ); } /* completely skip the drawing if only focus has changed */ if (action == ODA_FOCUS) goto draw_focus; uState = DFCS_BUTTONPUSH; if (style & BS_FLAT) uState |= DFCS_MONO; else if (pushedState) { if (get_button_type(style) == BS_DEFPUSHBUTTON ) uState |= DFCS_FLAT; else uState |= DFCS_PUSHED; } if (state & (BST_CHECKED | BST_INDETERMINATE)) uState |= DFCS_CHECKED; DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); /* draw button label */ r = rc; dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r); if (dtFlags == (UINT)-1L) goto cleanup; if (pushedState) OffsetRect(&r, 1, 1); oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r); SetTextColor( hDC, oldTxtColor ); draw_focus: if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) { InflateRect( &rc, -2, -2 ); DrawFocusRect( hDC, &rc ); } } cleanup: SelectObject( hDC, hOldPen ); SelectObject( hDC, hOldBrush ); SetBkMode(hDC, oldBkMode); SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }