include: Add STORAGE_HOTPLUG_INFO structure.
[wine.git] / dlls / user32 / nonclient.c
blobb28e9e258da07e5e58917186dbe575859ab6ae09
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 "user_private.h"
22 #include "controls.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(nonclient);
27 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
30 static void adjust_window_rect( RECT *rect, DWORD style, BOOL menu, DWORD exStyle, NONCLIENTMETRICSW *ncm )
32 int adjust = 0;
34 if ((exStyle & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) == WS_EX_STATICEDGE)
35 adjust = 1; /* for the outer frame always present */
36 else if ((exStyle & WS_EX_DLGMODALFRAME) || (style & (WS_THICKFRAME|WS_DLGFRAME)))
37 adjust = 2; /* outer */
39 if (style & WS_THICKFRAME)
40 adjust += ncm->iBorderWidth + ncm->iPaddedBorderWidth; /* The resize border */
42 if ((style & (WS_BORDER|WS_DLGFRAME)) || (exStyle & WS_EX_DLGMODALFRAME))
43 adjust++; /* The other border */
45 InflateRect (rect, adjust, adjust);
47 if ((style & WS_CAPTION) == WS_CAPTION)
49 if (exStyle & WS_EX_TOOLWINDOW)
50 rect->top -= ncm->iSmCaptionHeight + 1;
51 else
52 rect->top -= ncm->iCaptionHeight + 1;
54 if (menu) rect->top -= ncm->iMenuHeight + 1;
56 if (exStyle & WS_EX_CLIENTEDGE)
57 InflateRect(rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
61 /***********************************************************************
62 * DrawCaption (USER32.@) Draws a caption bar
64 BOOL WINAPI DrawCaption( HWND hwnd, HDC hdc, const RECT *rect, UINT flags )
66 return NtUserDrawCaptionTemp( hwnd, hdc, rect, 0, 0, NULL, flags & 0x103f );
70 /***********************************************************************
71 * DrawCaptionTempA (USER32.@)
73 BOOL WINAPI DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont,
74 HICON hIcon, LPCSTR str, UINT uFlags)
76 LPWSTR strW;
77 INT len;
78 BOOL ret = FALSE;
80 if (!(uFlags & DC_TEXT) || !str)
81 return NtUserDrawCaptionTemp( hwnd, hdc, rect, hFont, hIcon, NULL, uFlags );
83 len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
84 if ((strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
86 MultiByteToWideChar( CP_ACP, 0, str, -1, strW, len );
87 ret = NtUserDrawCaptionTemp( hwnd, hdc, rect, hFont, hIcon, strW, uFlags );
88 HeapFree( GetProcessHeap (), 0, strW );
90 return ret;
94 /***********************************************************************
95 * AdjustWindowRect (USER32.@)
97 BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
99 return AdjustWindowRectEx( rect, style, menu, 0 );
103 /***********************************************************************
104 * AdjustWindowRectEx (USER32.@)
106 BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
108 NONCLIENTMETRICSW ncm;
110 TRACE("(%s) %08lx %d %08lx\n", wine_dbgstr_rect(rect), style, menu, exStyle );
112 ncm.cbSize = sizeof(ncm);
113 SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
115 adjust_window_rect( rect, style, menu, exStyle, &ncm );
116 return TRUE;
120 /***********************************************************************
121 * AdjustWindowRectExForDpi (USER32.@)
123 BOOL WINAPI DECLSPEC_HOTPATCH AdjustWindowRectExForDpi( LPRECT rect, DWORD style, BOOL menu,
124 DWORD exStyle, UINT dpi )
126 NONCLIENTMETRICSW ncm;
128 TRACE("(%s) %08lx %d %08lx %u\n", wine_dbgstr_rect(rect), style, menu, exStyle, dpi );
130 ncm.cbSize = sizeof(ncm);
131 SystemParametersInfoForDpi( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0, dpi );
133 adjust_window_rect( rect, style, menu, exStyle, &ncm );
134 return TRUE;
139 /***********************************************************************
140 * NC_HandleSysCommand
142 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
144 LRESULT NC_HandleSysCommand( HWND hwnd, WPARAM wParam, LPARAM lParam )
146 if (!NtUserMessageCall( hwnd, WM_SYSCOMMAND, wParam, lParam, 0, NtUserDefWindowProc, FALSE ))
147 return 0;
149 switch (wParam & 0xfff0)
151 case SC_TASKLIST:
152 WinExec( "taskman.exe", SW_SHOWNORMAL );
153 break;
155 case SC_SCREENSAVE:
156 if (wParam == SC_ABOUTWINE)
158 HMODULE hmodule = LoadLibraryA( "shell32.dll" );
159 if (hmodule)
161 BOOL (WINAPI *aboutproc)(HWND, LPCSTR, LPCSTR, HICON);
162 const char * (CDECL *p_wine_get_version)(void);
163 char app[256];
165 p_wine_get_version = (void *)GetProcAddress( GetModuleHandleW(L"ntdll.dll"), "wine_get_version" );
166 aboutproc = (void *)GetProcAddress( hmodule, "ShellAboutA" );
167 if (p_wine_get_version && aboutproc)
169 snprintf( app, ARRAY_SIZE(app), "Wine %s", p_wine_get_version() );
170 aboutproc( hwnd, app, NULL, 0 );
172 FreeLibrary( hmodule );
175 break;
177 return 0;
180 static void user_draw_mdi_button( HDC hdc, enum NONCLIENT_BUTTON_TYPE type, RECT rect, BOOL down, BOOL grayed )
182 UINT flags;
184 switch (type)
186 case MENU_CLOSE_BUTTON:
187 flags = DFCS_CAPTIONCLOSE;
188 break;
189 case MENU_MIN_BUTTON:
190 flags = DFCS_CAPTIONMIN;
191 break;
192 case MENU_MAX_BUTTON:
193 flags = DFCS_CAPTIONMAX;
194 break;
195 case MENU_RESTORE_BUTTON:
196 flags = DFCS_CAPTIONRESTORE;
197 break;
198 case MENU_HELP_BUTTON:
199 flags = DFCS_CAPTIONHELP;
200 break;
201 default:
202 return;
205 if (down)
206 flags |= DFCS_PUSHED;
207 if (grayed)
208 flags |= DFCS_INACTIVE;
210 DrawFrameControl( hdc, &rect, DFC_CAPTION, flags );
213 void WINAPI USER_NonClientButtonDraw( HWND hwnd, HDC hdc, enum NONCLIENT_BUTTON_TYPE type,
214 RECT rect, BOOL down, BOOL grayed )
216 switch (type)
218 case MENU_CLOSE_BUTTON:
219 case MENU_MIN_BUTTON:
220 case MENU_MAX_BUTTON:
221 case MENU_RESTORE_BUTTON:
222 case MENU_HELP_BUTTON:
223 user_draw_mdi_button( hdc, type, rect, down, grayed );
224 return;