diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-27 16:32:09 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-04-27 16:32:09 +0200 |
| commit | 2f9bdf479c438a9f2e1129e5787db6e079c2204b (patch) | |
| tree | 0ece3ca9d256cf24c1a3ed4ed8fbc4e5dc98771a | |
| parent | 0dee09478a7b975b3921478966d4c78b7a032189 (diff) | |
add functions for drawing disabled text on buttons
now using the right way to do it everywhere but on Win3.1
| -rw-r--r-- | alf/alfbutton.cpp | 149 |
1 files changed, 88 insertions, 61 deletions
diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp index 667287a..2c7e918 100644 --- a/alf/alfbutton.cpp +++ b/alf/alfbutton.cpp @@ -33,6 +33,62 @@ typedef struct { } ALFNtButtonPriv; TCHAR *_alf_buttonClass = NULL; +static int (*ALF_Button_DrawDisabledText)(HDC,LPCTSTR,int,LPRECT,UINT) = NULL; + +static BOOL CALLBACK +ALF_Button_DrawDisabledText_DrawStateProc(HDC hdc, + LPARAM lData, + WPARAM wData, + int cx, + int cy) +{ + RECT rc = { 0, 0, cx, cy }; + DrawText(hdc, (const TCHAR *)lData, -1, &rc, (UINT)wData); + return TRUE; +} + + +static int +ALF_Button_DrawDisabledTextNt(HDC hdc, + LPCTSTR lpchText, + int cchText, + LPRECT lprc, + UINT format) +{ + (void)cchText; + return DrawState(hdc, NULL, ALF_Button_DrawDisabledText_DrawStateProc, + (LPARAM)lpchText, (WPARAM)format, + lprc->left, lprc->top, lprc->right - lprc->left, lprc->bottom - lprc->top, + DST_COMPLEX | DSS_DISABLED); +} + +static int +ALF_Button_DrawDisabledText9x(HDC hdc, + LPCTSTR lpchText, + int cchText, + LPRECT lprc, + UINT format) +{ + COLORREF oldcolor = SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); + int r = DrawText(hdc, lpchText, cchText, lprc, format); + SetTextColor(hdc, oldcolor); + return r; +} + +// FIXME! This is how NT 3.x dos it, need to figure out how to get the real 16bit look +static int +ALF_Button_DrawDisabledText31(HDC hdc, + LPCTSTR lpchText, + int cchText, + LPRECT lprc, + UINT format) +{ + COLORREF oldcolor = SetTextColor(hdc, GetSysColor(COLOR_BTNSHADOW)); + int r = DrawText(hdc, lpchText, cchText, lprc, format); + SetTextColor(hdc, oldcolor); + return r; +} + static ALFNtButtonPriv * ALF_NtButton_InitializePriv(void) @@ -156,19 +212,6 @@ ALF_NtButton_DefaultAnimatingTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, D } } -static BOOL CALLBACK -ALF_NtButton_Text_DrawStateProc(HDC hdc, LPARAM lData, WPARAM wData, int cx, int cy) -{ - int oldBkMode = SetBkMode(hdc, TRANSPARENT); - - RECT r = { 0, 0, cx, cy }; - DrawText(hdc, (TCHAR*)lData, -1, &r, (UINT)wData); - - SetBkMode(hdc, oldBkMode); - - return TRUE; -} - static void ALF_NtButton_RenderUxtheme(HWND hwnd, ALFNtButtonPriv *priv, int uxstate, DWORD drawFlags, HDC hDC, RECT *rcPaint) { @@ -271,34 +314,13 @@ ALF_NtButton_RenderClassic(HWND hwnd, ALFNtButtonPriv *priv, HDC dc, RECT *rcPai if (priv->drawFlags & ALF_NTBTN_FLAG_HIDEACCEL) style |= DT_HIDEPREFIX; + COLORREF oldBkColor = SetBkColor(dc, GetSysColor(COLOR_BTNFACE)); if (priv->drawFlags & ALF_NTBTN_FLAG_IS_DISABLED) { - 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 - COLORREF oldTextColor = SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT)); - - POINT oldorg = { 0, 0 }; - SetViewportOrgEx(dc, texttarget.left, texttarget.top, &oldorg); - ALF_NtButton_Text_DrawStateProc(dc, (LPARAM)textbuf, (WPARAM)style, - texttarget.right - texttarget.left, texttarget.bottom - texttarget.top); - SetViewportOrgEx(dc, oldorg.x, oldorg.y, NULL); - - SetTextColor(dc, oldTextColor); - } else { - DrawState(dc, NULL, ALF_NtButton_Text_DrawStateProc, - (LPARAM)textbuf, (WPARAM)style, - texttarget.left, texttarget.top, - texttarget.right - texttarget.left, texttarget.bottom - texttarget.top, - DST_COMPLEX | DSS_DISABLED); - } + ALF_Button_DrawDisabledText(dc, textbuf, -1, &texttarget, style); } else { - POINT oldorg = { 0, 0 }; - - SetViewportOrgEx(dc, texttarget.left, texttarget.top, &oldorg); - ALF_NtButton_Text_DrawStateProc(dc, (LPARAM)textbuf, (WPARAM)style, - texttarget.right - texttarget.left, texttarget.bottom - texttarget.top); - SetViewportOrgEx(dc, oldorg.x, oldorg.y, NULL); + DrawText(dc, textbuf, -1, &texttarget, style); } + SetBkColor(dc, oldBkColor); SelectFont(dc, oldfont); ALF_Free(textbuf); @@ -586,26 +608,38 @@ ALF_NtButton_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) void ALF_RegisterButtonClass(void) { - if (ALF_Compat_IsWin9x() || !ALF_Compat_IsMinWindowsVersion(4, 0)) - return; // use classic button on Win9x and NT 3.51 + // initialize helper function for disabled text + if (ALF_Compat_IsMinWindowsVersion(4, 0)) { + if (ALF_Compat_IsWin9x()) { + ALF_Button_DrawDisabledText = ALF_Button_DrawDisabledText9x; + } else { + ALF_Button_DrawDisabledText = ALF_Button_DrawDisabledTextNt; + } + } else { + ALF_Button_DrawDisabledText = ALF_Button_DrawDisabledText31; + } - WNDCLASS cls; - ZeroMemory(&cls, sizeof(cls)); + // Initialize custom themed button class on windows 2000 and newer + // Win9x and NT3.51/NT4 are well served by the classic version + if (ALF_Compat_IsMinWindowsVersion(5, 0)) { + WNDCLASS cls; + ZeroMemory(&cls, sizeof(cls)); - TCHAR classNameBuf[256]; - ALF_BuildUniqueName(classNameBuf, TEXT("ALFNtButton."), (ULONG_PTR)&_alf_buttonClass); + TCHAR classNameBuf[256]; + ALF_BuildUniqueName(classNameBuf, TEXT("ALFNtButton."), (ULONG_PTR)&_alf_buttonClass); - cls.hInstance = ALF_HINSTANCE; - cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW); - cls.lpszClassName = classNameBuf; - cls.cbWndExtra = sizeof(void*); - cls.lpfnWndProc = ALF_NtButton_WndProc; + cls.hInstance = ALF_HINSTANCE; + cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW); + cls.lpszClassName = classNameBuf; + cls.cbWndExtra = sizeof(void*); + cls.lpfnWndProc = ALF_NtButton_WndProc; - ATOM classatom = RegisterClass(&cls); - if (!classatom) - MessageBox(NULL, TEXT("FATAL: Could not register button class"), NULL, MB_OK); + ATOM classatom = RegisterClass(&cls); + if (!classatom) + MessageBox(NULL, TEXT("FATAL: Could not register button class"), NULL, MB_OK); - _alf_buttonClass = MAKEINTATOM(classatom); + _alf_buttonClass = MAKEINTATOM(classatom); + } } static HWND @@ -724,14 +758,7 @@ ALF_ClassicButton_Paint(HWND hwnd, ALFClassicButtonPriv *priv, DRAWITEMSTRUCT *d COLORREF oldBkColor = SetBkColor(dis->hDC, GetSysColor(COLOR_BTNFACE)); if (dis->itemState & ODS_DISABLED) { - // Win9x just uses gray text. DSS_DISABLED is broken there, too, - // so we can't get the NT look even if we wanted to - COLORREF disabledColor = ALF_Compat_IsMinWindowsVersion(4, 0) ? GetSysColor(COLOR_GRAYTEXT) : GetSysColor(COLOR_BTNSHADOW); - COLORREF oldTextColor = SetTextColor(dis->hDC, disabledColor); - - DrawText(dis->hDC, textbuf, -1, &texttarget, style); - - SetTextColor(dis->hDC, oldTextColor); + ALF_Button_DrawDisabledText(dis->hDC, textbuf, -1, &texttarget, style); } else { COLORREF oldTextColor = SetTextColor(dis->hDC, GetSysColor(COLOR_BTNTEXT)); |
