From: <kr_...@us...> - 2004-08-24 08:15:27
|
Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6226/src/cbits/Win32 Modified Files: Frame.c Log Message: bugfix: MaskBlt works only under WinNT+ so use BitBlt instead Index: Frame.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Frame.c,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Frame.c 23 Aug 2004 19:45:43 -0000 1.32 --- Frame.c 24 Aug 2004 08:15:12 -0000 1.33 *************** *** 93,96 **** --- 93,173 ---- } + void DrawMenuItemCheck(HDC hdc, ActionHandle action, RECT rcFrame, BOOL bSelected) + { + HBITMAP bmAndObject, bmAndBack, bmAndMem; + HBITMAP bmObjectOld, bmBackOld, bmMemOld; + HDC hdcObj, hdcBack, hdcMem; + POINT ptSize; + RECT rc; + + ptSize.x = rcFrame.right - rcFrame.left; + ptSize.y = rcFrame.bottom - rcFrame.top; + + rc.left = 0; + rc.top = 0; + rc.right = ptSize.x; + rc.bottom= ptSize.y; + + // Create some DCs to hold temporary data. + hdcMem = CreateCompatibleDC(hdc); + hdcBack = CreateCompatibleDC(hdc); + hdcObj = CreateCompatibleDC(hdc); + + // Create a bitmap for each DC. DCs are required for a number of + // GDI functions. + + // Monochrome DC + bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); + bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); + + bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); + + // Each DC must select a bitmap object to store pixel data. + bmObjectOld = SelectObject(hdcObj, bmAndObject); + bmBackOld = SelectObject(hdcBack, bmAndBack); + bmMemOld = SelectObject(hdcMem, bmAndMem); + + // Set proper mapping mode. + SetMapMode(hdcObj, GetMapMode(hdc)); + + switch (action->type) + { + case ACTION_CHECK: + DrawFrameControl(hdcObj, &rc, DFC_MENU, DFCS_MENUCHECK); + break; + case ACTION_RADIO: + DrawFrameControl(hdcObj, &rc, DFC_MENU, DFCS_MENUBULLET); + break; + } + + // Create the inverse of the object. + BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObj, 0, 0, NOTSRCCOPY); + + // Copy the background of the main DC to the destination. + BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, rcFrame.left, rcFrame.top, SRCCOPY); + + // Mask out the places where the bitmap will be placed. + BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObj, 0, 0, SRCAND); + + if (bSelected) + { + // XOR the bitmap with the background on the destination DC. + BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCPAINT); + } + + // Copy the destination to the screen. + BitBlt(hdc, rcFrame.left, rcFrame.top, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY); + + // Delete the memory bitmaps. + DeleteObject(SelectObject(hdcMem, bmMemOld)); + DeleteObject(SelectObject(hdcBack, bmBackOld)); + DeleteObject(SelectObject(hdcObj, bmObjectOld)); + + // Delete the memory DCs. + DeleteDC(hdcMem); + DeleteDC(hdcBack); + DeleteDC(hdcObj); + } + void SaveWindowState(HWND hWnd) { *************** *** 324,328 **** { long lDims; ! RECT rcFrame, rcBox, rcFill, rc; POINT pt; WORD wCheckWidth, wCheckHeight; --- 401,405 ---- { long lDims; ! RECT rcFrame, rcBox, rc; POINT pt; WORD wCheckWidth, wCheckHeight; *************** *** 369,382 **** SetBkMode(lpDIS->hDC,TRANSPARENT); ! // Add some spacing before drawing the text and hi-lite ! rcFill.left = lpDIS->rcItem.left; ! rcFill.top = lpDIS->rcItem.top-1; ! rcFill.right = lpDIS->rcItem.right; ! rcFill.bottom= lpDIS->rcItem.bottom; ! ! if ((lpDIS->itemState & ODS_SELECTED) && (lpDIS->itemState & ODS_CHECKED)) ! rcFill.left+=wWidth+Spacing; ! ! FillRect(lpDIS->hDC, &rcFill, hFillBrush); rc = lpDIS->rcItem; --- 446,450 ---- SetBkMode(lpDIS->hDC,TRANSPARENT); ! FillRect(lpDIS->hDC, &lpDIS->rcItem, hFillBrush); rc = lpDIS->rcItem; *************** *** 405,450 **** { if (action->checked) ! { ! HDC hMemDC; ! HBITMAP hBmp; ! RECT rc; ! ! hMemDC = CreateCompatibleDC(lpDIS->hDC); ! hBmp = CreateCompatibleBitmap(hMemDC, ! rcFrame.right-rcFrame.left, rcFrame.bottom-rcFrame.top); ! ! SelectObject(hMemDC, hBmp); ! ! rc.left = 0; ! rc.top = 0; ! rc.right = rcFrame.right-rcFrame.left; ! rc.bottom= rcFrame.bottom-rcFrame.top; ! ! switch (action->type) ! { ! case ACTION_CHECK: ! DrawFrameControl(hMemDC, &rc, DFC_MENU, DFCS_MENUCHECK); ! break; ! case ACTION_RADIO: ! DrawFrameControl(hMemDC, &rc, DFC_MENU, DFCS_MENUBULLET); ! break; ! } ! ! SelectObject(lpDIS->hDC, hFillBrush); ! ! MaskBlt(lpDIS->hDC, ! rcFrame.left, ! rcFrame.top, ! rcFrame.right-rcFrame.left, ! rcFrame.bottom-rcFrame.top, ! hMemDC, ! 0, 0, ! hBmp, ! 0, 0, ! MAKEROP4(SRCAND, (lpDIS->itemState & ODS_SELECTED) ? WHITENESS : BLACKNESS)); ! ! DeleteObject(hBmp); ! DeleteDC(hMemDC); ! } } --- 473,477 ---- { if (action->checked) ! DrawMenuItemCheck(lpDIS->hDC, action, rcFrame, (lpDIS->itemState & ODS_SELECTED)); } |