win32u: Move NtUserGetTitleBarInfo implementation from user32.
[wine.git] / dlls / user32 / nonclient.c
blob3eb7ce7883bafea48d2da77834f8b55236679077
1 /*
2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winnls.h"
27 #include "win.h"
28 #include "user_private.h"
29 #include "controls.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(nonclient);
34 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
37 static void adjust_window_rect( RECT *rect, DWORD style, BOOL menu, DWORD exStyle, NONCLIENTMETRICSW *ncm )
39 int adjust = 0;
41 if ((exStyle & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) == WS_EX_STATICEDGE)
42 adjust = 1; /* for the outer frame always present */
43 else if ((exStyle & WS_EX_DLGMODALFRAME) || (style & (WS_THICKFRAME|WS_DLGFRAME)))
44 adjust = 2; /* outer */
46 if (style & WS_THICKFRAME)
47 adjust += ncm->iBorderWidth + ncm->iPaddedBorderWidth; /* The resize border */
49 if ((style & (WS_BORDER|WS_DLGFRAME)) || (exStyle & WS_EX_DLGMODALFRAME))
50 adjust++; /* The other border */
52 InflateRect (rect, adjust, adjust);
54 if ((style & WS_CAPTION) == WS_CAPTION)
56 if (exStyle & WS_EX_TOOLWINDOW)
57 rect->top -= ncm->iSmCaptionHeight + 1;
58 else
59 rect->top -= ncm->iCaptionHeight + 1;
61 if (menu) rect->top -= ncm->iMenuHeight + 1;
63 if (exStyle & WS_EX_CLIENTEDGE)
64 InflateRect(rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
68 /***********************************************************************
69 * DrawCaption (USER32.@) Draws a caption bar
71 BOOL WINAPI DrawCaption( HWND hwnd, HDC hdc, const RECT *rect, UINT flags )
73 return NtUserDrawCaptionTemp( hwnd, hdc, rect, 0, 0, NULL, flags & 0x103f );
77 /***********************************************************************
78 * DrawCaptionTempA (USER32.@)
80 BOOL WINAPI DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont,
81 HICON hIcon, LPCSTR str, UINT uFlags)
83 LPWSTR strW;
84 INT len;
85 BOOL ret = FALSE;
87 if (!(uFlags & DC_TEXT) || !str)
88 return NtUserDrawCaptionTemp( hwnd, hdc, rect, hFont, hIcon, NULL, uFlags );
90 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
91 if ((strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
93 MultiByteToWideChar( CP_ACP, 0, str, -1, strW, len );
94 ret = NtUserDrawCaptionTemp( hwnd, hdc, rect, hFont, hIcon, strW, uFlags );
95 HeapFree( GetProcessHeap (), 0, strW );
97 return ret;
101 /***********************************************************************
102 * AdjustWindowRect (USER32.@)
104 BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
106 return AdjustWindowRectEx( rect, style, menu, 0 );
110 /***********************************************************************
111 * AdjustWindowRectEx (USER32.@)
113 BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
115 NONCLIENTMETRICSW ncm;
117 TRACE("(%s) %08lx %d %08lx\n", wine_dbgstr_rect(rect), style, menu, exStyle );
119 ncm.cbSize = sizeof(ncm);
120 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
122 adjust_window_rect( rect, style, menu, exStyle, &ncm );
123 return TRUE;
127 /***********************************************************************
128 * AdjustWindowRectExForDpi (USER32.@)
130 BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRectExForDpi( LPRECT rect, DWORD style, BOOL menu,
131 DWORD exStyle, UINT dpi )
133 NONCLIENTMETRICSW ncm;
135 TRACE("(%s) %08lx %d %08lx %u\n", wine_dbgstr_rect(rect), style, menu, exStyle, dpi );
137 ncm.cbSize = sizeof(ncm);
138 SystemParametersInfoForDpi( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0, dpi );
140 adjust_window_rect( rect, style, menu, exStyle, &ncm );
141 return TRUE;
145 LRESULT NC_HandleNCMouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
147 RECT rect;
148 POINT pt;
150 TRACE("hwnd=%p wparam=%#Ix lparam=%#Ix\n", hwnd, wParam, lParam);
152 if (wParam != HTHSCROLL && wParam != HTVSCROLL)
153 return 0;
155 WIN_GetRectangles(hwnd, COORDS_CLIENT, &rect, NULL);
157 pt.x = (short)LOWORD(lParam);
158 pt.y = (short)HIWORD(lParam);
159 ScreenToClient(hwnd, &pt);
160 pt.x -= rect.left;
161 pt.y -= rect.top;
162 SCROLL_HandleScrollEvent(hwnd, wParam == HTHSCROLL ? SB_HORZ : SB_VERT, WM_NCMOUSEMOVE, pt);
163 return 0;
166 LRESULT NC_HandleNCMouseLeave(HWND hwnd)
168 LONG style = GetWindowLongW(hwnd, GWL_STYLE);
169 POINT pt = {0, 0};
171 TRACE("hwnd=%p\n", hwnd);
173 if (style & WS_HSCROLL)
174 SCROLL_HandleScrollEvent(hwnd, SB_HORZ, WM_NCMOUSELEAVE, pt);
175 if (style & WS_VSCROLL)
176 SCROLL_HandleScrollEvent(hwnd, SB_VERT, WM_NCMOUSELEAVE, pt);
178 return 0;
182 /***********************************************************************
183 * NC_TrackScrollBar
185 * Track a mouse button press on the horizontal or vertical scroll-bar.
187 static void NC_TrackScrollBar( HWND hwnd, WPARAM wParam, POINT pt )
189 INT scrollbar;
191 if ((wParam & 0xfff0) == SC_HSCROLL)
193 if ((wParam & 0x0f) != HTHSCROLL) return;
194 scrollbar = SB_HORZ;
196 else /* SC_VSCROLL */
198 if ((wParam & 0x0f) != HTVSCROLL) return;
199 scrollbar = SB_VERT;
201 SCROLL_TrackScrollBar( hwnd, scrollbar, pt );
205 /***********************************************************************
206 * NC_HandleSysCommand
208 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
210 LRESULT NC_HandleSysCommand( HWND hwnd, WPARAM wParam, LPARAM lParam )
212 if (!NtUserMessageCall( hwnd, WM_SYSCOMMAND, wParam, lParam, 0, NtUserDefWindowProc, FALSE ))
213 return 0;
215 switch (wParam & 0xfff0)
217 case SC_VSCROLL:
218 case SC_HSCROLL:
220 POINT pt;
221 pt.x = (short)LOWORD(lParam);
222 pt.y = (short)HIWORD(lParam);
223 NC_TrackScrollBar( hwnd, wParam, pt );
225 break;
227 case SC_TASKLIST:
228 WinExec( "taskman.exe", SW_SHOWNORMAL );
229 break;
231 case SC_SCREENSAVE:
232 if (wParam == SC_ABOUTWINE)
234 HMODULE hmodule = LoadLibraryA( "shell32.dll" );
235 if (hmodule)
237 BOOL (WINAPI *aboutproc)(HWND, LPCSTR, LPCSTR, HICON);
238 extern const char * CDECL wine_get_version(void);
239 char app[256];
241 sprintf( app, "Wine %s", wine_get_version() );
242 aboutproc = (void *)GetProcAddress( hmodule, "ShellAboutA" );
243 if (aboutproc) aboutproc( hwnd, app, NULL, 0 );
244 FreeLibrary( hmodule );
247 break;
249 return 0;