xref: /reactos/dll/win32/uxtheme/uxthemep.h (revision d11582f0)
1 #ifndef _UXTHEME_PCH_
2 #define _UXTHEME_PCH_
3 
4 #include <stdarg.h>
5 
6 #include "resource.h"
7 
8 #define WIN32_NO_STATUS
9 #define _INC_WINDOWS
10 #define COM_NO_WINDOWS_H
11 
12 #include <windef.h>
13 #include <winbase.h>
14 #include <wingdi.h>
15 #include <winuser.h>
16 #include <winnls.h>
17 #include <windowsx.h>
18 #include <undocuser.h>
19 #include <undocgdi.h>
20 #include <uxtheme.h>
21 #include <uxundoc.h>
22 #include <vfwmsgs.h>
23 #include <tmschema.h>
24 
25 #define NTOS_MODE_USER
26 #include <ndk/ntndk.h>
27 #include <ndk/rtltypes.h>
28 
29 #include <wine/debug.h>
30 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
31 
32 #define TMT_ENUM 200
33 
34 #define MAX_THEME_APP_NAME 60
35 #define MAX_THEME_CLASS_NAME 60
36 #define MAX_THEME_VALUE_NAME 60
37 
38 typedef struct _THEME_PROPERTY {
39     int iPrimitiveType;
40     int iPropertyId;
41     PROPERTYORIGIN origin;
42 
43     LPCWSTR lpValue;
44     DWORD dwValueLen;
45 
46     struct _THEME_PROPERTY *next;
47 } THEME_PROPERTY, *PTHEME_PROPERTY;
48 
49 typedef struct _THEME_PARTSTATE {
50     int iPartId;
51     int iStateId;
52     PTHEME_PROPERTY properties;
53 
54     struct _THEME_PARTSTATE *next;
55 } THEME_PARTSTATE, *PTHEME_PARTSTATE;
56 
57 struct _THEME_FILE;
58 
59 typedef struct _THEME_CLASS {
60     HMODULE hTheme;
61     struct _THEME_FILE* tf;
62     WCHAR szAppName[MAX_THEME_APP_NAME];
63     WCHAR szClassName[MAX_THEME_CLASS_NAME];
64     PTHEME_PARTSTATE partstate;
65     struct _THEME_CLASS *overrides;
66 
67     struct _THEME_CLASS *next;
68 } THEME_CLASS, *PTHEME_CLASS;
69 
70 typedef struct _THEME_IMAGE {
71     WCHAR name[MAX_PATH];
72     HBITMAP image;
73     BOOL hasAlpha;
74 
75     struct _THEME_IMAGE *next;
76 } THEME_IMAGE, *PTHEME_IMAGE;
77 
78 typedef struct _THEME_FILE {
79     DWORD dwRefCount;
80     HMODULE hTheme;
81     WCHAR szThemeFile[MAX_PATH];
82     LPWSTR pszAvailColors;
83     LPWSTR pszAvailSizes;
84 
85     LPWSTR pszSelectedColor;
86     LPWSTR pszSelectedSize;
87 
88     PTHEME_CLASS classes;
89     PTHEME_PROPERTY metrics;
90     PTHEME_IMAGE images;
91 } THEME_FILE, *PTHEME_FILE;
92 
93 typedef struct _UXINI_FILE *PUXINI_FILE;
94 
95 typedef struct _UXTHEME_HANDLE
96 {
97     RTL_HANDLE_TABLE_ENTRY Handle;
98     PTHEME_CLASS pClass;
99 } UXTHEME_HANDLE, *PUXTHEME_HANDLE;
100 
101 PTHEME_CLASS ValidateHandle(HTHEME hTheme);
102 
103 HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph,
104                           HBITMAP *hBmp, RECT *bmpRect, BOOL* hasImageAlpha);
105 
106 BOOL MSSTYLES_LookupProperty(LPCWSTR pszPropertyName, int *dwPrimitive, int *dwId);
107 BOOL MSSTYLES_LookupEnum(LPCWSTR pszValueName, int dwEnum, int *dwValue);
108 BOOL MSSTYLES_LookupPartState(LPCWSTR pszClass, LPCWSTR pszPart, LPCWSTR pszState, int *iPartId, int *iStateId);
109 
110 HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWSTR pszSizeName, PTHEME_FILE *tf);
111 HRESULT MSSTYLES_ReferenceTheme(PTHEME_FILE tf);
112 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf);
113 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf);
114 PTHEME_CLASS MSSTYLES_OpenThemeClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassList);
115 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc);
116 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf);
117 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext);
118 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId);
119 PTHEME_PROPERTY MSSTYLES_FindMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId);
120 #ifdef ENABLE_PNG_SUPPORT
121 EXTERN_C
122 BOOL
123 MSSTYLES_TryLoadPng(
124     _In_ HINSTANCE hTheme,
125     _In_ LPCWSTR szFile,
126     _In_ LPCWSTR type,
127     _Out_ HBITMAP *phBitmap);
128 EXTERN_C
129 BOOL
130 prepare_png_alpha(
131     _In_ HBITMAP png,
132     _Out_ BOOL* hasAlpha);
133 #endif /* ENABLE_PNG_SUPPORT */
134 HBITMAP MSSTYLES_LoadBitmap(PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha);
135 
136 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal);
137 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor);
138 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont);
139 HRESULT MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp, int *piVal);
140 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList);
141 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint);
142 HRESULT MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp, LPWSTR pszBuff, int cchMaxBuffChars);
143 HRESULT MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp, RECT *pRect);
144 HRESULT MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp, RECT *prc, MARGINS *pMargins);
145 
146 PUXINI_FILE UXINI_LoadINI(HMODULE hTheme, LPCWSTR lpName);
147 void UXINI_CloseINI(PUXINI_FILE uf);
148 LPCWSTR UXINI_GetNextSection(PUXINI_FILE uf, DWORD *dwLen);
149 BOOL UXINI_FindSection(PUXINI_FILE uf, LPCWSTR lpName);
150 LPCWSTR UXINI_GetNextValue(PUXINI_FILE uf, DWORD *dwNameLen, LPCWSTR *lpValue, DWORD *dwValueLen);
151 BOOL UXINI_FindValue(PUXINI_FILE uf, LPCWSTR lpName, LPCWSTR *lpValue, DWORD *dwValueLen);
152 
153   /* Scroll-bar hit testing */
154 enum SCROLL_HITTEST
155 {
156     SCROLL_NOWHERE,      /* Outside the scroll bar */
157     SCROLL_TOP_ARROW,    /* Top or left arrow */
158     SCROLL_TOP_RECT,     /* Rectangle between the top arrow and the thumb */
159     SCROLL_THUMB,        /* Thumb rectangle */
160     SCROLL_BOTTOM_RECT,  /* Rectangle between the thumb and the bottom arrow */
161     SCROLL_BOTTOM_ARROW  /* Bottom or right arrow */
162 };
163 
164 /* The window context stores data for the window needed through the life of the window */
165 typedef struct _WND_DATA
166 {
167     HTHEME hthemeWindow;
168     HTHEME hthemeScrollbar;
169 
170     RECT rcCaptionButtons[4];
171     UINT lastHitTest;
172     BOOL HasAppDefinedRgn;
173     BOOL HasThemeRgn;
174     BOOL UpdatingRgn;
175     BOOL DirtyThemeRegion;
176     HBRUSH hTabBackgroundBrush;
177     HBITMAP hTabBackgroundBmp;
178 
179     BOOL SCROLL_trackVertical;
180     enum SCROLL_HITTEST SCROLL_trackHitTest;
181     BOOL SCROLL_MovingThumb;  /* Is the moving thumb being displayed? */
182     HWND SCROLL_TrackingWin;
183     INT  SCROLL_TrackingBar;
184     INT  SCROLL_TrackingPos;
185     INT  SCROLL_TrackingVal;
186 } WND_DATA, *PWND_DATA;
187 
188 /* The draw context stores data that are needed by the drawing operations in the non client area of the window */
189 typedef struct _DRAW_CONTEXT
190 {
191     HWND hWnd;
192     HDC hDC;
193     HTHEME theme;
194     HTHEME scrolltheme;
195     HTHEME hPrevTheme;
196     WINDOWINFO wi;
197     BOOL Active; /* wi.dwWindowStatus isn't correct for mdi child windows */
198     HRGN hRgn;
199     int CaptionHeight;
200 
201     /* for double buffering */
202     HDC hDCScreen;
203     HBITMAP hbmpOld;
204 } DRAW_CONTEXT, *PDRAW_CONTEXT;
205 
206 typedef enum
207 {
208     CLOSEBUTTON,
209     MAXBUTTON,
210     MINBUTTON,
211     HELPBUTTON
212 } CAPTIONBUTTON;
213 
214 /*
215 The following values specify all possible button states
216 Note that not all of them are documented but it is easy to
217 find them by opening a theme file
218 */
219 typedef enum {
220     BUTTON_NORMAL = 1 ,
221     BUTTON_HOT ,
222     BUTTON_PRESSED ,
223     BUTTON_DISABLED ,
224     BUTTON_INACTIVE ,
225     BUTTON_INACTIVE_HOT ,
226     BUTTON_INACTIVE_PRESSED ,
227     BUTTON_INACTIVE_DISABLED
228 } THEME_BUTTON_STATES;
229 
230 #define HT_ISBUTTON(ht) ((ht) == HTMINBUTTON || (ht) == HTMAXBUTTON || (ht) == HTCLOSE || (ht) == HTHELP)
231 
232 #define HASSIZEGRIP(Style, ExStyle, ParentStyle, WindowRect, ParentClientRect) \
233             ((!(Style & WS_CHILD) && (Style & WS_THICKFRAME) && !(Style & WS_MAXIMIZE))  || \
234              ((Style & WS_CHILD) && (ParentStyle & WS_THICKFRAME) && !(ParentStyle & WS_MAXIMIZE) && \
235              (WindowRect.right - WindowRect.left == ParentClientRect.right) && \
236              (WindowRect.bottom - WindowRect.top == ParentClientRect.bottom)))
237 
238 #define HAS_MENU(hwnd,style)  ((((style) & (WS_CHILD | WS_POPUP)) != WS_CHILD) && GetMenu(hwnd))
239 
240 #define BUTTON_GAP_SIZE 2
241 
242 #define MENU_BAR_ITEMS_SPACE (12)
243 
244 #define SCROLL_TIMER   0                /* Scroll timer id */
245 
246   /* Overlap between arrows and thumb */
247 #define SCROLL_ARROW_THUMB_OVERLAP 0
248 
249   /* Delay (in ms) before first repetition when holding the button down */
250 #define SCROLL_FIRST_DELAY   200
251 
252   /* Delay (in ms) between scroll repetitions */
253 #define SCROLL_REPEAT_DELAY  50
254 
255 /* Minimum size of the thumb in pixels */
256 #define SCROLL_MIN_THUMB 6
257 
258 /* Minimum size of the rectangle between the arrows */
259 #define SCROLL_MIN_RECT  4
260 
261 LRESULT CALLBACK ThemeWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, WNDPROC DefWndProc);
262 void ThemeCalculateCaptionButtonsPos(HWND hWnd, HTHEME htheme);
263 LONG SCROLL_getObjectId(INT nBar);
264 void ThemeDrawScrollBarEx(PDRAW_CONTEXT pcontext, INT nBar, PSCROLLBARINFO psbi, POINT* pt);
265 void ThemeDrawScrollBar(PDRAW_CONTEXT pcontext, INT Bar, POINT* pt);
266 VOID NC_TrackScrollBar(HWND Wnd, WPARAM wParam, POINT Pt);
267 void ThemeInitDrawContext(PDRAW_CONTEXT pcontext, HWND hWnd, HRGN hRgn);
268 void ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext);
269 PWND_DATA ThemeGetWndData(HWND hWnd);
270 HTHEME GetNCCaptionTheme(HWND hWnd, DWORD style);
271 HTHEME GetNCScrollbarTheme(HWND hWnd, DWORD style);
272 
273 extern HINSTANCE hDllInst;
274 extern ATOM atWindowTheme;
275 extern ATOM atWndContext;
276 extern BOOL g_bThemeHooksActive;
277 
278 void UXTHEME_InitSystem(HINSTANCE hInst);
279 void UXTHEME_LoadTheme(BOOL bLoad);
280 BOOL CALLBACK UXTHEME_broadcast_theme_changed (HWND hWnd, LPARAM enable);
281 
282 /* No alpha blending */
283 #define ALPHABLEND_NONE             0
284 /* "Cheap" binary alpha blending - but possibly faster */
285 #define ALPHABLEND_BINARY           1
286 /* Full alpha blending */
287 #define ALPHABLEND_FULL             2
288 
289 #endif /* _UXTHEME_PCH_ */
290