diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-05-29 23:43:00 +0200 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2020-05-29 23:43:00 +0200 |
| commit | c9ebff8e7de093e7705aab6208593fae048ad98d (patch) | |
| tree | 06f641c182e4013e95c7fa1f255e4adbd32a67f2 /alf/alfbutton.cpp | |
| parent | 46326d57e0c912f265595ffed375d211bbe23f44 (diff) | |
controls: subclass generic "ALFControl" window
The idea is that the compiler can strip unused controls when linking
statically, but the window class initialization functions blocked that.
Diffstat (limited to 'alf/alfbutton.cpp')
| -rw-r--r-- | alf/alfbutton.cpp | 129 |
1 files changed, 25 insertions, 104 deletions
diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp index f41b0b5..6d7d319 100644 --- a/alf/alfbutton.cpp +++ b/alf/alfbutton.cpp @@ -64,21 +64,6 @@ typedef struct { ALFColor bgcolor; } 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 BOOL CALLBACK ALF_Button_DrawDisabledTextW_DrawStateProc(HDC hdc, LPARAM lData, @@ -92,20 +77,6 @@ ALF_Button_DrawDisabledTextW_DrawStateProc(HDC hdc, } 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_DrawDisabledTextNtW(HDC hdc, LPCWSTR lpchText, int cchText, @@ -119,33 +90,6 @@ ALF_Button_DrawDisabledTextNtW(HDC hdc, 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; -} - // FIXME! this doesn’t really look correct static int ALF_Button_CalcCheckboxTextSpace(HDC hdc) @@ -996,55 +940,32 @@ ALF_NtButton_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return DefWindowProcW(hwnd, uMsg, wParam, lParam); } -void -ALF_RegisterButtonClass(void) -{ - // 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; - } - - // 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)) { - WNDCLASSW cls; - ZeroMemory(&cls, sizeof(cls)); - - WCHAR classNameBuf[256]; - ALF_BuildUniqueNameW(classNameBuf, L"ALFNtButton.", (ULONG_PTR)&_alf_buttonClass); +#ifdef UNICODE +# define ALF_NtButton_WndProcStart ALF_NtButton_WndProc +#else - 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 = RegisterClassW(&cls); - if (!classatom) - MessageBox(NULL, TEXT("FATAL: Could not register button class"), NULL, MB_OK); - - _alf_buttonClass = MAKEINTATOM(classatom); - } +// HACK to get a unicode window +static LRESULT CALLBACK +ALF_NtButton_WndProcStart(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) +{ + SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ALF_NtButton_WndProc); + WNDPROC thunk = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_WNDPROC); + return CallWindowProc(thunk, hwnd, msg, wparam, lparam); } +#endif + static HWND ALF_NtButton_Create(HWND win, WORD id, int x, int y, const TCHAR *text, DWORD addstyle) { - HWND hwndButton = CreateWindowEx(0, - _alf_buttonClass, - text, - WS_CHILD | WS_VISIBLE | addstyle, - 0, 0, 100, 100, - win, - (HMENU)(ULONG_PTR)id, - ALF_HINSTANCE, - NULL); + HWND hwndButton = ALF_CreateControlWindow(0, + text, + WS_CHILD | WS_VISIBLE | addstyle, + 0, 0, 100, 100, + win, + (HMENU)(ULONG_PTR)id, + ALF_NtButton_WndProcStart, + NULL); int minwidth = 5625; int minheight = 1725; @@ -1211,7 +1132,7 @@ ALF_ClassicButton_PaintCheckbox(HWND hwnd, ALFClassicButtonPriv *priv, DRAWITEMS COLORREF oldBkColor = SetBkColor(dis->hDC, GetSysColor(COLOR_BTNFACE)); if (dis->itemState & ODS_DISABLED) { - ALF_Button_DrawDisabledText(dis->hDC, textbuf, -1, &texttarget, style); + ALF_Compat_DrawDisabledText(dis->hDC, textbuf, -1, &texttarget, style); } else { DrawText(dis->hDC, textbuf, -1, &texttarget, style); } @@ -1270,7 +1191,7 @@ ALF_ClassicButton_PaintButton(HWND hwnd, ALFClassicButtonPriv *priv, DRAWITEMSTR COLORREF oldBkColor = SetBkColor(dis->hDC, GetSysColor(COLOR_BTNFACE)); if (dis->itemState & ODS_DISABLED) { - ALF_Button_DrawDisabledText(dis->hDC, textbuf, -1, &texttarget, style); + ALF_Compat_DrawDisabledText(dis->hDC, textbuf, -1, &texttarget, style); } else { COLORREF oldTextColor = SetTextColor(dis->hDC, GetSysColor(COLOR_BTNTEXT)); @@ -1467,7 +1388,7 @@ ALF_ClassicButton_Create(HWND win, WORD id, int x, int y, const TCHAR *text, DWO HWND ALF_AddButton(HWND win, WORD id, int x, int y, const TCHAR *text) { - if (_alf_buttonClass) { + if (ALF_Compat_IsMinWindowsVersion(5, 0)) { return ALF_NtButton_Create(win, id, x, y, text, WS_TABSTOP); } else { return ALF_ClassicButton_Create(win, id, x, y, text, 0); @@ -1477,7 +1398,7 @@ ALF_AddButton(HWND win, WORD id, int x, int y, const TCHAR *text) HWND ALF_AddCheckbox(HWND win, WORD id, int x, int y, const TCHAR *text) { - if (_alf_buttonClass) { + if (ALF_Compat_IsMinWindowsVersion(5, 0)) { return ALF_NtButton_Create(win, id, x, y, text, WS_TABSTOP | BS_AUTOCHECKBOX); } else { return ALF_ClassicButton_Create(win, id, x, y, text, BS_AUTOCHECKBOX); @@ -1487,7 +1408,7 @@ ALF_AddCheckbox(HWND win, WORD id, int x, int y, const TCHAR *text) HWND ALF_AddRadioButton(HWND parent, WORD id, int x, int y, const TCHAR *text) { - if (_alf_buttonClass) { + if (ALF_Compat_IsMinWindowsVersion(5, 0)) { return ALF_NtButton_Create(parent, id, x, y, text, BS_AUTORADIOBUTTON); } else { return ALF_ClassicButton_Create(parent, id, x, y, text, BS_AUTORADIOBUTTON); |
