diff options
| -rw-r--r-- | alf/alflabel.cpp | 68 |
1 files changed, 49 insertions, 19 deletions
diff --git a/alf/alflabel.cpp b/alf/alflabel.cpp index 73296d9..d0b9b59 100644 --- a/alf/alflabel.cpp +++ b/alf/alflabel.cpp @@ -66,75 +66,105 @@ ALF_Label_Paint(HWND hwnd, ALFLabelPriv *priv, HDC hdc, RECT *r) { if (priv->bgcolor == ALF_COLOR_TRANSPARENT) { ALF_Compat_DrawThemeParentBackground(hwnd, hdc, r); + SetBkMode(hdc, TRANSPARENT); } else { ALF_FillRect(hdc, r, priv->bgcolor); + SetBkMode(hdc, OPAQUE); + SetBkColor(hdc, ALF_ColorToGdi(priv->bgcolor)); } HFONT oldFont = SelectFont(hdc, priv->font); - SetTextColor(hdc, ALF_ColorToGdi(priv->textcolor)); - SetBkMode(hdc, TRANSPARENT); + + TCHAR *text = ALF_Text(hwnd); // calc drawtext style - UINT format = DT_EXPANDTABS; + UINT format = DT_EXPANDTABS | DT_NOCLIP; LRESULT uiState = SendMessage(hwnd, WM_QUERYUISTATE, 0, 0); if (uiState & UISF_HIDEACCEL) format |= DT_HIDEPREFIX; - RECT rc; - GetClientRect(hwnd, &rc); + // calculate text position + RECT rcClient = { 0, 0, 0, 0 }; + GetClientRect(hwnd, &rcClient); + + RECT rcText = { 0, 0, 0, 0 }; + DrawText(hdc, text, -1, &rcText, DT_EXPANDTABS | DT_CALCRECT); + + RECT rcTarget = { 0, 0, 0, 0 }; switch (priv->style & ALF_LABEL_HALIGN_MASK) { + case ALF_LABEL_ALIGN_LEFT: + format |= DT_LEFT; + rcTarget.left = 0; + rcTarget.right = rcText.right - rcText.left; + break; + case ALF_LABEL_ALIGN_LEFT_LIKE_EDIT: + format |= DT_LEFT; + rcTarget.left = ALF__LabelLeftPadding(hwnd, hdc, priv); + rcTarget.right = rcTarget.left + rcText.right - rcText.left; + break; case ALF_LABEL_ALIGN_HCENTER: format |= DT_CENTER; + rcTarget.left = (rcClient.right - rcClient.left - rcText.right + rcText.left)/2; + rcTarget.right = rcTarget.left + rcText.right - rcText.left; break; case ALF_LABEL_ALIGN_RIGHT: format |= DT_RIGHT; + rcTarget.right = rcClient.right - rcClient.left; + rcTarget.left = rcTarget.right - rcText.right + rcText.left; break; } switch (priv->style & ALF_LABEL_VALIGN_MASK) { + case ALF_LABEL_ALIGN_TOP: + format |= DT_TOP; + rcTarget.top = 0; + rcTarget.bottom = rcText.bottom - rcText.top; + break; + case ALF_LABEL_ALIGN_TOP_LIKE_EDIT: + format |= DT_TOP; + rcTarget.top = ALF__LabelTopPadding(hwnd, priv); + rcTarget.bottom = rcTarget.top + rcText.bottom - rcText.top; + break; case ALF_LABEL_ALIGN_BOTTOM: format |= DT_BOTTOM; + rcTarget.bottom = rcClient.bottom - rcClient.top; + rcTarget.top = rcTarget.bottom - rcText.bottom + rcText.top; break; case ALF_LABEL_ALIGN_VCENTER: format |= DT_VCENTER; + rcTarget.top = (rcClient.bottom - rcClient.top - rcText.bottom + rcText.top) / 2; + rcTarget.bottom = rcTarget.top + rcText.bottom - rcText.top; break; } - if ((priv->style & ALF_LABEL_HALIGN_MASK) == ALF_LABEL_ALIGN_LEFT_LIKE_EDIT) - rc.left += ALF__LabelLeftPadding(hwnd, hdc, priv); - if ((priv->style & ALF_LABEL_VALIGN_MASK) == ALF_LABEL_ALIGN_TOP_LIKE_EDIT) - rc.top += ALF__LabelTopPadding(hwnd, priv); - - TCHAR *text = ALF_Text(hwnd); - if (!IsWindowEnabled(hwnd)) { if (!ALF_Compat_IsMinWindowsVersion(4, 0)) { // Win32s/NT 3.51 uses gray text, but a different gray than Win9x SetTextColor(hdc, GetSysColor(COLOR_BTNSHADOW)); - DrawText(hdc, text, -1, &rc, format); + DrawText(hdc, text, -1, &rcTarget, format); } else if (ALF_Compat_IsWin9x()) { // Win9x just uses gray text. DSS_DISABLED is broken there, too, // so we can't get the NT look even if we wanted to SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); - DrawText(hdc, text, -1, &rc, format); + DrawText(hdc, text, -1, &rcTarget, format); } else { // FIXME! This doesn't look good when using uxtheme, even though windows does it the same way // need to investigate whether drawing with disabled button style looks nicer DrawState(hdc, NULL, ALF__Label_Text_DrawStateProc, (LPARAM)text, (WPARAM)format, - rc.left, - rc.top, - rc.right - rc.left, - rc.bottom - rc.top, + rcTarget.left, + rcTarget.top, + rcTarget.right - rcTarget.left, + rcTarget.bottom - rcTarget.top, DST_COMPLEX | DSS_DISABLED); } } else { - DrawText(hdc, text, -1, &rc, format); + DrawText(hdc, text, -1, &rcTarget, format); } ALF_Free(text); |
