windows.networking.hostname/tests: Add IHostNameFactory::CreateHostName() tests.
[wine.git] / dlls / user32 / sysparams.c
blob5ededfee62a7484065e343079100fe43d7d5d65d
1 /*
2 * System parameters 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/asm.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(system);
29 static HDC display_dc;
30 static CRITICAL_SECTION display_dc_section;
31 static CRITICAL_SECTION_DEBUG critsect_debug =
33 0, 0, &display_dc_section,
34 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
35 0, 0, { (DWORD_PTR)(__FILE__ ": display_dc_section") }
37 static CRITICAL_SECTION display_dc_section = { &critsect_debug, -1 ,0, 0, 0, 0 };
40 /* System parameters storage */
41 static UINT system_dpi;
43 static void SYSPARAMS_LogFont32WTo32A( const LOGFONTW* font32W, LPLOGFONTA font32A )
45 font32A->lfHeight = font32W->lfHeight;
46 font32A->lfWidth = font32W->lfWidth;
47 font32A->lfEscapement = font32W->lfEscapement;
48 font32A->lfOrientation = font32W->lfOrientation;
49 font32A->lfWeight = font32W->lfWeight;
50 font32A->lfItalic = font32W->lfItalic;
51 font32A->lfUnderline = font32W->lfUnderline;
52 font32A->lfStrikeOut = font32W->lfStrikeOut;
53 font32A->lfCharSet = font32W->lfCharSet;
54 font32A->lfOutPrecision = font32W->lfOutPrecision;
55 font32A->lfClipPrecision = font32W->lfClipPrecision;
56 font32A->lfQuality = font32W->lfQuality;
57 font32A->lfPitchAndFamily = font32W->lfPitchAndFamily;
58 WideCharToMultiByte( CP_ACP, 0, font32W->lfFaceName, -1, font32A->lfFaceName, LF_FACESIZE, NULL, NULL );
59 font32A->lfFaceName[LF_FACESIZE-1] = 0;
62 static void SYSPARAMS_LogFont32ATo32W( const LOGFONTA* font32A, LPLOGFONTW font32W )
64 font32W->lfHeight = font32A->lfHeight;
65 font32W->lfWidth = font32A->lfWidth;
66 font32W->lfEscapement = font32A->lfEscapement;
67 font32W->lfOrientation = font32A->lfOrientation;
68 font32W->lfWeight = font32A->lfWeight;
69 font32W->lfItalic = font32A->lfItalic;
70 font32W->lfUnderline = font32A->lfUnderline;
71 font32W->lfStrikeOut = font32A->lfStrikeOut;
72 font32W->lfCharSet = font32A->lfCharSet;
73 font32W->lfOutPrecision = font32A->lfOutPrecision;
74 font32W->lfClipPrecision = font32A->lfClipPrecision;
75 font32W->lfQuality = font32A->lfQuality;
76 font32W->lfPitchAndFamily = font32A->lfPitchAndFamily;
77 MultiByteToWideChar( CP_ACP, 0, font32A->lfFaceName, -1, font32W->lfFaceName, LF_FACESIZE );
78 font32W->lfFaceName[LF_FACESIZE-1] = 0;
81 static void SYSPARAMS_NonClientMetrics32WTo32A( const NONCLIENTMETRICSW* lpnm32W, LPNONCLIENTMETRICSA lpnm32A )
83 lpnm32A->iBorderWidth = lpnm32W->iBorderWidth;
84 lpnm32A->iScrollWidth = lpnm32W->iScrollWidth;
85 lpnm32A->iScrollHeight = lpnm32W->iScrollHeight;
86 lpnm32A->iCaptionWidth = lpnm32W->iCaptionWidth;
87 lpnm32A->iCaptionHeight = lpnm32W->iCaptionHeight;
88 SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfCaptionFont, &lpnm32A->lfCaptionFont );
89 lpnm32A->iSmCaptionWidth = lpnm32W->iSmCaptionWidth;
90 lpnm32A->iSmCaptionHeight = lpnm32W->iSmCaptionHeight;
91 SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfSmCaptionFont, &lpnm32A->lfSmCaptionFont );
92 lpnm32A->iMenuWidth = lpnm32W->iMenuWidth;
93 lpnm32A->iMenuHeight = lpnm32W->iMenuHeight;
94 SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMenuFont, &lpnm32A->lfMenuFont );
95 SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfStatusFont, &lpnm32A->lfStatusFont );
96 SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMessageFont, &lpnm32A->lfMessageFont );
97 if (lpnm32A->cbSize > FIELD_OFFSET(NONCLIENTMETRICSA, iPaddedBorderWidth))
99 if (lpnm32W->cbSize > FIELD_OFFSET(NONCLIENTMETRICSW, iPaddedBorderWidth))
100 lpnm32A->iPaddedBorderWidth = lpnm32W->iPaddedBorderWidth;
101 else
102 lpnm32A->iPaddedBorderWidth = 0;
106 static void SYSPARAMS_NonClientMetrics32ATo32W( const NONCLIENTMETRICSA* lpnm32A, LPNONCLIENTMETRICSW lpnm32W )
108 lpnm32W->iBorderWidth = lpnm32A->iBorderWidth;
109 lpnm32W->iScrollWidth = lpnm32A->iScrollWidth;
110 lpnm32W->iScrollHeight = lpnm32A->iScrollHeight;
111 lpnm32W->iCaptionWidth = lpnm32A->iCaptionWidth;
112 lpnm32W->iCaptionHeight = lpnm32A->iCaptionHeight;
113 SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfCaptionFont, &lpnm32W->lfCaptionFont );
114 lpnm32W->iSmCaptionWidth = lpnm32A->iSmCaptionWidth;
115 lpnm32W->iSmCaptionHeight = lpnm32A->iSmCaptionHeight;
116 SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfSmCaptionFont, &lpnm32W->lfSmCaptionFont );
117 lpnm32W->iMenuWidth = lpnm32A->iMenuWidth;
118 lpnm32W->iMenuHeight = lpnm32A->iMenuHeight;
119 SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMenuFont, &lpnm32W->lfMenuFont );
120 SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfStatusFont, &lpnm32W->lfStatusFont );
121 SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMessageFont, &lpnm32W->lfMessageFont );
122 if (lpnm32W->cbSize > FIELD_OFFSET(NONCLIENTMETRICSW, iPaddedBorderWidth))
124 if (lpnm32A->cbSize > FIELD_OFFSET(NONCLIENTMETRICSA, iPaddedBorderWidth))
125 lpnm32W->iPaddedBorderWidth = lpnm32A->iPaddedBorderWidth;
126 else
127 lpnm32W->iPaddedBorderWidth = 0;
132 /* Helper functions to retrieve monitors info */
134 HDC get_display_dc(void)
136 EnterCriticalSection( &display_dc_section );
137 if (!display_dc)
139 HDC dc;
141 LeaveCriticalSection( &display_dc_section );
142 dc = CreateDCW( L"DISPLAY", NULL, NULL, NULL );
143 EnterCriticalSection( &display_dc_section );
144 if (display_dc)
145 DeleteDC(dc);
146 else
147 display_dc = dc;
149 return display_dc;
152 void release_display_dc( HDC hdc )
154 LeaveCriticalSection( &display_dc_section );
157 /***********************************************************************
158 * SYSPARAMS_Init
160 void SYSPARAMS_Init(void)
162 system_dpi = NtUserGetSystemDpiForProcess( NULL );
165 static BOOL update_desktop_wallpaper(void)
167 DWORD pid;
169 if (GetWindowThreadProcessId( GetDesktopWindow(), &pid ) && pid == GetCurrentProcessId())
171 WCHAR wallpaper[MAX_PATH], pattern[256];
173 if (NtUserSystemParametersInfo( SPI_GETDESKWALLPAPER, ARRAYSIZE(wallpaper), wallpaper, 0 ) &&
174 NtUserCallOneParam( (ULONG_PTR)pattern, NtUserGetDeskPattern ))
176 update_wallpaper( wallpaper, pattern );
179 else SendMessageW( GetDesktopWindow(), WM_SETTINGCHANGE, SPI_SETDESKWALLPAPER, 0 );
180 return TRUE;
184 /***********************************************************************
185 * SystemParametersInfoForDpi (USER32.@)
187 BOOL WINAPI SystemParametersInfoForDpi( UINT action, UINT val, PVOID ptr, UINT winini, UINT dpi )
189 BOOL ret = NtUserSystemParametersInfoForDpi( action, val, ptr, winini, dpi );
190 if (ret && (action == SPI_SETDESKWALLPAPER || action == SPI_SETDESKPATTERN))
191 ret = update_desktop_wallpaper();
192 return ret;
196 /***********************************************************************
197 * SystemParametersInfoW (USER32.@)
199 BOOL WINAPI SystemParametersInfoW( UINT action, UINT val, void *ptr, UINT winini )
201 BOOL ret = NtUserSystemParametersInfo( action, val, ptr, winini );
202 if (ret && (action == SPI_SETDESKWALLPAPER || action == SPI_SETDESKPATTERN))
203 ret = update_desktop_wallpaper();
204 return ret;
208 /***********************************************************************
209 * SystemParametersInfoA (USER32.@)
211 BOOL WINAPI SystemParametersInfoA( UINT uiAction, UINT uiParam,
212 PVOID pvParam, UINT fuWinIni )
214 BOOL ret;
216 TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fuWinIni);
218 switch (uiAction)
220 case SPI_SETDESKWALLPAPER: /* 20 */
221 case SPI_SETDESKPATTERN: /* 21 */
223 WCHAR buffer[256];
224 if (pvParam)
225 if (!MultiByteToWideChar( CP_ACP, 0, pvParam, -1, buffer, ARRAY_SIZE( buffer )))
226 buffer[ARRAY_SIZE(buffer)-1] = 0;
227 ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? buffer : NULL, fuWinIni );
228 break;
231 case SPI_GETICONTITLELOGFONT: /* 31 */
233 LOGFONTW tmp;
234 ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? &tmp : NULL, fuWinIni );
235 if (ret && pvParam)
236 SYSPARAMS_LogFont32WTo32A( &tmp, pvParam );
237 break;
240 case SPI_GETNONCLIENTMETRICS: /* 41 WINVER >= 0x400 */
242 NONCLIENTMETRICSW tmp;
243 LPNONCLIENTMETRICSA lpnmA = pvParam;
244 if (lpnmA && (lpnmA->cbSize == sizeof(NONCLIENTMETRICSA) ||
245 lpnmA->cbSize == FIELD_OFFSET(NONCLIENTMETRICSA, iPaddedBorderWidth)))
247 tmp.cbSize = sizeof(NONCLIENTMETRICSW);
248 ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
249 if (ret)
250 SYSPARAMS_NonClientMetrics32WTo32A( &tmp, lpnmA );
252 else
253 ret = FALSE;
254 break;
257 case SPI_SETNONCLIENTMETRICS: /* 42 WINVER >= 0x400 */
259 NONCLIENTMETRICSW tmp;
260 LPNONCLIENTMETRICSA lpnmA = pvParam;
261 if (lpnmA && (lpnmA->cbSize == sizeof(NONCLIENTMETRICSA) ||
262 lpnmA->cbSize == FIELD_OFFSET(NONCLIENTMETRICSA, iPaddedBorderWidth)))
264 tmp.cbSize = sizeof(NONCLIENTMETRICSW);
265 SYSPARAMS_NonClientMetrics32ATo32W( lpnmA, &tmp );
266 ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
268 else
269 ret = FALSE;
270 break;
273 case SPI_GETICONMETRICS: /* 45 WINVER >= 0x400 */
275 ICONMETRICSW tmp;
276 LPICONMETRICSA lpimA = pvParam;
277 if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
279 tmp.cbSize = sizeof(ICONMETRICSW);
280 ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
281 if (ret)
283 lpimA->iHorzSpacing = tmp.iHorzSpacing;
284 lpimA->iVertSpacing = tmp.iVertSpacing;
285 lpimA->iTitleWrap = tmp.iTitleWrap;
286 SYSPARAMS_LogFont32WTo32A( &tmp.lfFont, &lpimA->lfFont );
289 else
290 ret = FALSE;
291 break;
294 case SPI_SETICONMETRICS: /* 46 WINVER >= 0x400 */
296 ICONMETRICSW tmp;
297 LPICONMETRICSA lpimA = pvParam;
298 if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
300 tmp.cbSize = sizeof(ICONMETRICSW);
301 tmp.iHorzSpacing = lpimA->iHorzSpacing;
302 tmp.iVertSpacing = lpimA->iVertSpacing;
303 tmp.iTitleWrap = lpimA->iTitleWrap;
304 SYSPARAMS_LogFont32ATo32W( &lpimA->lfFont, &tmp.lfFont);
305 ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
307 else
308 ret = FALSE;
309 break;
312 case SPI_GETHIGHCONTRAST: /* 66 WINVER >= 0x400 */
314 HIGHCONTRASTW tmp;
315 LPHIGHCONTRASTA lphcA = pvParam;
316 if (lphcA && lphcA->cbSize == sizeof(HIGHCONTRASTA))
318 tmp.cbSize = sizeof(HIGHCONTRASTW);
319 ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
320 if (ret)
322 lphcA->dwFlags = tmp.dwFlags;
323 lphcA->lpszDefaultScheme = NULL; /* FIXME? */
326 else
327 ret = FALSE;
328 break;
331 case SPI_GETDESKWALLPAPER: /* 115 */
333 WCHAR buffer[MAX_PATH];
334 ret = (SystemParametersInfoW( SPI_GETDESKWALLPAPER, uiParam, buffer, fuWinIni ) &&
335 WideCharToMultiByte(CP_ACP, 0, buffer, -1, pvParam, uiParam, NULL, NULL));
336 break;
339 default:
340 ret = SystemParametersInfoW( uiAction, uiParam, pvParam, fuWinIni );
341 break;
343 return ret;
347 /***********************************************************************
348 * GetSystemMetrics (USER32.@)
350 INT WINAPI GetSystemMetrics( INT index )
352 return NtUserGetSystemMetrics( index );
356 /***********************************************************************
357 * GetSystemMetricsForDpi (USER32.@)
359 INT WINAPI GetSystemMetricsForDpi( INT index, UINT dpi )
361 return NtUserGetSystemMetricsForDpi( index, dpi );
365 /***********************************************************************
366 * SwapMouseButton (USER32.@)
367 * Reverse or restore the meaning of the left and right mouse buttons
368 * fSwap [I ] TRUE - reverse, FALSE - original
369 * RETURN
370 * previous state
372 BOOL WINAPI SwapMouseButton( BOOL fSwap )
374 BOOL prev = GetSystemMetrics(SM_SWAPBUTTON);
375 SystemParametersInfoW(SPI_SETMOUSEBUTTONSWAP, fSwap, 0, 0);
376 return prev;
380 /**********************************************************************
381 * SetDoubleClickTime (USER32.@)
383 BOOL WINAPI SetDoubleClickTime( UINT interval )
385 return SystemParametersInfoW(SPI_SETDOUBLECLICKTIME, interval, 0, 0);
389 /*************************************************************************
390 * GetSysColor (USER32.@)
392 COLORREF WINAPI DECLSPEC_HOTPATCH GetSysColor( INT index )
394 return NtUserGetSysColor( index );
398 /*************************************************************************
399 * SetSysColorsTemp (USER32.@)
401 DWORD_PTR WINAPI SetSysColorsTemp( const COLORREF *pPens, const HBRUSH *pBrushes, DWORD_PTR n)
403 FIXME( "no longer supported\n" );
404 return FALSE;
408 /***********************************************************************
409 * GetSysColorBrush (USER32.@)
411 HBRUSH WINAPI DECLSPEC_HOTPATCH GetSysColorBrush( INT index )
413 return NtUserGetSysColorBrush( index );
417 /***********************************************************************
418 * SYSCOLOR_GetPen
420 HPEN SYSCOLOR_GetPen( INT index )
422 return NtUserGetSysColorPen( index );
426 /***********************************************************************
427 * SYSCOLOR_Get55AABrush
429 HBRUSH SYSCOLOR_Get55AABrush(void)
431 return NtUserGetSysColorBrush( COLOR_55AA_BRUSH );
434 /***********************************************************************
435 * ChangeDisplaySettingsA (USER32.@)
437 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
439 if (devmode) devmode->dmDriverExtra = 0;
441 return ChangeDisplaySettingsExA(NULL,devmode,NULL,flags,NULL);
445 /***********************************************************************
446 * ChangeDisplaySettingsW (USER32.@)
448 LONG WINAPI ChangeDisplaySettingsW( LPDEVMODEW devmode, DWORD flags )
450 if (devmode) devmode->dmDriverExtra = 0;
452 return ChangeDisplaySettingsExW(NULL,devmode,NULL,flags,NULL);
456 /***********************************************************************
457 * ChangeDisplaySettingsExA (USER32.@)
459 LONG WINAPI ChangeDisplaySettingsExA( LPCSTR devname, LPDEVMODEA devmode, HWND hwnd,
460 DWORD flags, LPVOID lparam )
462 LONG ret;
463 UNICODE_STRING nameW;
465 if (devname) RtlCreateUnicodeStringFromAsciiz(&nameW, devname);
466 else nameW.Buffer = NULL;
468 if (devmode)
470 DEVMODEW *devmodeW;
472 devmodeW = GdiConvertToDevmodeW(devmode);
473 if (devmodeW)
475 ret = ChangeDisplaySettingsExW(nameW.Buffer, devmodeW, hwnd, flags, lparam);
476 HeapFree(GetProcessHeap(), 0, devmodeW);
478 else
479 ret = DISP_CHANGE_SUCCESSFUL;
481 else
483 ret = ChangeDisplaySettingsExW(nameW.Buffer, NULL, hwnd, flags, lparam);
486 if (devname) RtlFreeUnicodeString(&nameW);
487 return ret;
491 /***********************************************************************
492 * ChangeDisplaySettingsExW (USER32.@)
494 LONG WINAPI ChangeDisplaySettingsExW( LPCWSTR devname, LPDEVMODEW devmode, HWND hwnd,
495 DWORD flags, LPVOID lparam )
497 UNICODE_STRING str;
498 RtlInitUnicodeString( &str, devname );
499 return NtUserChangeDisplaySettings( &str, devmode, hwnd, flags, lparam );
503 /***********************************************************************
504 * EnumDisplaySettingsW (USER32.@)
506 * RETURNS
507 * TRUE if nth setting exists found (described in the LPDEVMODEW struct)
508 * FALSE if we do not have the nth setting
510 BOOL WINAPI EnumDisplaySettingsW( LPCWSTR name, DWORD n, LPDEVMODEW devmode )
512 return EnumDisplaySettingsExW(name, n, devmode, 0);
516 /***********************************************************************
517 * EnumDisplaySettingsA (USER32.@)
519 BOOL WINAPI EnumDisplaySettingsA(LPCSTR name,DWORD n,LPDEVMODEA devmode)
521 return EnumDisplaySettingsExA(name, n, devmode, 0);
525 /***********************************************************************
526 * EnumDisplaySettingsExA (USER32.@)
528 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
529 LPDEVMODEA lpDevMode, DWORD dwFlags)
531 DEVMODEW devmodeW;
532 BOOL ret;
533 UNICODE_STRING nameW;
535 if (lpszDeviceName) RtlCreateUnicodeStringFromAsciiz(&nameW, lpszDeviceName);
536 else nameW.Buffer = NULL;
538 memset(&devmodeW, 0, sizeof(devmodeW));
539 devmodeW.dmSize = sizeof(devmodeW);
540 ret = EnumDisplaySettingsExW(nameW.Buffer,iModeNum,&devmodeW,dwFlags);
541 if (ret)
543 lpDevMode->dmSize = FIELD_OFFSET(DEVMODEA, dmICMMethod);
544 lpDevMode->dmSpecVersion = devmodeW.dmSpecVersion;
545 lpDevMode->dmDriverVersion = devmodeW.dmDriverVersion;
546 WideCharToMultiByte(CP_ACP, 0, devmodeW.dmDeviceName, -1,
547 (LPSTR)lpDevMode->dmDeviceName, CCHDEVICENAME, NULL, NULL);
548 lpDevMode->dmDriverExtra = 0; /* FIXME */
549 lpDevMode->dmBitsPerPel = devmodeW.dmBitsPerPel;
550 lpDevMode->dmPelsHeight = devmodeW.dmPelsHeight;
551 lpDevMode->dmPelsWidth = devmodeW.dmPelsWidth;
552 lpDevMode->dmDisplayFlags = devmodeW.dmDisplayFlags;
553 lpDevMode->dmDisplayFrequency = devmodeW.dmDisplayFrequency;
554 lpDevMode->dmFields = devmodeW.dmFields;
556 lpDevMode->dmPosition.x = devmodeW.dmPosition.x;
557 lpDevMode->dmPosition.y = devmodeW.dmPosition.y;
558 lpDevMode->dmDisplayOrientation = devmodeW.dmDisplayOrientation;
559 lpDevMode->dmDisplayFixedOutput = devmodeW.dmDisplayFixedOutput;
561 if (lpszDeviceName) RtlFreeUnicodeString(&nameW);
562 return ret;
566 /***********************************************************************
567 * EnumDisplaySettingsExW (USER32.@)
569 BOOL WINAPI EnumDisplaySettingsExW( const WCHAR *device, DWORD mode,
570 DEVMODEW *dev_mode, DWORD flags )
572 UNICODE_STRING str;
573 RtlInitUnicodeString( &str, device );
574 return NtUserEnumDisplaySettings( &str, mode, dev_mode, flags );
577 /**********************************************************************
578 * SetProcessDpiAwarenessContext (USER32.@)
580 BOOL WINAPI SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT context )
582 ULONG awareness;
584 switch (GetAwarenessFromDpiAwarenessContext( context ))
586 case DPI_AWARENESS_UNAWARE:
587 awareness = NTUSER_DPI_UNAWARE;
588 break;
589 case DPI_AWARENESS_SYSTEM_AWARE:
590 awareness = NTUSER_DPI_SYSTEM_AWARE;
591 break;
592 case DPI_AWARENESS_PER_MONITOR_AWARE:
593 awareness = context == DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
594 ? NTUSER_DPI_PER_MONITOR_AWARE_V2 : NTUSER_DPI_PER_MONITOR_AWARE;
595 break;
596 default:
597 SetLastError( ERROR_INVALID_PARAMETER );
598 return FALSE;
601 if (!NtUserSetProcessDpiAwarenessContext( awareness, 0 ))
603 SetLastError( ERROR_ACCESS_DENIED );
604 return FALSE;
607 TRACE( "set to %p\n", context );
608 return TRUE;
611 /**********************************************************************
612 * GetProcessDpiAwarenessInternal (USER32.@)
614 BOOL WINAPI GetProcessDpiAwarenessInternal( HANDLE process, DPI_AWARENESS *awareness )
616 *awareness = NtUserGetProcessDpiAwarenessContext( process ) & 3;
617 return TRUE;
620 /**********************************************************************
621 * SetProcessDpiAwarenessInternal (USER32.@)
623 BOOL WINAPI SetProcessDpiAwarenessInternal( DPI_AWARENESS awareness )
625 static const DPI_AWARENESS_CONTEXT contexts[3] = { DPI_AWARENESS_CONTEXT_UNAWARE,
626 DPI_AWARENESS_CONTEXT_SYSTEM_AWARE,
627 DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE };
629 if (awareness < DPI_AWARENESS_UNAWARE || awareness > DPI_AWARENESS_PER_MONITOR_AWARE)
631 SetLastError( ERROR_INVALID_PARAMETER );
632 return FALSE;
634 return SetProcessDpiAwarenessContext( contexts[awareness] );
637 /***********************************************************************
638 * AreDpiAwarenessContextsEqual (USER32.@)
640 BOOL WINAPI AreDpiAwarenessContextsEqual( DPI_AWARENESS_CONTEXT ctx1, DPI_AWARENESS_CONTEXT ctx2 )
642 DPI_AWARENESS aware1 = GetAwarenessFromDpiAwarenessContext( ctx1 );
643 DPI_AWARENESS aware2 = GetAwarenessFromDpiAwarenessContext( ctx2 );
644 return aware1 != DPI_AWARENESS_INVALID && aware1 == aware2;
647 /***********************************************************************
648 * GetAwarenessFromDpiAwarenessContext (USER32.@)
650 DPI_AWARENESS WINAPI GetAwarenessFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT context )
652 switch ((ULONG_PTR)context)
654 case 0x10:
655 case 0x11:
656 case 0x12:
657 case 0x80000010:
658 case 0x80000011:
659 case 0x80000012:
660 return (ULONG_PTR)context & 3;
661 case (ULONG_PTR)DPI_AWARENESS_CONTEXT_UNAWARE:
662 case (ULONG_PTR)DPI_AWARENESS_CONTEXT_SYSTEM_AWARE:
663 case (ULONG_PTR)DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE:
664 return ~(ULONG_PTR)context;
665 default:
666 return DPI_AWARENESS_INVALID;
670 /***********************************************************************
671 * IsValidDpiAwarenessContext (USER32.@)
673 BOOL WINAPI IsValidDpiAwarenessContext( DPI_AWARENESS_CONTEXT context )
675 return GetAwarenessFromDpiAwarenessContext( context ) != DPI_AWARENESS_INVALID;
678 /***********************************************************************
679 * SetProcessDPIAware (USER32.@)
681 BOOL WINAPI SetProcessDPIAware(void)
683 TRACE("\n");
684 NtUserSetProcessDpiAwarenessContext( NTUSER_DPI_SYSTEM_AWARE, 0 );
685 return TRUE;
688 /***********************************************************************
689 * IsProcessDPIAware (USER32.@)
691 BOOL WINAPI IsProcessDPIAware(void)
693 return GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() ) != DPI_AWARENESS_UNAWARE;
696 /**********************************************************************
697 * EnableNonClientDpiScaling (USER32.@)
699 BOOL WINAPI EnableNonClientDpiScaling( HWND hwnd )
701 FIXME("(%p): stub\n", hwnd);
702 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
703 return FALSE;
706 /***********************************************************************
707 * GetDpiForSystem (USER32.@)
709 UINT WINAPI GetDpiForSystem(void)
711 if (!IsProcessDPIAware()) return USER_DEFAULT_SCREEN_DPI;
712 return system_dpi;
715 /**********************************************************************
716 * GetThreadDpiAwarenessContext (USER32.@)
718 DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext(void)
720 struct ntuser_thread_info *info = NtUserGetThreadInfo();
722 if (info->dpi_awareness) return ULongToHandle( info->dpi_awareness );
723 return UlongToHandle( (NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) & 3 ) | 0x10 );
726 /**********************************************************************
727 * SetThreadDpiAwarenessContext (USER32.@)
729 DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT context )
731 struct ntuser_thread_info *info = NtUserGetThreadInfo();
732 DPI_AWARENESS prev, val = GetAwarenessFromDpiAwarenessContext( context );
734 if (val == DPI_AWARENESS_INVALID)
736 SetLastError( ERROR_INVALID_PARAMETER );
737 return 0;
739 if (!(prev = info->dpi_awareness))
741 prev = NtUserGetProcessDpiAwarenessContext( GetCurrentProcess() ) & 3;
742 prev |= 0x80000010; /* restore to process default */
744 if (((ULONG_PTR)context & ~(ULONG_PTR)0x13) == 0x80000000) info->dpi_awareness = 0;
745 else info->dpi_awareness = val | 0x10;
746 return ULongToHandle( prev );
749 /***********************************************************************
750 * MonitorFromRect (USER32.@)
752 HMONITOR WINAPI MonitorFromRect( const RECT *rect, DWORD flags )
754 return NtUserMonitorFromRect( rect, flags );
757 /***********************************************************************
758 * MonitorFromPoint (USER32.@)
760 HMONITOR WINAPI MonitorFromPoint( POINT pt, DWORD flags )
762 RECT rect;
764 SetRect( &rect, pt.x, pt.y, pt.x + 1, pt.y + 1 );
765 return MonitorFromRect( &rect, flags );
768 /***********************************************************************
769 * MonitorFromWindow (USER32.@)
771 HMONITOR WINAPI MonitorFromWindow( HWND hwnd, DWORD flags )
773 return NtUserMonitorFromWindow( hwnd, flags );
776 /***********************************************************************
777 * GetMonitorInfoA (USER32.@)
779 BOOL WINAPI GetMonitorInfoA( HMONITOR monitor, LPMONITORINFO info )
781 MONITORINFOEXW miW;
782 BOOL ret;
784 if (info->cbSize == sizeof(MONITORINFO)) return GetMonitorInfoW( monitor, info );
785 if (info->cbSize != sizeof(MONITORINFOEXA)) return FALSE;
787 miW.cbSize = sizeof(miW);
788 ret = GetMonitorInfoW( monitor, (MONITORINFO *)&miW );
789 if (ret)
791 MONITORINFOEXA *miA = (MONITORINFOEXA *)info;
792 miA->rcMonitor = miW.rcMonitor;
793 miA->rcWork = miW.rcWork;
794 miA->dwFlags = miW.dwFlags;
795 WideCharToMultiByte(CP_ACP, 0, miW.szDevice, -1, miA->szDevice, sizeof(miA->szDevice), NULL, NULL);
797 return ret;
800 /***********************************************************************
801 * GetMonitorInfoW (USER32.@)
803 BOOL WINAPI GetMonitorInfoW( HMONITOR monitor, LPMONITORINFO info )
805 return NtUserGetMonitorInfo( monitor, info );
808 #ifdef __i386__
809 /* Some apps pass a non-stdcall callback to EnumDisplayMonitors,
810 * so we need a small assembly wrapper to call it.
812 extern BOOL enum_mon_callback_wrapper( void *proc, HMONITOR monitor, HDC hdc, RECT *rect, LPARAM lparam );
813 __ASM_GLOBAL_FUNC( enum_mon_callback_wrapper,
814 "pushl %ebp\n\t"
815 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
816 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
817 "movl %esp,%ebp\n\t"
818 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
819 "subl $8,%esp\n\t"
820 "pushl 24(%ebp)\n\t" /* lparam */
821 /* MJ's Help Diagnostic expects that %ecx contains the address to the rect. */
822 "movl 20(%ebp),%ecx\n\t" /* rect */
823 "pushl %ecx\n\t"
824 "pushl 16(%ebp)\n\t" /* hdc */
825 "pushl 12(%ebp)\n\t" /* monitor */
826 "movl 8(%ebp),%eax\n" /* proc */
827 "call *%eax\n\t"
828 "leave\n\t"
829 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
830 __ASM_CFI(".cfi_same_value %ebp\n\t")
831 "ret" )
832 #endif /* __i386__ */
834 BOOL WINAPI User32CallEnumDisplayMonitor( struct enum_display_monitor_params *params, ULONG size )
836 #ifdef __i386__
837 return enum_mon_callback_wrapper( params->proc, params->monitor, params->hdc,
838 &params->rect, params->lparam );
839 #else
840 return params->proc( params->monitor, params->hdc, &params->rect, params->lparam );
841 #endif
844 /***********************************************************************
845 * EnumDisplayDevicesA (USER32.@)
847 BOOL WINAPI EnumDisplayDevicesA( LPCSTR device, DWORD index, DISPLAY_DEVICEA *info, DWORD flags )
849 UNICODE_STRING deviceW;
850 DISPLAY_DEVICEW ddW;
851 BOOL ret;
853 if (device)
854 RtlCreateUnicodeStringFromAsciiz( &deviceW, device );
855 else
856 deviceW.Buffer = NULL;
858 ddW.cb = sizeof(ddW);
859 ret = EnumDisplayDevicesW( deviceW.Buffer, index, &ddW, flags );
860 RtlFreeUnicodeString( &deviceW );
862 if (!ret)
863 return ret;
865 WideCharToMultiByte( CP_ACP, 0, ddW.DeviceName, -1, info->DeviceName, sizeof(info->DeviceName), NULL, NULL );
866 WideCharToMultiByte( CP_ACP, 0, ddW.DeviceString, -1, info->DeviceString, sizeof(info->DeviceString), NULL, NULL );
867 info->StateFlags = ddW.StateFlags;
869 if (info->cb >= offsetof(DISPLAY_DEVICEA, DeviceID) + sizeof(info->DeviceID))
870 WideCharToMultiByte( CP_ACP, 0, ddW.DeviceID, -1, info->DeviceID, sizeof(info->DeviceID), NULL, NULL );
871 if (info->cb >= offsetof(DISPLAY_DEVICEA, DeviceKey) + sizeof(info->DeviceKey))
872 WideCharToMultiByte( CP_ACP, 0, ddW.DeviceKey, -1, info->DeviceKey, sizeof(info->DeviceKey), NULL, NULL );
874 return TRUE;
877 /***********************************************************************
878 * EnumDisplayDevicesW (USER32.@)
880 BOOL WINAPI EnumDisplayDevicesW( LPCWSTR device, DWORD index, DISPLAY_DEVICEW *info, DWORD flags )
882 UNICODE_STRING str;
883 RtlInitUnicodeString( &str, device );
884 return NT_SUCCESS(NtUserEnumDisplayDevices( &str, index, info, flags ));
887 /**********************************************************************
888 * GetAutoRotationState [USER32.@]
890 BOOL WINAPI GetAutoRotationState( AR_STATE *state )
892 TRACE("(%p)\n", state);
894 if (!state)
896 SetLastError(ERROR_INVALID_PARAMETER);
897 return FALSE;
900 *state = AR_NOSENSOR;
901 return TRUE;
904 /**********************************************************************
905 * GetDisplayAutoRotationPreferences [USER32.@]
907 BOOL WINAPI GetDisplayAutoRotationPreferences( ORIENTATION_PREFERENCE *orientation )
909 FIXME("(%p): stub\n", orientation);
910 *orientation = ORIENTATION_PREFERENCE_NONE;
911 return TRUE;
914 /* physical<->logical mapping functions from win8 that are nops in later versions */
916 /***********************************************************************
917 * GetPhysicalCursorPos (USER32.@)
919 BOOL WINAPI GetPhysicalCursorPos( POINT *point )
921 return GetCursorPos( point );
924 /***********************************************************************
925 * SetPhysicalCursorPos (USER32.@)
927 BOOL WINAPI SetPhysicalCursorPos( INT x, INT y )
929 return NtUserSetCursorPos( x, y );
932 /***********************************************************************
933 * WindowFromPhysicalPoint (USER32.@)
935 HWND WINAPI WindowFromPhysicalPoint( POINT pt )
937 return WindowFromPoint( pt );
940 /***********************************************************************
941 * LogicalToPhysicalPoint (USER32.@)
943 BOOL WINAPI LogicalToPhysicalPoint( HWND hwnd, POINT *point )
945 return TRUE;
948 /***********************************************************************
949 * PhysicalToLogicalPoint (USER32.@)
951 BOOL WINAPI PhysicalToLogicalPoint( HWND hwnd, POINT *point )
953 return TRUE;
956 /***********************************************************************
957 * DisplayConfigGetDeviceInfo (USER32.@)
959 LONG WINAPI DisplayConfigGetDeviceInfo(DISPLAYCONFIG_DEVICE_INFO_HEADER *packet)
961 return RtlNtStatusToDosError(NtUserDisplayConfigGetDeviceInfo(packet));
964 /***********************************************************************
965 * SetDisplayConfig (USER32.@)
967 LONG WINAPI SetDisplayConfig(UINT32 path_info_count, DISPLAYCONFIG_PATH_INFO *path_info, UINT32 mode_info_count,
968 DISPLAYCONFIG_MODE_INFO *mode_info, UINT32 flags)
970 FIXME("path_info_count %u, path_info %p, mode_info_count %u, mode_info %p, flags %#x stub.\n",
971 path_info_count, path_info, mode_info_count, mode_info, flags);
973 return ERROR_SUCCESS;