summaryrefslogtreecommitdiff
path: root/alf/alfcompat.h
blob: 8acdbc6240f7624b695c0e490e251e337d3a742f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#pragma once

#include <windows.h>
#include <rpc.h>
#include <uxtheme.h>

#ifndef WM_DPICHANGED
#define WM_DPICHANGED       0x02E0
#endif

#ifdef __cplusplus
extern "C" IMAGE_DOS_HEADER __ImageBase;
#else
extern IMAGE_DOS_HEADER __ImageBase;
#endif
#define ALF_HINSTANCE ((HINSTANCE)&__ImageBase)

typedef struct {
    UINT     cbSize;
    int      iBorderWidth;
    int      iScrollWidth;
    int      iScrollHeight;
    int      iCaptionWidth;
    int      iCaptionHeight;
    LOGFONTW lfCaptionFont;
    int      iSmCaptionWidth;
    int      iSmCaptionHeight;
    LOGFONTW lfSmCaptionFont;
    int      iMenuWidth;
    int      iMenuHeight;
    LOGFONTW lfMenuFont;
    LOGFONTW lfStatusFont;
    LOGFONTW lfMessageFont;
    int      iPaddedBorderWidth; // new in Vista
} ALF_NONCLIENTMETRICSW_VISTA;
typedef struct {
    UINT     cbSize;
    int      iBorderWidth;
    int      iScrollWidth;
    int      iScrollHeight;
    int      iCaptionWidth;
    int      iCaptionHeight;
    LOGFONTA lfCaptionFont;
    int      iSmCaptionWidth;
    int      iSmCaptionHeight;
    LOGFONTA lfSmCaptionFont;
    int      iMenuWidth;
    int      iMenuHeight;
    LOGFONTA lfMenuFont;
    LOGFONTA lfStatusFont;
    LOGFONTA lfMessageFont;
    int      iPaddedBorderWidth; // new in Vista
} ALF_NONCLIENTMETRICSA_VISTA;

long
ALF_GetAveCharWidth(HDC hdc);

typedef void *ALF_Compat_HANIMATIONBUFFER;
typedef void *ALF_Compat_HPAINTBUFFER;

typedef enum {
  ALF_Compat_BPAS_NONE,
  ALF_Compat_BPAS_LINEAR,
  ALF_Compat_BPAS_CUBIC,
  ALF_Compat_BPAS_SINE
} ALF_Compat_BP_ANIMATIONSTYLE;

typedef struct {
  DWORD                         cbSize;
  DWORD                         dwFlags;
  ALF_Compat_BP_ANIMATIONSTYLE  style;
  DWORD                         dwDuration;
} ALF_Compat_BP_ANIMATIONPARAMS;

typedef struct {
  DWORD               cbSize;
  DWORD               dwFlags;
  const RECT          *prcExclude;
  const BLENDFUNCTION *pBlendFunction;
} ALF_Compat_BP_PAINTPARAMS;

typedef struct {
    int cxLeftWidth;
    int cxRightWidth;
    int cyTopHeight;
    int cyBottomHeight;
} ALF_Compat_MARGINS;


#ifndef TMT_TRANSITIONDURATION
#define TMT_TRANSITIONDURATION 6000
#endif

void ALF_LoadCompatFunctions(void);
void ALF_UnloadCompatFunctions(void);

inline static void
ALF_Compat_LogFontWtoA(const LOGFONTW *w, LOGFONTA *a)
{
    CopyMemory(a, w, sizeof(LOGFONTA) - LF_FACESIZE);
    WideCharToMultiByte(CP_ACP, 0, w->lfFaceName, -1, a->lfFaceName, LF_FACESIZE, NULL, NULL);
    a->lfFaceName[LF_FACESIZE - 1] = '\0';
}

inline static void
ALF_Compat_LogFontAtoW(const LOGFONTA *a, LOGFONTW *w)
{
    CopyMemory(w, a, sizeof(LOGFONTA) - LF_FACESIZE);
    MultiByteToWideChar(CP_ACP, 0, a->lfFaceName, -1, w->lfFaceName, LF_FACESIZE);
    w->lfFaceName[LF_FACESIZE - 1] = 0;
}

extern int (*ALF_Compat_DrawDisabledText)(HDC,LPCTSTR,int,LPRECT,UINT);

extern BOOL (WINAPI *ALF_Compat_IsAppThemed)(void);
extern UINT (WINAPI *ALF_Compat_GetDpiForWindow)(HWND);
extern BOOL (WINAPI *ALF_Compat_AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT);
extern int (WINAPI *ALF_Compat_GetSystemMetricsForDpi)(int,  UINT);
extern BOOL (WINAPI *ALF_Compat_SystemParametersInfoForDpi)(UINT,UINT,PVOID,UINT,UINT);
extern HTHEME (WINAPI *ALF_Compat_OpenThemeData)(HWND, LPCWSTR);
extern HRESULT (WINAPI *ALF_Compat_CloseThemeData)(HTHEME);
extern BOOL (WINAPI *ALF_Compat_IsThemeBackgroundPartiallyTransparent)(HTHEME,int,int);
extern HRESULT (WINAPI *ALF_Compat_DrawThemeParentBackground)(HWND,HDC,RECT *);
extern HRESULT (WINAPI *ALF_Compat_DrawThemeBackground)(HTHEME, HDC, int, int, const RECT *, const RECT *);
extern HRESULT (WINAPI *ALF_Compat_GetThemeBackgroundContentRect)(HTHEME,HDC,int,int,const RECT *,RECT *);
extern HRESULT (WINAPI *ALF_Compat_GetThemeTextExtent)(HTHEME,HDC,int,int,LPCWSTR,int,DWORD,const RECT *, RECT *);
extern HRESULT (WINAPI *ALF_Compat_DrawThemeText)(HTHEME,HDC,int,int,LPCWSTR,int,DWORD,DWORD,const RECT *);
extern HRESULT (WINAPI *ALF_Compat_GetThemePartSize)(HTHEME,HDC,int,int,RECT *,THEMESIZE,SIZE *);
extern BOOL (WINAPI *ALF_Compat_TrackMouseEvent)(LPTRACKMOUSEEVENT tme);
extern HRESULT (WINAPI *ALF_Compat_BufferedPaintInit)(void);
extern HRESULT (WINAPI *ALF_Compat_BufferedPaintUnInit)(void);
extern ALF_Compat_HANIMATIONBUFFER (WINAPI *ALF_Compat_BeginBufferedAnimation)(HWND,HDC,const RECT *,DWORD,ALF_Compat_BP_PAINTPARAMS *,ALF_Compat_BP_ANIMATIONPARAMS *,HDC *,HDC *);
extern ALF_Compat_HPAINTBUFFER (WINAPI *ALF_Compat_BeginBufferedPaint)(HDC,const RECT *,DWORD,ALF_Compat_BP_PAINTPARAMS *,HDC *);
extern HRESULT (WINAPI *ALF_Compat_EndBufferedAnimation)(ALF_Compat_HANIMATIONBUFFER,BOOL);
extern HRESULT (WINAPI *ALF_Compat_EndBufferedPaint)(ALF_Compat_HPAINTBUFFER,BOOL);
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*);
extern HRESULT (WINAPI *ALF_Compat_GetThemeMargins)(HTHEME,HDC,int,int,int,const RECT *,MARGINS *);
extern HRESULT (WINAPI *ALF_Compat_LoadIconWithScaleDown)(HINSTANCE,PCWSTR,int,int,HICON *);
extern BOOL (WINAPI *ALF_Compat_GetMonitorInfoA)(HMONITOR,MONITORINFO *);
extern HMONITOR (WINAPI *ALF_Compat_MonitorFromPoint)(POINT,DWORD);
extern HMONITOR (WINAPI *ALF_Compat_MonitorFromWindow)(HWND,DWORD);

// 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);
}