summaryrefslogtreecommitdiff
path: root/alf
diff options
context:
space:
mode:
Diffstat (limited to 'alf')
-rw-r--r--alf/alfbutton.cpp6
-rw-r--r--alf/alfcombobox.cpp4
-rw-r--r--alf/alfcompat.cpp40
-rw-r--r--alf/alfcompat.h65
-rw-r--r--alf/alfedit.cpp2
-rw-r--r--alf/alflayout.cpp4
6 files changed, 86 insertions, 35 deletions
diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp
index 3c3e940..abdf162 100644
--- a/alf/alfbutton.cpp
+++ b/alf/alfbutton.cpp
@@ -1388,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_Compat_IsMinWindowsVersion(5, 0)) {
+ if (ALF_Compat_Is2k()) {
return ALF_NtButton_Create(win, id, x, y, text, WS_TABSTOP);
} else {
return ALF_ClassicButton_Create(win, id, x, y, text, 0);
@@ -1398,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_Compat_IsMinWindowsVersion(5, 0)) {
+ if (ALF_Compat_Is2k()) {
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);
@@ -1408,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_Compat_IsMinWindowsVersion(5, 0)) {
+ if (ALF_Compat_Is2k()) {
return ALF_NtButton_Create(parent, id, x, y, text, BS_AUTORADIOBUTTON);
} else {
return ALF_ClassicButton_Create(parent, id, x, y, text, BS_AUTORADIOBUTTON);
diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp
index 5350a2a..349bd40 100644
--- a/alf/alfcombobox.cpp
+++ b/alf/alfcombobox.cpp
@@ -252,7 +252,7 @@ ALF_Combo_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
SendMessage(priv->hwndChild, CB_SETEDITSEL, 0, (LPARAM)sel);
int heightOffset = 0;
- if (ALF_Compat_IsMinWindowsVersion(4, 0)) {
+ if (ALF_Compat_Is40()) {
heightOffset = - 2*ALF_Compat_GetSystemMetricsForDpi(
SM_CYEDGE, (UINT)priv->dpi)
- 2;
@@ -284,7 +284,7 @@ ALF_Combo_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return TRUE;
}
- if (!ALF_Compat_IsMinWindowsVersion(4, 0)) {
+ if (!ALF_Compat_Is40()) {
// HACK to draw the space between edit control and button as COLOR_BTNFACE
if (uMsg == WM_CTLCOLORLISTBOX && priv && !(GetWindowLong(priv->hwndChild, GWL_STYLE) & 1)) {
SetTextColor((HDC)wParam, GetSysColor(COLOR_BTNTEXT));
diff --git a/alf/alfcompat.cpp b/alf/alfcompat.cpp
index 12a79f4..b986ee8 100644
--- a/alf/alfcompat.cpp
+++ b/alf/alfcompat.cpp
@@ -2,6 +2,8 @@
#include <shlwapi.h>
+DWORD _alf_compatBits = 0;
+
static
DWORD ALF_DllGetVersion(const char *dll)
{
@@ -32,7 +34,7 @@ static int WINAPI
ALF_Compat_fallbackGetSystemMetricsForDpi(int nIndex, UINT dpi)
{
(void)dpi;
- if (!ALF_Compat_IsMinWindowsVersion(4, 0)) {
+ if (!ALF_Compat_Is40()) {
// old NT does not support several properties, so we fake them
switch (nIndex) {
case SM_CXEDGE:
@@ -84,7 +86,7 @@ ALF_Compat_fallbackSystemParametersInfoForDpi(UINT uiAction, UINT uiParam, PVOID
// we need to provide a fallback even on ANSI systems
#ifdef UNICODE
SIZE_T s = sizeof(*ncmw);
- if (!ALF_Compat_IsMinWindowsVersion(6, 0)) {
+ if (!ALF_Compat_IsVista()) {
// pre-vista OS doesn't contain last member
s -= sizeof(ncmw->iPaddedBorderWidth);
ncmw->iPaddedBorderWidth = 0;
@@ -97,7 +99,7 @@ ALF_Compat_fallbackSystemParametersInfoForDpi(UINT uiAction, UINT uiParam, PVOID
ZeroMemory(&ncma, sizeof(ncma));
SIZE_T s = sizeof(ncma);
- if (!ALF_Compat_IsMinWindowsVersion(6, 0)) {
+ if (!ALF_Compat_IsVista()) {
// pre-vista OS doesn't contain last member
s -= sizeof(ncma.iPaddedBorderWidth);
ncma.iPaddedBorderWidth = 0;
@@ -428,17 +430,39 @@ static HMODULE _alf_dll_comctl32 = NULL;
void ALF_LoadCompatFunctions(void)
{
- if (ALF_Compat_IsWinNT()) // don't attempt to load uxtheme.dll on non-NT platforms (ugly error on Win32s)
+ // setup compat bits
+ DWORD v = GetVersion();
+ DWORD vMajor = LOBYTE(LOWORD(v));
+ DWORD vMinor = HIBYTE(LOWORD(v));
+
+ if (v < 0x80000000)
+ _alf_compatBits |= ALF_COMPAT_ISNT;
+
+ if (vMajor >= 4)
+ _alf_compatBits |= ALF_COMPAT_IS40;
+
+ if (vMajor >= 5)
+ _alf_compatBits |= ALF_COMPAT_ISW2K;
+
+ if (vMajor > 5 || (vMajor == 5 && vMinor >= 1))
+ _alf_compatBits |= ALF_COMPAT_ISXP;
+
+ if (vMajor >= 6)
+ _alf_compatBits |= ALF_COMPAT_ISVISTA;
+
+ // load compat functions
+ if (ALF_Compat_IsXP()) // don't even attempt to load uxtheme.dll on non-XP
_alf_dll_uxtheme = LoadLibraryA("uxtheme.dll");
_alf_dll_user32 = LoadLibraryA("user32.dll");
_alf_dll_comctl32 = LoadLibraryA("comctl32.dll");
-
- if (ALF_DllGetVersion("comctl32.dll") >= 0x60000)
+ if (ALF_DllGetVersion("comctl32.dll") >= 0x60000) {
+ _alf_compatBits |= ALF_COMPAT_ISCOMCTLV6;
LOAD_FUNC(uxtheme, IsAppThemed);
- else
+ } else {
ALF_Compat_IsAppThemed = ALF_Compat_fallbackIsAppThemed;
+ }
LOAD_FUNC(user32, GetDpiForWindow);
LOAD_FUNC(user32, AdjustWindowRectExForDpi);
@@ -467,7 +491,7 @@ void ALF_LoadCompatFunctions(void)
LOAD_FUNC(uxtheme, GetThemeColor);
// initialize helper function for disabled text
- if (ALF_Compat_IsMinWindowsVersion(4, 0)) {
+ if (ALF_Compat_Is40()) {
if (GetSystemMetrics(SM_SLOWMACHINE)) {
ALF_Compat_DrawDisabledText = ALF_Compat_DrawDisabledTextSolid;
} else {
diff --git a/alf/alfcompat.h b/alf/alfcompat.h
index 8186492..eeb70da 100644
--- a/alf/alfcompat.h
+++ b/alf/alfcompat.h
@@ -15,25 +15,6 @@ extern IMAGE_DOS_HEADER __ImageBase;
#endif
#define ALF_HINSTANCE ((HINSTANCE)&__ImageBase)
-static inline BOOL ALF_Compat_IsMinWindowsVersion(DWORD major, DWORD minor)
-{
- DWORD v = GetVersion();
- DWORD vMajor = LOBYTE(LOWORD(v));
- DWORD vMinor = HIBYTE(LOWORD(v));
-
- return vMajor > major || (vMajor == major && vMinor >= minor);
-}
-
-static inline BOOL ALF_Compat_IsWin9x(void)
-{
- return GetVersion() >= 0x80000000;
-}
-
-static inline BOOL ALF_Compat_IsWinNT(void)
-{
- return GetVersion() < 0x80000000;
-}
-
typedef struct {
UINT cbSize;
int iBorderWidth;
@@ -144,3 +125,49 @@ extern HRESULT (WINAPI *ALF_Compat_EndBufferedAnimation)(ALF_Compat_HANIMATIONBU
extern BOOL (WINAPI *ALF_Compat_BufferedPaintRenderAnimation)(HWND,HDC);
extern HRESULT (WINAPI *ALF_Compat_GetThemeTransitionDuration)(HTHEME,int,int,int,int,DWORD*);
extern HRESULT (WINAPI *ALF_Compat_GetThemeColor)(HTHEME,int,int,int,COLORREF*);
+
+// compatibility bits
+
+#define ALF_COMPAT_ISNT 1
+#define ALF_COMPAT_IS40 2
+#define ALF_COMPAT_ISW2K 4
+#define ALF_COMPAT_ISXP 8
+#define ALF_COMPAT_ISVISTA 16
+#define ALF_COMPAT_ISCOMCTLV6 32
+
+extern DWORD _alf_compatBits;
+
+static inline BOOL ALF_Compat_IsWin9x(void)
+{
+ return !(_alf_compatBits & ALF_COMPAT_ISNT);
+}
+
+static inline BOOL ALF_Compat_IsNT(void)
+{
+ return !!(_alf_compatBits & ALF_COMPAT_ISNT);
+}
+
+static inline BOOL ALF_Compat_Is40(void) // both NT 4.0 and Win95
+{
+ return !!(_alf_compatBits & ALF_COMPAT_IS40);
+}
+
+static inline BOOL ALF_Compat_Is2k(void)
+{
+ return !!(_alf_compatBits & ALF_COMPAT_ISW2K);
+}
+
+static inline BOOL ALF_Compat_IsXP(void)
+{
+ return !!(_alf_compatBits & ALF_COMPAT_ISXP);
+}
+
+static inline BOOL ALF_Compat_IsVista(void)
+{
+ return !!(_alf_compatBits & ALF_COMPAT_ISVISTA);
+}
+
+static inline BOOL ALF_Compat_IsComCtlV6(void)
+{
+ return !!(_alf_compatBits & ALF_COMPAT_ISCOMCTLV6);
+}
diff --git a/alf/alfedit.cpp b/alf/alfedit.cpp
index cf47d23..645cb97 100644
--- a/alf/alfedit.cpp
+++ b/alf/alfedit.cpp
@@ -8,7 +8,7 @@ ALF_AddEdit(HWND win, WORD id, int x, int y, const TCHAR *text)
DWORD exstyle;
DWORD style;
- if (ALF_Compat_IsMinWindowsVersion(4, 0)) {
+ if (ALF_Compat_Is40()) {
exstyle = WS_EX_CLIENTEDGE;
style = 0;
} else {
diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp
index 6f35345..745b303 100644
--- a/alf/alflayout.cpp
+++ b/alf/alflayout.cpp
@@ -231,7 +231,7 @@ ALF_Layout_CalcCheckboxSize(HWND hwndWindow, ALFLayout *layout, HWND hwndCheckbo
int checkwidth = 12 * layout->dpi / 96 + 1;
int checkheight = checkwidth;
- if (!ALF_Compat_IsMinWindowsVersion(4, 0)) {
+ if (!ALF_Compat_Is40()) {
// 3.x-style checkboxes have the checkmark baseline-aligned
TEXTMETRIC tm;
ZeroMemory(&tm, sizeof(tm));
@@ -624,7 +624,7 @@ ALF_Layout_Apply(ALFLayout* layout, HWND window)
UINT flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER;
// NT 3.51 and Win32s have so many invalidation bugs it's not even funny
- if (!ALF_Compat_IsMinWindowsVersion(4, 0))
+ if (!ALF_Compat_Is40())
flags |= SWP_NOCOPYBITS;
// transparent background: invalidate if control moved