The final bit. Sorry for the messy formatting.
void CButtonST::PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage)
{
CRect rBtn;
GetClientRect(&rBtn);
PrepareSTButtonImageRect(bHasTitle, rpItem, rpTitle, bIsPressed, dwWidth, dwHeight, rpImage, m_byAlign, m_nBitmapPadding, m_ptImageOrg, m_ptPressedOffset,
rBtn, (GetStyle() & BS_LEFT) == BS_LEFT, m_bIsCheckBox);
} void CButtonST::DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
{
BYTE byIndex = 0;
ASSERT(!m_bIsCheckBox && !m_bIsRadio);
if ((m_bIsCheckBox && bIsPressed) || (!m_bIsCheckBox && (bIsPressed || m_bMouseOnButton)))
byIndex = 0;
else
byIndex = (BYTE)(m_csIcons[1].hIcon == NULL ? 0 : 1);
CRect rectClient;
GetClientRect(&rectClient);
DrawTheSTButtonIcon(pDC, bHasTitle, rpItem, rpCaption, bIsPressed, bIsDisabled,
m_csIcons[byIndex].hIcon, m_csIcons[byIndex].dwWidth, m_csIcons[byIndex].dwHeight, m_byAlign, m_nBitmapPadding, m_ptImageOrg, m_ptPressedOffset,
rectClient, (GetStyle() & BS_LEFT) == BS_LEFT,
m_bIsCheckBox);
}
void CButtonST::DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
{
UNREFERENCED_PARAMETER(bIsPressed);
UNUSED_ALWAYS(bIsPressed);
UNREFERENCED_PARAMETER(bIsDisabled);
UNUSED_ALWAYS(bIsDisabled);
ASSERT(!m_bIsCheckBox && !m_bIsRadio);
DrawTheSTButtonText(GetSafeHwnd(), pDC, lpszText, rpItem, rpCaption, m_bIsPressed, m_bIsDisabled, m_bMouseOnButton,
m_bIsFocused,
m_bIsCheckBox, m_ptPressedOffset, m_csIcons[0].hIcon, m_csBitmaps[0].hBitmap,
m_byAlign, GetStyle(), m_nBitmapPadding,
GetPressedTextColour(), GetFocusedTextColour(), GetTextColour(), m_crColors[BTNST_COLOR_BK_IN],
m_crColors[BTNST_COLOR_BK_FOCUS], m_crColors[BTNST_COLOR_BK_OUT], bSTBUTTON_BUTTONISWINDOW);
} DWORD CButtonST::OnDrawBackground(CDC* pDC, CRect* pRect)
{
return DrawSTButtonBackground(GetSafeHwnd(), pDC, pRect, m_bIsDefault, m_bIsFocused, m_bMouseOnButton, m_bIsPressed,
m_bIsFlat, m_crColors[BTNST_COLOR_BK_IN], m_crColors[BTNST_COLOR_BK_FOCUS], m_crColors[BTNST_COLOR_BK_OUT]);
}
DWORD DrawSTButtonBackground(HWND hWnd, CDC* pDC, CRect* pRect, IN const int bIsDefault,
IN const int bIsFocused, IN const int bMouseOnButton, IN const int bIsPressed,
IN const int bIsFlat, IN const COLORREF colorIn, IN const COLORREF colorFocus,
IN const COLORREF colorOut)
{
UNUSED_ALWAYS(hWnd);
COLORREF crColor;
if (bIsFlat == FALSE)
{
if (bIsFocused || bIsDefault)
{
CBrush br(RGB(0,0,0));
pDC->FrameRect(pRect, &br);
pRect->DeflateRect(1, 1);
} } if (bMouseOnButton || bIsPressed)
crColor = colorIn;
else
{
if (bIsFocused)
crColor = colorFocus;
else
crColor = colorOut;
} CBrush brBackground(crColor);
pDC->FillRect(pRect, &brBackground);
return BTNST_OK;
}
DWORD CButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)
{
return DrawSTButtonBorder(pDC, pRect, m_bIsPressed != 0, m_bIsFlat != 0, m_bDrawBorder != 0, m_bMouseOnButton != 0);
} DWORD DrawSTButtonBorder(CDC* pDC, CRect* pRect, IN const bool bIsPressed, IN const bool bIsFlat,
IN const bool bDrawBorder, IN const bool bMouseOnButton)
{
if (bIsPressed)
{
if (bIsFlat)
{
if (bDrawBorder)
pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));
}
else
{
CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
pDC->FrameRect(pRect, &brBtnShadow);
}
}
else {
CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); if (bIsFlat)
{
if (bMouseOnButton && bDrawBorder)
pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
}
else
{
CPen* pOldPen = pDC->SelectObject(&penBtnHiLight);
pDC->MoveTo(pRect->left, pRect->bottom-1);
pDC->LineTo(pRect->left, pRect->top);
pDC->LineTo(pRect->right, pRect->top);
pDC->SelectObject(pen3DLight);
pDC->MoveTo(pRect->left+1, pRect->bottom-1);
pDC->LineTo(pRect->left+1, pRect->top+1);
pDC->LineTo(pRect->right, pRect->top+1);
pDC->SelectObject(pen3DDKShadow);
pDC->MoveTo(pRect->left, pRect->bottom-1);
pDC->LineTo(pRect->right-1, pRect->bottom-1);
pDC->LineTo(pRect->right-1, pRect->top-1);
pDC->SelectObject(penBtnShadow);
pDC->MoveTo(pRect->left+1, pRect->bottom-2);
pDC->LineTo(pRect->right-2, pRect->bottom-2);
pDC->LineTo(pRect->right-2, pRect->top);
pDC->SelectObject(pOldPen);
} } return BTNST_OK;
}
void DrawTheSTButtonText(HWND hWnd, CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, IN const BOOL bIsPressed,
IN const BOOL bIsDisabled, IN const BOOL bMouseOnButton, IN const BOOL bIsFocused,
IN const BOOL bIsCheckBox, IN const CPoint ptPressedOffset, IN const HICON hIcon,
IN const HBITMAP hBitmap, IN const BYTE byAlign, IN const DWORD style,
IN const short nBitmapPadding, IN const COLORREF colorForeIn,IN const COLORREF colorForeFocus,
IN const COLORREF colorForeOut,IN const COLORREF colorBackIn,
IN const COLORREF colorBackFocus,IN const COLORREF colorBackOut, IN const bool bButtonIsWindow)
{
if (bIsPressed && bIsCheckBox == FALSE)
rpCaption->OffsetRect(ptPressedOffset.x, ptPressedOffset.y);
CTempThemeHandle* pTempHandleTheme = NULL;
int nState;
int nSaveDC;
int nTotalBlockToCentre = 0;
int nLeftOffsetForBlock = 0;
int nOffsetForCaption = 0;
COLORREF colourThemeText = COLOR_BLACK;
bool bDrawThemeText = true;
nSaveDC = pDC->SaveDC();
CRect centerRect = rpCaption;
bool bHaveBitmap = (hIcon || hBitmap);
CRect rectItem = rpItem;
if (bIsPressed)
{
nState = PBS_PRESSED;
}
else if (bIsDisabled)
{
nState = PBS_DISABLED;
}
else if (bMouseOnButton)
{
nState = PBS_HOT;
}
else
{
nState = PBS_NORMAL;
}
#ifdef _UNICODE
if (CVisualStylesXP::GetInstance()->IsAppUsingThemes())
{
pTempHandleTheme = new CTempThemeHandle(hWnd, L"BUTTON");
CVisualStylesXP::GetInstance()->GetThemeColor(pTempHandleTheme->GetThemeHandle(), BP_PUSHBUTTON, PBS_NORMAL, TMT_TEXTCOLOR, &colourThemeText);
if (colourThemeText != colorForeOut)
{
bDrawThemeText = false;
}
}
#endif
rpCaption->left += ::GetSystemMetrics(SM_CXBORDER);
rpCaption->right -= ::GetSystemMetrics(SM_CXBORDER);
pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);
if (byAlign == CButtonST::ST_ALIGN_HORIZ)
{
if (style & BS_LEFT)
{
rpCaption->OffsetRect(0, (centerRect.Height() - rpCaption->Height())/2);
}
else if (style & BS_RIGHT)
{
TRACE0("Right-aligned button text not supported right now. Come back next week.\n");
}
else
{
if (!bButtonIsWindow)
{
if (bHaveBitmap)
{
nTotalBlockToCentre = rpCaption->left - rectItem.left - nBitmapPadding + rpCaption->Width();
nLeftOffsetForBlock = (rectItem.Width() - nTotalBlockToCentre)/2;
nOffsetForCaption = nLeftOffsetForBlock + rpCaption->left - rectItem.left - nBitmapPadding;
(*rpCaption).right = rectItem.left + nOffsetForCaption + (*rpCaption).Width();
(*rpCaption).left = rectItem.left + nOffsetForCaption;
(*rpCaption).OffsetRect( 0, (rectItem.Height() - rpCaption->Height())/2);
}
else
{
(*rpCaption).OffsetRect( (rectItem.Width() - rpCaption->Width())/2, (rectItem.Height() - rpCaption->Height())/2);
}
}
else
{
(*rpCaption) = CRect(CPoint( (rectItem.Width() - rpCaption->Width())/2,
(rectItem.Height() - rpCaption->Height())/2 ), rpCaption->Size());
}
if (bHaveBitmap && bButtonIsWindow && centerRect.left + nBitmapPadding > rpCaption->left)
{
rpCaption->OffsetRect(centerRect.left + nBitmapPadding - rpCaption->left, 0);
}
}
}
CRect rcItem = *rpItem;
if (rpCaption->Height() > rcItem.Height())
{
rpCaption->top -= (rpCaption->Height() - rcItem.Height());
}
pDC->SetBkMode(TRANSPARENT);
#ifdef _UNICODE
if (CVisualStylesXP::GetInstance()->IsAppUsingThemes() && bDrawThemeText)
{
CVisualStylesXP::GetInstance()->DrawThemeText(pTempHandleTheme->GetThemeHandle(),
pDC->GetSafeHdc(), BP_PUSHBUTTON, nState, lpszText, -1, DT_WORDBREAK | DT_CENTER ,
NULL, rpCaption);
}
else
#endif
{
if (bIsDisabled)
{
rpCaption->OffsetRect(1, 1);
pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
rpCaption->OffsetRect(-1, -1);
pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
} else
{
if (bMouseOnButton || bIsPressed)
{
pDC->SetTextColor(colorForeIn);
pDC->SetBkColor(colorBackIn);
} else
{
if (bIsFocused)
{
pDC->SetTextColor(colorForeFocus);
pDC->SetBkColor(colorBackFocus);
} else
{
pDC->SetTextColor(colorForeOut);
pDC->SetBkColor(colorBackOut);
} } pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
} }
pDC->RestoreDC(nSaveDC);
DELETE_SAFE(pTempHandleTheme);
}
void PrepareSTButtonImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage, BYTE byAlign,
short nBitmapPadding, POINT ptImageOrg, POINT ptPressedOffset, IN const CRect rectClient, IN const bool bTextLeftAligned, BOOL bIsCheckBox)
{
CRect rBtn;
rpImage->CopyRect(rpItem);
switch (byAlign)
{
case CButtonST::ST_ALIGN_HORIZ:
if (bHasTitle == FALSE)
{
rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);
}
else
{
rpImage->left += ptImageOrg.x;
if (bTextLeftAligned)
{
rpTitle->left += dwWidth + ptImageOrg.x + nBitmapPadding;
}
else
{
rpTitle->left += dwWidth + ptImageOrg.x;
}
}
rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);
break;
case CButtonST::ST_ALIGN_HORIZ_RIGHT:
if (bHasTitle == FALSE)
{
rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);
}
else
{
rpTitle->right = rpTitle->Width() - dwWidth - ptImageOrg.x;
rpTitle->left = ptImageOrg.x;
rpImage->left = rectClient.right - dwWidth - ptImageOrg.x;
rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);
}
break;
case CButtonST::ST_ALIGN_VERT:
rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);
if (bHasTitle == FALSE)
{
rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);
}
else
{
rpImage->top = ptImageOrg.y;
rpTitle->top += dwHeight;
}
break;
case CButtonST::ST_ALIGN_OVERLAP:
break;
}
if (bIsPressed && bIsCheckBox == FALSE)
rpImage->OffsetRect(ptPressedOffset.x, ptPressedOffset.y);
} void DrawTheSTButtonIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled,
HICON hIcon, int nIconWidth, int nIconHeight, BYTE byAlign,
short nBitmapPadding, POINT ptImageOrg, POINT ptPressedOffset, IN const CRect rectClient, IN const bool bTextLeftAligned,
BOOL bIsCheckBox)
{
CRect rImage;
PrepareSTButtonImageRect(bHasTitle, rpItem, rpCaption, bIsPressed, nIconWidth, nIconHeight, &rImage, byAlign,
nBitmapPadding, ptImageOrg, ptPressedOffset, rectClient, bTextLeftAligned, bIsCheckBox);
pDC->DrawState(rImage.TopLeft(),
rImage.Size(),
hIcon,
(bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
(CBrush*)NULL);
}
- Pfft. Coddled kids. In my day, we used to telnet to port 80, then render the page with pencil and paper-- and that's the way we liked it!
- Pshaw! Youngster. Your UID barely fits inside 16 bits. In _my_ day we had to whistle the 1's and 0's through an acoustic coupler!
Tools that support "all of UTF-8 as long as it starts with ASCII" and tools that cannot handle these three [BOM] bytes at all are not really supporting UTF-8.
- Michael Kaplan
|