quartz: Add a cleanup callback for parser filters to call on release.
[wine.git] / dlls / user32 / misc.c
blobbd1c9f7c0f11142658296d63ff36896c9608bb5c
1 /*
2 * Misc USER functions
4 * Copyright 1995 Thomas Sandford
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998 Turchanov Sergey
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "wine/windef16.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "winternl.h"
32 #include "user_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(win);
39 /* USER signal proc flags and codes */
40 /* See UserSignalProc for comments */
41 #define USIG_FLAGS_WIN32 0x0001
42 #define USIG_FLAGS_GUI 0x0002
43 #define USIG_FLAGS_FEEDBACK 0x0004
44 #define USIG_FLAGS_FAULT 0x0008
46 #define USIG_DLL_UNLOAD_WIN16 0x0001
47 #define USIG_DLL_UNLOAD_WIN32 0x0002
48 #define USIG_FAULT_DIALOG_PUSH 0x0003
49 #define USIG_FAULT_DIALOG_POP 0x0004
50 #define USIG_DLL_UNLOAD_ORPHANS 0x0005
51 #define USIG_THREAD_INIT 0x0010
52 #define USIG_THREAD_EXIT 0x0020
53 #define USIG_PROCESS_CREATE 0x0100
54 #define USIG_PROCESS_INIT 0x0200
55 #define USIG_PROCESS_EXIT 0x0300
56 #define USIG_PROCESS_DESTROY 0x0400
57 #define USIG_PROCESS_RUNNING 0x0500
58 #define USIG_PROCESS_LOADED 0x0600
60 /***********************************************************************
61 * SignalProc32 (USER.391)
62 * UserSignalProc (USER32.@)
64 * The exact meaning of the USER signals is undocumented, but this
65 * should cover the basic idea:
67 * USIG_DLL_UNLOAD_WIN16
68 * This is sent when a 16-bit module is unloaded.
70 * USIG_DLL_UNLOAD_WIN32
71 * This is sent when a 32-bit module is unloaded.
73 * USIG_DLL_UNLOAD_ORPHANS
74 * This is sent after the last Win3.1 module is unloaded,
75 * to allow removal of orphaned menus.
77 * USIG_FAULT_DIALOG_PUSH
78 * USIG_FAULT_DIALOG_POP
79 * These are called to allow USER to prepare for displaying a
80 * fault dialog, even though the fault might have happened while
81 * inside a USER critical section.
83 * USIG_THREAD_INIT
84 * This is called from the context of a new thread, as soon as it
85 * has started to run.
87 * USIG_THREAD_EXIT
88 * This is called, still in its context, just before a thread is
89 * about to terminate.
91 * USIG_PROCESS_CREATE
92 * This is called, in the parent process context, after a new process
93 * has been created.
95 * USIG_PROCESS_INIT
96 * This is called in the new process context, just after the main thread
97 * has started execution (after the main thread's USIG_THREAD_INIT has
98 * been sent).
100 * USIG_PROCESS_LOADED
101 * This is called after the executable file has been loaded into the
102 * new process context.
104 * USIG_PROCESS_RUNNING
105 * This is called immediately before the main entry point is called.
107 * USIG_PROCESS_EXIT
108 * This is called in the context of a process that is about to
109 * terminate (but before the last thread's USIG_THREAD_EXIT has
110 * been sent).
112 * USIG_PROCESS_DESTROY
113 * This is called after a process has terminated.
116 * The meaning of the dwFlags bits is as follows:
118 * USIG_FLAGS_WIN32
119 * Current process is 32-bit.
121 * USIG_FLAGS_GUI
122 * Current process is a (Win32) GUI process.
124 * USIG_FLAGS_FEEDBACK
125 * Current process needs 'feedback' (determined from the STARTUPINFO
126 * flags STARTF_FORCEONFEEDBACK / STARTF_FORCEOFFFEEDBACK).
128 * USIG_FLAGS_FAULT
129 * The signal is being sent due to a fault.
131 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
132 DWORD dwFlags, HMODULE16 hModule )
134 FIXME("(%04x, %08x, %04x, %04x)\n",
135 uCode, dwThreadOrProcessID, dwFlags, hModule );
136 /* FIXME: Should chain to GdiSignalProc now. */
137 return 0;
141 /**********************************************************************
142 * SetLastErrorEx [USER32.@]
144 * Sets the last-error code.
146 * RETURNS
147 * None.
149 void WINAPI SetLastErrorEx(
150 DWORD error, /* [in] Per-thread error code */
151 DWORD type) /* [in] Error type */
153 TRACE("(0x%08x, 0x%08x)\n", error,type);
154 switch(type) {
155 case 0:
156 break;
157 case SLE_ERROR:
158 case SLE_MINORERROR:
159 case SLE_WARNING:
160 /* Fall through for now */
161 default:
162 FIXME("(error=%08x, type=%08x): Unhandled type\n", error,type);
163 break;
165 SetLastError( error );
168 /******************************************************************************
169 * GetAltTabInfoA [USER32.@]
171 BOOL WINAPI GetAltTabInfoA(HWND hwnd, int iItem, PALTTABINFO pati, LPSTR pszItemText, UINT cchItemText)
173 FIXME("(%p, 0x%08x, %p, %p, 0x%08x)\n", hwnd, iItem, pati, pszItemText, cchItemText);
174 return FALSE;
177 /******************************************************************************
178 * GetAltTabInfoW [USER32.@]
180 BOOL WINAPI GetAltTabInfoW(HWND hwnd, int iItem, PALTTABINFO pati, LPWSTR pszItemText, UINT cchItemText)
182 FIXME("(%p, 0x%08x, %p, %p, 0x%08x)\n", hwnd, iItem, pati, pszItemText, cchItemText);
183 return FALSE;
186 /******************************************************************************
187 * SetDebugErrorLevel [USER32.@]
188 * Sets the minimum error level for generating debugging events
190 * PARAMS
191 * dwLevel [I] Debugging error level
193 * RETURNS
194 * Nothing.
196 VOID WINAPI SetDebugErrorLevel( DWORD dwLevel )
198 FIXME("(%d): stub\n", dwLevel);
202 /******************************************************************************
203 * GetProcessDefaultLayout [USER32.@]
205 * Gets the default layout for parentless windows.
206 * Right now, just returns 0 (left-to-right).
208 * RETURNS
209 * Success: Nonzero
210 * Failure: Zero
212 * BUGS
213 * No RTL
215 BOOL WINAPI GetProcessDefaultLayout( DWORD *pdwDefaultLayout )
217 if ( !pdwDefaultLayout ) {
218 SetLastError( ERROR_INVALID_PARAMETER );
219 return FALSE;
221 FIXME( "( %p ): No BiDi\n", pdwDefaultLayout );
222 *pdwDefaultLayout = 0;
223 return TRUE;
227 /******************************************************************************
228 * SetProcessDefaultLayout [USER32.@]
230 * Sets the default layout for parentless windows.
231 * Right now, only accepts 0 (left-to-right).
233 * RETURNS
234 * Success: Nonzero
235 * Failure: Zero
237 * BUGS
238 * No RTL
240 BOOL WINAPI SetProcessDefaultLayout( DWORD dwDefaultLayout )
242 if ( dwDefaultLayout == 0 )
243 return TRUE;
244 FIXME( "( %08x ): No BiDi\n", dwDefaultLayout );
245 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
246 return FALSE;
250 /***********************************************************************
251 * SetWindowStationUser (USER32.@)
253 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2)
255 FIXME("(0x%08x,0x%08x),stub!\n",x1,x2);
256 return 1;
259 /***********************************************************************
260 * RegisterLogonProcess (USER32.@)
262 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x)
264 FIXME("(%p,%d),stub!\n",hprocess,x);
265 return 1;
268 /***********************************************************************
269 * SetLogonNotifyWindow (USER32.@)
271 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd)
273 FIXME("(%p,%p),stub!\n",hwinsta,hwnd);
274 return 1;
277 static const WCHAR primary_device_name[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0};
278 static const WCHAR primary_device_string[] = {'X','1','1',' ','W','i','n','d','o','w','i','n','g',' ',
279 'S','y','s','t','e','m',0};
281 /***********************************************************************
282 * EnumDisplayDevicesA (USER32.@)
284 BOOL WINAPI EnumDisplayDevicesA( LPCSTR lpDevice, DWORD i, LPDISPLAY_DEVICEA lpDispDev,
285 DWORD dwFlags )
287 UNICODE_STRING deviceW;
288 DISPLAY_DEVICEW ddW;
289 BOOL ret;
291 if(lpDevice)
292 RtlCreateUnicodeStringFromAsciiz(&deviceW, lpDevice);
293 else
294 deviceW.Buffer = NULL;
296 ddW.cb = sizeof(ddW);
297 ret = EnumDisplayDevicesW(deviceW.Buffer, i, &ddW, dwFlags);
298 RtlFreeUnicodeString(&deviceW);
300 if(!ret) return ret;
302 WideCharToMultiByte(CP_ACP, 0, ddW.DeviceName, -1, lpDispDev->DeviceName, sizeof(lpDispDev->DeviceName), NULL, NULL);
303 WideCharToMultiByte(CP_ACP, 0, ddW.DeviceString, -1, lpDispDev->DeviceString, sizeof(lpDispDev->DeviceString), NULL, NULL);
304 lpDispDev->StateFlags = ddW.StateFlags;
306 if(lpDispDev->cb >= offsetof(DISPLAY_DEVICEA, DeviceID) + sizeof(lpDispDev->DeviceID))
307 WideCharToMultiByte(CP_ACP, 0, ddW.DeviceID, -1, lpDispDev->DeviceID, sizeof(lpDispDev->DeviceID), NULL, NULL);
308 if(lpDispDev->cb >= offsetof(DISPLAY_DEVICEA, DeviceKey) + sizeof(lpDispDev->DeviceKey))
309 WideCharToMultiByte(CP_ACP, 0, ddW.DeviceKey, -1, lpDispDev->DeviceKey, sizeof(lpDispDev->DeviceKey), NULL, NULL);
311 return TRUE;
314 /***********************************************************************
315 * EnumDisplayDevicesW (USER32.@)
317 BOOL WINAPI EnumDisplayDevicesW( LPCWSTR lpDevice, DWORD i, LPDISPLAY_DEVICEW lpDisplayDevice,
318 DWORD dwFlags )
320 FIXME("(%s,%d,%p,0x%08x), stub!\n",debugstr_w(lpDevice),i,lpDisplayDevice,dwFlags);
322 if (i)
323 return FALSE;
325 memcpy(lpDisplayDevice->DeviceName, primary_device_name, sizeof(primary_device_name));
326 memcpy(lpDisplayDevice->DeviceString, primary_device_string, sizeof(primary_device_string));
328 lpDisplayDevice->StateFlags =
329 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
330 DISPLAY_DEVICE_PRIMARY_DEVICE |
331 DISPLAY_DEVICE_VGA_COMPATIBLE;
333 if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceID) + sizeof(lpDisplayDevice->DeviceID))
334 lpDisplayDevice->DeviceID[0] = 0;
335 if(lpDisplayDevice->cb >= offsetof(DISPLAY_DEVICEW, DeviceKey) + sizeof(lpDisplayDevice->DeviceKey))
336 lpDisplayDevice->DeviceKey[0] = 0;
338 return TRUE;
341 struct monitor_enum_info
343 RECT rect;
344 UINT max_area;
345 UINT min_distance;
346 HMONITOR primary;
347 HMONITOR ret;
350 /* helper callback for MonitorFromRect */
351 static BOOL CALLBACK monitor_enum( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
353 struct monitor_enum_info *info = (struct monitor_enum_info *)lp;
354 RECT intersect;
356 if (IntersectRect( &intersect, rect, &info->rect ))
358 /* check for larger intersecting area */
359 UINT area = (intersect.right - intersect.left) * (intersect.bottom - intersect.top);
360 if (area > info->max_area)
362 info->max_area = area;
363 info->ret = monitor;
366 else if (!info->max_area) /* if not intersecting, check for min distance */
368 UINT distance;
369 INT x, y;
371 if (rect->left >= info->rect.right) x = info->rect.right - rect->left;
372 else x = rect->right - info->rect.left;
373 if (rect->top >= info->rect.bottom) y = info->rect.bottom - rect->top;
374 else y = rect->bottom - info->rect.top;
375 distance = x * x + y * y;
376 if (distance < info->min_distance)
378 info->min_distance = distance;
379 info->ret = monitor;
382 if (!info->primary)
384 MONITORINFO mon_info;
385 mon_info.cbSize = sizeof(mon_info);
386 GetMonitorInfoW( monitor, &mon_info );
387 if (mon_info.dwFlags & MONITORINFOF_PRIMARY) info->primary = monitor;
389 return TRUE;
392 /***********************************************************************
393 * MonitorFromRect (USER32.@)
395 HMONITOR WINAPI MonitorFromRect( LPRECT rect, DWORD flags )
397 struct monitor_enum_info info;
399 /* make sure the desktop window exists */
400 GetDesktopWindow();
402 info.rect = *rect;
403 info.max_area = 0;
404 info.min_distance = ~0u;
405 info.primary = 0;
406 info.ret = 0;
407 if (!EnumDisplayMonitors( 0, NULL, monitor_enum, (LPARAM)&info )) return 0;
408 if (!info.ret && (flags & MONITOR_DEFAULTTOPRIMARY)) info.ret = info.primary;
410 TRACE( "%s flags %x returning %p\n", wine_dbgstr_rect(rect), flags, info.ret );
411 return info.ret;
414 /***********************************************************************
415 * MonitorFromPoint (USER32.@)
417 HMONITOR WINAPI MonitorFromPoint( POINT pt, DWORD flags )
419 RECT rect;
421 SetRect( &rect, pt.x, pt.y, pt.x + 1, pt.y + 1 );
422 return MonitorFromRect( &rect, flags );
425 /***********************************************************************
426 * MonitorFromWindow (USER32.@)
428 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
430 RECT rect;
431 WINDOWPLACEMENT wp;
433 if (IsIconic(hWnd) && GetWindowPlacement(hWnd, &wp))
434 return MonitorFromRect( &wp.rcNormalPosition, dwFlags );
436 if (GetWindowRect( hWnd, &rect ))
437 return MonitorFromRect( &rect, dwFlags );
439 if (!(dwFlags & (MONITOR_DEFAULTTOPRIMARY|MONITOR_DEFAULTTONEAREST))) return 0;
440 /* retrieve the primary */
441 SetRect( &rect, 0, 0, 1, 1 );
442 return MonitorFromRect( &rect, dwFlags );
445 /***********************************************************************
446 * GetMonitorInfoA (USER32.@)
448 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
450 MONITORINFOEXW miW;
451 MONITORINFOEXA *miA = (MONITORINFOEXA*)lpMonitorInfo;
452 BOOL ret;
454 miW.cbSize = sizeof(miW);
456 ret = GetMonitorInfoW(hMonitor, (MONITORINFO*)&miW);
457 if(!ret) return ret;
459 miA->rcMonitor = miW.rcMonitor;
460 miA->rcWork = miW.rcWork;
461 miA->dwFlags = miW.dwFlags;
462 if(miA->cbSize >= offsetof(MONITORINFOEXA, szDevice) + sizeof(miA->szDevice))
463 WideCharToMultiByte(CP_ACP, 0, miW.szDevice, -1, miA->szDevice, sizeof(miA->szDevice), NULL, NULL);
464 return ret;
467 /***********************************************************************
468 * GetMonitorInfoW (USER32.@)
470 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
472 return USER_Driver->pGetMonitorInfo( hMonitor, lpMonitorInfo );
475 /***********************************************************************
476 * EnumDisplayMonitors (USER32.@)
478 BOOL WINAPI EnumDisplayMonitors( HDC hdc, LPRECT rect, MONITORENUMPROC proc, LPARAM lp )
480 return USER_Driver->pEnumDisplayMonitors( hdc, rect, proc, lp );
483 /***********************************************************************
484 * RegisterSystemThread (USER32.@)
486 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
488 FIXME("(%08x, %08x)\n", flags, reserved);
491 /***********************************************************************
492 * RegisterShellHookWindow [USER32.@]
494 BOOL WINAPI RegisterShellHookWindow ( HWND hWnd )
496 FIXME("(%p): stub\n", hWnd);
497 return 0;
501 /***********************************************************************
502 * DeregisterShellHookWindow [USER32.@]
504 HRESULT WINAPI DeregisterShellHookWindow ( DWORD u )
506 FIXME("0x%08x stub\n",u);
507 return 0;
512 /***********************************************************************
513 * RegisterTasklist [USER32.@]
515 DWORD WINAPI RegisterTasklist (DWORD x)
517 FIXME("0x%08x\n",x);
518 return TRUE;
522 /***********************************************************************
523 * RegisterDeviceNotificationA (USER32.@)
525 * See RegisterDeviceNotificationW.
527 HDEVNOTIFY WINAPI RegisterDeviceNotificationA(HANDLE hnd, LPVOID notifyfilter, DWORD flags)
529 FIXME("(hwnd=%p, filter=%p,flags=0x%08x),\n"
530 "\treturns a fake device notification handle!\n", hnd,notifyfilter,flags );
531 return (HDEVNOTIFY) 0xcafecafe;
534 /***********************************************************************
535 * RegisterDeviceNotificationW (USER32.@)
537 * Registers a window with the system so that it will receive
538 * notifications about a device.
540 * PARAMS
541 * hRecepient [I] Window or service status handle that
542 * will receive notifications.
543 * pNotificationFilter [I] DEV_BROADCAST_HDR followed by some
544 * type-specific data.
545 * dwFlags [I] See notes
547 * RETURNS
549 * A handle to the device notification.
551 * NOTES
553 * The dwFlags parameter can be one of two values:
554 *| DEVICE_NOTIFY_WINDOW_HANDLE - hRecepient is a window handle
555 *| DEVICE_NOTIFY_SERVICE_HANDLE - hRecepient is a service status handle
557 HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecepient, LPVOID pNotificationFilter, DWORD dwFlags)
559 FIXME("(hwnd=%p, filter=%p,flags=0x%08x), STUB!\n", hRecepient,pNotificationFilter,dwFlags );
560 return 0;
563 /***********************************************************************
564 * UnregisterDeviceNotification (USER32.@)
567 BOOL WINAPI UnregisterDeviceNotification(HDEVNOTIFY hnd)
569 FIXME("(handle=%p), STUB!\n", hnd);
570 return TRUE;
573 /***********************************************************************
574 * GetAppCompatFlags (USER32.@)
576 DWORD WINAPI GetAppCompatFlags( HTASK hTask )
578 FIXME("stub\n");
579 return 0;
583 /***********************************************************************
584 * AlignRects (USER32.@)
586 BOOL WINAPI AlignRects(LPRECT rect, DWORD b, DWORD c, DWORD d)
588 FIXME("(%p, %d, %d, %d): stub\n", rect, b, c, d);
589 if (rect)
590 FIXME("rect: [[%d, %d], [%d, %d]]\n", rect->left, rect->top, rect->right, rect->bottom);
591 /* Calls OffsetRect */
592 return FALSE;
596 /***********************************************************************
597 * LoadLocalFonts (USER32.@)
599 VOID WINAPI LoadLocalFonts(VOID)
601 /* are loaded. */
602 return;
606 /***********************************************************************
607 * USER_489 (USER.489)
609 LONG WINAPI stub_USER_489(void) { FIXME("stub\n"); return 0; }
611 /***********************************************************************
612 * USER_490 (USER.490)
614 LONG WINAPI stub_USER_490(void) { FIXME("stub\n"); return 0; }
616 /***********************************************************************
617 * USER_492 (USER.492)
619 LONG WINAPI stub_USER_492(void) { FIXME("stub\n"); return 0; }
621 /***********************************************************************
622 * USER_496 (USER.496)
624 LONG WINAPI stub_USER_496(void) { FIXME("stub\n"); return 0; }
626 /***********************************************************************
627 * User32InitializeImmEntryTable
629 BOOL WINAPI User32InitializeImmEntryTable(LPVOID ptr)
631 FIXME("(%p): stub\n", ptr);
632 return TRUE;
635 /**********************************************************************
636 * WINNLSGetIMEHotkey [USER32.@]
639 UINT WINAPI WINNLSGetIMEHotkey(HWND hUnknown1)
641 FIXME("hUnknown1 %p: stub!\n", hUnknown1);
642 return 0; /* unknown */
645 /**********************************************************************
646 * WINNLSEnableIME [USER32.@]
649 BOOL WINAPI WINNLSEnableIME(HWND hUnknown1, BOOL bUnknown2)
651 FIXME("hUnknown1 %p bUnknown2 %d: stub!\n", hUnknown1, bUnknown2);
652 return TRUE; /* success (?) */
655 /**********************************************************************
656 * WINNLSGetEnableStatus [USER32.@]
659 BOOL WINAPI WINNLSGetEnableStatus(HWND hUnknown1)
661 FIXME("hUnknown1 %p: stub!\n", hUnknown1);
662 return TRUE; /* success (?) */
665 /**********************************************************************
666 * SendIMEMessageExA [USER32.@]
669 LRESULT WINAPI SendIMEMessageExA(HWND p1, LPARAM p2)
671 FIXME("(%p,%lx): stub\n", p1, p2);
672 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
673 return 0;
676 /**********************************************************************
677 * SendIMEMessageExW [USER32.@]
680 LRESULT WINAPI SendIMEMessageExW(HWND p1, LPARAM p2)
682 FIXME("(%p,%lx): stub\n", p1, p2);
683 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
684 return 0;