ReactOS  0.4.14-dev-77-gd9e7c48
nonclient.c
Go to the documentation of this file.
1 /*
2  * ReactOS User32 Library
3  * - Window non-client area management
4  *
5  * Copyright (C) 2003 ReactOS Team
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <user32.h>
23 
25 
26 #define HASSIZEGRIP(Style, ExStyle, ParentStyle, WindowRect, ParentClientRect) \
27  ((!(Style & WS_CHILD) && (Style & WS_THICKFRAME) && !(Style & WS_MAXIMIZE)) || \
28  ((Style & WS_CHILD) && (ParentStyle & WS_THICKFRAME) && !(ParentStyle & WS_MAXIMIZE) && \
29  (WindowRect.right - WindowRect.left == ParentClientRect.right) && \
30  (WindowRect.bottom - WindowRect.top == ParentClientRect.bottom)))
31 
32 
33 /* PRIVATE FUNCTIONS **********************************************************/
34 
35 BOOL
37 {
38  if (Style & WS_MINIMIZE)
39  return TRUE;
41  return TRUE;
43  return FALSE;
44  if (Style & WS_THICKFRAME)
45  return TRUE;
46  Style &= WS_CAPTION;
47  if (Style == WS_DLGFRAME || Style == WS_CAPTION)
48  return TRUE;
49  return FALSE;
50 }
51 
52 VOID
54 {
55  DWORD Border = 0;
56 
58  Border += 2;
59  else if (ExStyle & WS_EX_STATICEDGE)
60  Border += 1;
61  if ((ExStyle & WS_EX_CLIENTEDGE) && WithClient)
62  Border += 2;
64  Border ++;
65  Size->cx = Size->cy = Border;
66  if ((Style & WS_THICKFRAME) && !(Style & WS_MINIMIZE))
67  {
70  }
73 }
74 
75 /*
76  RealUserDrawCaption: This function is passed through RegisterUserApiHook to uxtheme
77  to call it when the classic caption is needed to be drawn.
78  */
81 {
82  ERR("Real DC flags %08x\n",uFlags);
83  return NtUserDrawCaption(hWnd, hDC, lpRc, uFlags);
84 }
85 
86 
87 /* PUBLIC FUNCTIONS ***********************************************************/
88 
91  DWORD dwStyle,
92  BOOL bMenu,
93  DWORD dwExStyle)
94 {
95  SIZE BorderSize;
96 
97  if (bMenu)
98  {
99  lpRect->top -= GetSystemMetrics(SM_CYMENU);
100  }
101  if ((dwStyle & WS_CAPTION) == WS_CAPTION)
102  {
103  if (dwExStyle & WS_EX_TOOLWINDOW)
104  lpRect->top -= GetSystemMetrics(SM_CYSMCAPTION);
105  else
106  lpRect->top -= GetSystemMetrics(SM_CYCAPTION);
107  }
108  UserGetWindowBorders(dwStyle, dwExStyle, &BorderSize, TRUE);
109  InflateRect(
110  lpRect,
111  BorderSize.cx,
112  BorderSize.cy);
113 
114  return TRUE;
115 }
116 
117 /*
118  * @implemented
119  */
120 BOOL
121 WINAPI
124  DWORD dwStyle,
125  BOOL bMenu,
126  DWORD dwExStyle)
127 {
128  BOOL Hook, Ret = FALSE;
129 
130  LoadUserApiHook();
131 
132  Hook = BeginIfHookedUserApiHook();
133 
134  /* Bypass SEH and go direct. */
135  if (!Hook) return RealAdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
136 
137  _SEH2_TRY
138  {
139  Ret = guah.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
140  }
142  {
143  }
144  _SEH2_END;
145 
146  EndUserApiHook();
147 
148  return Ret;
149 }
150 
151 
152 /*
153  * @implemented
154  */
155 BOOL
156 WINAPI
159  DWORD dwStyle,
160  BOOL bMenu)
161 {
162  return AdjustWindowRectEx(lpRect, dwStyle, bMenu, 0);
163 }
164 
165 // Enabling this will cause captions to draw smoother, but slower:
166 #define DOUBLE_BUFFER_CAPTION
167 
168 /*
169  * @implemented
170  */
171 BOOL WINAPI
173 {
174  BOOL Hook, Ret = FALSE;
175 
176  LoadUserApiHook();
177 
178  Hook = BeginIfHookedUserApiHook();
179 
180  /* Bypass SEH and go direct. */
181  if (!Hook) return NtUserDrawCaption(hWnd, hDC, lprc, uFlags);
182 
183  _SEH2_TRY
184  {
185  Ret = guah.DrawCaption(hWnd, hDC, lprc, uFlags);
186  }
188  {
189  }
190  _SEH2_END;
191 
192  EndUserApiHook();
193 
194  return Ret;
195 }
196 
197 /*
198  * @implemented
199  */
200 BOOL
201 WINAPI
203  HWND hWnd,
204  HDC hDC,
205  const RECT *rect,
206  HFONT hFont,
207  HICON hIcon,
208  LPCWSTR str,
209  UINT uFlags
210  )
211 {
212  UNICODE_STRING Text = {0};
215 }
216 
217 /*
218  * @implemented
219  */
220 BOOL
221 WINAPI
223  HWND hwnd,
224  HDC hdc,
225  const RECT *rect,
226  HFONT hFont,
227  HICON hIcon,
228  LPCSTR str,
229  UINT uFlags
230  )
231 {
232  LPWSTR strW;
233  INT len;
234  BOOL ret = FALSE;
235 
236  if (!(uFlags & DC_TEXT) || !str)
238 
239  len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
240  if ((strW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
241  {
242  MultiByteToWideChar(CP_ACP, 0, str, -1, strW, len );
245  }
246  return ret;
247 }
#define WS_THICKFRAME
Definition: pedump.c:630
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL FASTCALL EndUserApiHook(VOID)
Definition: usrapihk.c:164
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
_In_ int _Inout_ LPRECT lprc
Definition: winuser.h:4366
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
WINE_DEFAULT_DEBUG_CHANNEL(user32)
#define CP_ACP
Definition: compat.h:99
USERAPIHOOK guah
Definition: usrapihk.c:344
static HDC
Definition: imagelist.c:92
HWND hWnd
Definition: settings.c:17
LONG top
Definition: windef.h:292
#define WS_DLGFRAME
Definition: pedump.c:626
BOOL UserHasWindowEdge(DWORD Style, DWORD ExStyle)
Definition: nonclient.c:36
UINT uFlags
Definition: api.c:60
#define SM_CYFRAME
Definition: winuser.h:986
#define SM_CXFRAME
Definition: winuser.h:984
#define WS_EX_TOOLWINDOW
Definition: winuser.h:404
int32_t INT
Definition: typedefs.h:56
& rect
Definition: startmenu.cpp:1413
HFONT hFont
Definition: main.c:53
_SEH2_TRY
Definition: create.c:4250
DRAWCAPTION DrawCaption
Definition: undocuser.h:350
BOOL WINAPI DrawCaptionTempW(HWND hWnd, HDC hDC, const RECT *rect, HFONT hFont, HICON hIcon, LPCWSTR str, UINT uFlags)
Definition: nonclient.c:202
BOOL WINAPI RealAdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle)
Definition: nonclient.c:90
ADJUSTWINDOWRECTEX AdjustWindowRectEx
Definition: undocuser.h:337
BOOL WINAPI RealUserDrawCaption(HWND hWnd, HDC hDC, LPCRECT lpRc, UINT uFlags)
Definition: nonclient.c:80
#define WS_MINIMIZE
Definition: pedump.c:622
unsigned int BOOL
Definition: ntddk_ex.h:94
WCHAR strW[12]
Definition: clipboard.c:2029
#define SM_CYDLGFRAME
Definition: winuser.h:958
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define WS_EX_DLGMODALFRAME
Definition: pedump.c:645
LONG cx
Definition: windef.h:319
const char * LPCSTR
Definition: xmlstorage.h:183
VOID UserGetWindowBorders(DWORD Style, DWORD ExStyle, SIZE *Size, BOOL WithClient)
Definition: nonclient.c:53
BOOL NTAPI NtUserDrawCaptionTemp(HWND hWnd, HDC hDC, LPCRECT lpRc, HFONT hFont, HICON hIcon, const PUNICODE_STRING str, UINT uFlags)
Definition: painting.c:2364
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
#define WS_CAPTION
Definition: pedump.c:624
#define GetProcessHeap()
Definition: compat.h:395
#define SM_CYCAPTION
Definition: winuser.h:953
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
const DWORD Style
Definition: appswitch.c:71
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SM_CXDLGFRAME
Definition: winuser.h:956
#define WINAPI
Definition: msvc.h:8
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRect(LPRECT lpRect, DWORD dwStyle, BOOL bMenu)
Definition: nonclient.c:158
#define SM_CYBORDER
Definition: winuser.h:955
int ret
HDC hdc
Definition: main.c:9
#define SM_CXBORDER
Definition: winuser.h:954
GLenum GLsizei len
Definition: glext.h:6722
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define ERR(fmt,...)
Definition: debug.h:109
static HDC hDC
Definition: 3dtext.c:33
_SEH2_END
Definition: create.c:4424
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
HICON hIcon
Definition: msconfig.c:44
static __inline void LoadUserApiHook()
Definition: user_x.h:85
BOOL FASTCALL BeginIfHookedUserApiHook(VOID)
Definition: usrapihk.c:106
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI DrawCaption(HWND hWnd, HDC hDC, LPCRECT lprc, UINT uFlags)
Definition: nonclient.c:172
#define MultiByteToWideChar
Definition: compat.h:100
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
BOOL WINAPI DrawCaptionTempA(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCSTR str, UINT uFlags)
Definition: nonclient.c:222
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define SM_CYMENU
Definition: winuser.h:966
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle)
Definition: nonclient.c:123
#define SM_CYSMCAPTION
Definition: winuser.h:1004
LONG cy
Definition: windef.h:320
#define WS_EX_STATICEDGE
Definition: winuser.h:403
#define HeapFree(x, y, z)
Definition: compat.h:394
#define DC_TEXT
Definition: winuser.h:430
BOOL NTAPI NtUserDrawCaption(HWND hWnd, HDC hDc, LPCRECT lpRc, UINT uFlags)
Definition: painting.c:2447
char * Text
Definition: combotst.c:136
const DWORD ExStyle
Definition: appswitch.c:72