New files to support load order and partial stubs for elfdlls.
[wine/wine-kai.git] / windows / user.c
blob22dc18ff79e6b558cf183c73356bcb1da6cfa28f
1 /*
2 * Misc. USER functions
4 * Copyright 1993 Robert J. Amstadt
5 * 1996 Alex Korobka
6 */
8 #include <stdlib.h>
9 #include "wine/winbase16.h"
10 #include "winuser.h"
11 #include "heap.h"
12 #include "user.h"
13 #include "gdi.h"
14 #include "task.h"
15 #include "queue.h"
16 #include "win.h"
17 #include "clipboard.h"
18 #include "menu.h"
19 #include "cursoricon.h"
20 #include "hook.h"
21 #include "toolhelp.h"
22 #include "message.h"
23 #include "module.h"
24 #include "miscemu.h"
25 #include "shell.h"
26 #include "callback.h"
27 #include "local.h"
28 #include "class.h"
29 #include "desktop.h"
30 #include "process.h"
31 #include "debug.h"
33 /***********************************************************************
34 * GetFreeSystemResources (USER.284)
36 WORD WINAPI GetFreeSystemResources16( WORD resType )
38 int userPercent, gdiPercent;
40 switch(resType)
42 case GFSR_USERRESOURCES:
43 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
44 LOCAL_HeapSize( USER_HeapSel );
45 gdiPercent = 100;
46 break;
48 case GFSR_GDIRESOURCES:
49 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
50 LOCAL_HeapSize( GDI_HeapSel );
51 userPercent = 100;
52 break;
54 case GFSR_SYSTEMRESOURCES:
55 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
56 LOCAL_HeapSize( USER_HeapSel );
57 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
58 LOCAL_HeapSize( GDI_HeapSel );
59 break;
61 default:
62 return 0;
64 return (WORD)MIN( userPercent, gdiPercent );
68 /***********************************************************************
69 * SystemHeapInfo (TOOLHELP.71)
71 BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
73 pHeapInfo->wUserFreePercent = GetFreeSystemResources16( GFSR_USERRESOURCES );
74 pHeapInfo->wGDIFreePercent = GetFreeSystemResources16( GFSR_GDIRESOURCES );
75 pHeapInfo->hUserSegment = USER_HeapSel;
76 pHeapInfo->hGDISegment = GDI_HeapSel;
77 return TRUE;
81 /***********************************************************************
82 * TimerCount (TOOLHELP.80)
84 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
86 /* FIXME
87 * In standard mode, dwmsSinceStart = dwmsThisVM
89 * I tested this, under Windows in enhanced mode, and
90 * if you never switch VM (ie start/stop DOS) these
91 * values should be the same as well.
93 * Also, Wine should adjust for the hardware timer
94 * to reduce the amount of error to ~1ms.
95 * I can't be bothered, can you?
97 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
98 return TRUE;
101 /**********************************************************************
102 * InitApp (USER.5)
104 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
106 /* Hack: restore the divide-by-zero handler */
107 /* FIXME: should set a USER-specific handler that displays a msg box */
108 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
110 /* Create task message queue */
111 if ( !GetFastQueue16() ) return 0;
113 return 1;
116 /**********************************************************************
117 * USER_ModuleUnload
119 static void USER_ModuleUnload( HMODULE16 hModule )
121 HOOK_FreeModuleHooks( hModule );
122 CLASS_FreeModuleClasses( hModule );
123 CURSORICON_FreeModuleIcons( hModule );
126 /**********************************************************************
127 * USER_QueueCleanup
129 static void USER_QueueCleanup( HQUEUE16 hQueue )
131 if ( hQueue )
133 WND* desktop = WIN_GetDesktop();
135 /* Patch desktop window */
136 if ( desktop->hmemTaskQ == hQueue )
138 HTASK16 nextTask = TASK_GetNextTask( GetCurrentTask() );
139 desktop->hmemTaskQ = GetTaskQueue16( nextTask );
142 /* Patch resident popup menu window */
143 MENU_PatchResidentPopup( hQueue, NULL );
145 TIMER_RemoveQueueTimers( hQueue );
147 HOOK_FreeQueueHooks( hQueue );
149 QUEUE_SetExitingQueue( hQueue );
150 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
151 CLIPBOARD_ResetLock( hQueue, 0 );
152 QUEUE_SetExitingQueue( 0 );
154 /* Free the message queue */
155 QUEUE_DeleteMsgQueue( hQueue );
157 WIN_ReleaseDesktop();
161 /**********************************************************************
162 * USER_AppExit
164 static void USER_AppExit( HINSTANCE16 hInstance )
166 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
167 * only complains about them but does nothing);
170 /* ModuleUnload() in "Internals" */
172 hInstance = GetExePtr( hInstance );
173 if( GetModuleUsage16( hInstance ) <= 1 )
174 USER_ModuleUnload( hInstance );
178 /***********************************************************************
179 * USER_ExitWindows
181 * Clean-up everything and exit the Wine process.
182 * This is the back-end of ExitWindows(), called when all windows
183 * have agreed to be terminated.
185 void USER_ExitWindows(void)
187 /* Do the clean-up stuff */
189 WriteOutProfiles16();
190 SHELL_SaveRegistry();
192 exit(0);
196 /***********************************************************************
197 * USER_SignalProc (USER.314)
199 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
200 UINT16 uExitFn, HINSTANCE16 hInstance,
201 HQUEUE16 hQueue )
203 FIXME( win, "Win 3.1 USER signal %04x\n", uCode );
206 /***********************************************************************
207 * UserSignalProc (USER.610) (USER32.559)
209 * For comments about the meaning of uCode and dwFlags
210 * see PROCESS_CallUserSignalProc.
213 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
214 DWORD dwFlags, HMODULE16 hModule )
216 HINSTANCE16 hInst;
218 /* FIXME: Proper reaction to most signals still missing. */
220 switch ( uCode )
222 case USIG_DLL_UNLOAD_WIN16:
223 case USIG_DLL_UNLOAD_WIN32:
224 USER_ModuleUnload( hModule );
225 break;
227 case USIG_DLL_UNLOAD_ORPHANS:
228 break;
230 case USIG_FAULT_DIALOG_PUSH:
231 case USIG_FAULT_DIALOG_POP:
232 break;
234 case USIG_THREAD_INIT:
235 break;
237 case USIG_THREAD_EXIT:
238 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID ) );
239 SetThreadQueue16( dwThreadOrProcessID, 0 );
240 break;
242 case USIG_PROCESS_CREATE:
243 case USIG_PROCESS_INIT:
244 case USIG_PROCESS_LOADED:
245 case USIG_PROCESS_RUNNING:
246 break;
248 case USIG_PROCESS_EXIT:
249 break;
251 case USIG_PROCESS_DESTROY:
252 hInst = GetProcessDword( dwThreadOrProcessID, GPD_HINSTANCE16 );
253 USER_AppExit( hInst );
254 break;
256 default:
257 FIXME( win, "(%04x, %08lx, %04lx, %04x)\n",
258 uCode, dwThreadOrProcessID, dwFlags, hModule );
259 break;
262 /* FIXME: Should chain to GdiSignalProc now. */
264 return 0;
269 /***********************************************************************
270 * ExitWindows16 (USER.7)
272 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
274 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
278 /***********************************************************************
279 * ExitWindowsExec16 (USER.246)
281 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
283 TRACE(system, "Should run the following in DOS-mode: \"%s %s\"\n",
284 lpszExe, lpszParams);
285 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
289 /***********************************************************************
290 * ExitWindowsEx (USER32.196)
292 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
294 int i;
295 BOOL result;
296 WND **list, **ppWnd;
298 /* We have to build a list of all windows first, as in EnumWindows */
300 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
302 WIN_ReleaseDesktop();
303 return FALSE;
306 /* Send a WM_QUERYENDSESSION message to every window */
308 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
310 /* Make sure that the window still exists */
311 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
312 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
313 break;
315 result = !(*ppWnd);
317 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
319 for (ppWnd = list; i > 0; i--, ppWnd++)
321 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
322 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
324 WIN_ReleaseWinArray(list);
326 if (result) USER_ExitWindows();
327 WIN_ReleaseDesktop();
328 return FALSE;
332 /***********************************************************************
333 * ChangeDisplaySettingA (USER32.589)
335 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
337 FIXME(system, ": stub\n");
338 if (devmode==NULL)
339 FIXME(system," devmode=NULL (return to default mode)\n");
340 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
341 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
342 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
346 if (devmode->dmFields & DM_BITSPERPEL)
347 FIXME(system," bpp=%ld\n",devmode->dmBitsPerPel);
348 if (devmode->dmFields & DM_PELSWIDTH)
349 FIXME(system," width=%ld\n",devmode->dmPelsWidth);
350 if (devmode->dmFields & DM_PELSHEIGHT)
351 FIXME(system," height=%ld\n",devmode->dmPelsHeight);
352 FIXME(system," (Putting X in this mode beforehand might help)\n");
353 /* we don't, but the program ... does not need to know */
354 return DISP_CHANGE_SUCCESSFUL;
356 return DISP_CHANGE_SUCCESSFUL;
359 /***********************************************************************
360 * EnumDisplaySettingsA (USER32.592)
361 * FIXME: Currently uses static list of modes.
363 * RETURNS
364 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
365 * FALSE if we do not have the nth setting
367 BOOL WINAPI EnumDisplaySettingsA(
368 LPCSTR name, /* [in] huh? */
369 DWORD n, /* [in] nth entry in display settings list*/
370 LPDEVMODEA devmode /* [out] devmode for that setting */
372 #define NRMODES 5
373 #define NRDEPTHS 4
374 struct {
375 int w,h;
376 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
377 int depths[4] = {8,16,24,32};
379 TRACE(system,"(%s,%ld,%p)\n",name,n,devmode);
380 if (n==0) {
381 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
382 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
383 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
384 return TRUE;
386 if ((n-1)<NRMODES*NRDEPTHS) {
387 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
388 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
389 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
390 return TRUE;
392 return FALSE;
395 /***********************************************************************
396 * EnumDisplaySettingsW (USER32.593)
398 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) {
399 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
400 DEVMODEA devmodeA;
401 BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
403 if (ret) {
404 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
405 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
406 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
407 /* FIXME: convert rest too, if they are ever returned */
409 HeapFree(GetProcessHeap(),0,nameA);
410 return ret;
413 /***********************************************************************
414 * SetEventHook (USER.321)
416 * Used by Turbo Debugger for Windows
418 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
420 FIXME(hook, "(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
421 return NULL;
424 /***********************************************************************
425 * UserSeeUserDo (USER.216)
427 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
429 switch (wReqType)
431 case USUD_LOCALALLOC:
432 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
433 case USUD_LOCALFREE:
434 return LOCAL_Free(USER_HeapSel, wParam1);
435 case USUD_LOCALCOMPACT:
436 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
437 case USUD_LOCALHEAP:
438 return USER_HeapSel;
439 case USUD_FIRSTCLASS:
440 FIXME(local, "return a pointer to the first window class.\n");
441 return (DWORD)-1;
442 default:
443 WARN(local, "wReqType %04x (unknown)", wReqType);
444 return (DWORD)-1;
448 /***********************************************************************
449 * RegisterLogonProcess (USER32.434)
451 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
452 FIXME(win32,"(%d,%d),stub!\n",hprocess,x);
453 return 1;
456 /***********************************************************************
457 * CreateWindowStation32W (USER32.86)
459 HWINSTA WINAPI CreateWindowStationW(
460 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
461 LPSECURITY_ATTRIBUTES lpsa
463 FIXME(win32,"(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
464 res1,desiredaccess,lpsa
466 return 0xdeadcafe;
469 /***********************************************************************
470 * SetProcessWindowStation (USER32.496)
472 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
473 FIXME(win32,"(%d),stub!\n",hWinSta);
474 return TRUE;
477 /***********************************************************************
478 * SetUserObjectSecurity (USER32.514)
480 BOOL WINAPI SetUserObjectSecurity(
481 HANDLE hObj,
482 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
483 PSECURITY_DESCRIPTOR pSID
485 FIXME(win32,"(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
486 return TRUE;
489 /***********************************************************************
490 * CreateDesktop32W (USER32.69)
492 HDESK WINAPI CreateDesktopW(
493 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
494 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
496 FIXME(win32,"(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
497 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
498 dwFlags,dwDesiredAccess,lpsa
500 return 0xcafedead;
503 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
505 FIXME(win32, "(0x%08x)\n", hWinSta);
506 return TRUE;
508 BOOL WINAPI CloseDesktop(HDESK hDesk)
510 FIXME(win32, "(0x%08x)\n", hDesk);
511 return TRUE;
514 /***********************************************************************
515 * SetWindowStationUser (USER32.521)
517 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
518 FIXME(win32,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
519 return 1;
522 /***********************************************************************
523 * SetLogonNotifyWindow (USER32.486)
525 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
526 FIXME(win32,"(0x%x,%04x),stub!\n",hwinsta,hwnd);
527 return 1;
530 /***********************************************************************
531 * LoadLocalFonts (USER32.486)
533 VOID WINAPI LoadLocalFonts(VOID) {
534 /* are loaded. */
535 return;
537 /***********************************************************************
538 * GetUserObjectInformation32A (USER32.299)
540 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
541 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
542 return TRUE;
544 /***********************************************************************
545 * GetUserObjectInformation32W (USER32.300)
547 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
548 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
549 return TRUE;
551 /***********************************************************************
552 * GetUserObjectSecurity32 (USER32.300)
554 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, SECURITY_INFORMATION * pSIRequested,
555 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
556 { FIXME(win32,"(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
557 return TRUE;
560 /***********************************************************************
561 * SetSystemCursor (USER32.507)
563 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
564 { FIXME(win32,"(%08x,%08lx),stub!\n", hcur, id);
565 return TRUE;
568 /***********************************************************************
569 * RegisterSystemThread (USER32.435)
571 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
573 FIXME(win32, "(%08lx, %08lx)\n", flags, reserved);