Since SetParent now hides/shows, explicitly invalidating DCs in the
[wine/testsucceed.git] / windows / user.c
blob2dd940eb337adf37d8ef4072fb764684fff9e68f
1 /*
2 * Misc. USER functions
4 * Copyright 1993 Robert J. Amstadt
5 * 1996 Alex Korobka
6 */
8 #include <stdlib.h>
9 #include "windows.h"
10 #include "resource.h"
11 #include "heap.h"
12 #include "gdi.h"
13 #include "user.h"
14 #include "task.h"
15 #include "queue.h"
16 #include "win.h"
17 #include "clipboard.h"
18 #include "menu.h"
19 #include "hook.h"
20 #include "debug.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"
31 /***********************************************************************
32 * GetFreeSystemResources (USER.284)
34 WORD WINAPI GetFreeSystemResources( WORD resType )
36 int userPercent, gdiPercent;
38 switch(resType)
40 case GFSR_USERRESOURCES:
41 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
42 LOCAL_HeapSize( USER_HeapSel );
43 gdiPercent = 100;
44 break;
46 case GFSR_GDIRESOURCES:
47 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
48 LOCAL_HeapSize( GDI_HeapSel );
49 userPercent = 100;
50 break;
52 case GFSR_SYSTEMRESOURCES:
53 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
54 LOCAL_HeapSize( USER_HeapSel );
55 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
56 LOCAL_HeapSize( GDI_HeapSel );
57 break;
59 default:
60 return 0;
62 return (WORD)MIN( userPercent, gdiPercent );
66 /***********************************************************************
67 * SystemHeapInfo (TOOLHELP.71)
69 BOOL16 WINAPI SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
71 pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
72 pHeapInfo->wGDIFreePercent = GetFreeSystemResources( GFSR_GDIRESOURCES );
73 pHeapInfo->hUserSegment = USER_HeapSel;
74 pHeapInfo->hGDISegment = GDI_HeapSel;
75 return TRUE;
79 /***********************************************************************
80 * TimerCount (TOOLHELP.80)
82 BOOL16 WINAPI TimerCount( TIMERINFO *pTimerInfo )
84 /* FIXME
85 * In standard mode, dwmsSinceStart = dwmsThisVM
87 * I tested this, under Windows in enhanced mode, and
88 * if you never switch VM (ie start/stop DOS) these
89 * values should be the same as well.
91 * Also, Wine should adjust for the hardware timer
92 * to reduce the amount of error to ~1ms.
93 * I can't be bothered, can you?
95 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
96 return TRUE;
99 static FARPROC16 __r16loader = NULL;
101 /**********************************************************************
102 * USER_CallDefaultRsrcHandler
104 * Called by the LoadDIBIcon/CursorHandler().
106 HGLOBAL16 USER_CallDefaultRsrcHandler( HGLOBAL16 hMemObj, HMODULE16 hModule, HRSRC16 hRsrc )
108 return Callbacks->CallResourceHandlerProc( __r16loader, hMemObj, hModule, hRsrc );
111 /**********************************************************************
112 * USER_InstallRsrcHandler
114 static void USER_InstallRsrcHandler( HINSTANCE16 hInstance )
116 FARPROC16 proc;
118 /* SetResourceHandler() returns previous function which is set
119 * when a module's resource table is loaded. */
121 proc = SetResourceHandler( hInstance, RT_ICON16,
122 MODULE_GetWndProcEntry16("LoadDIBIconHandler") );
123 if (!__r16loader) __r16loader = proc;
125 proc = SetResourceHandler( hInstance, RT_CURSOR16,
126 MODULE_GetWndProcEntry16("LoadDIBCursorHandler") );
127 if (!__r16loader) __r16loader = proc;
130 /**********************************************************************
131 * InitApp (USER.5)
133 INT16 WINAPI InitApp( HINSTANCE16 hInstance )
135 /* InitTask() calls LibMain()'s of implicitly loaded DLLs
136 * prior to InitApp() so there is no clean way to do
137 * SetTaskSignalHandler() in time. So, broken Windows bypasses
138 * a pTask->userhandler on startup and simply calls a global
139 * function pointer to the default USER signal handler.
142 USER_InstallRsrcHandler( hInstance );
144 /* Hack: restore the divide-by-zero handler */
145 /* FIXME: should set a USER-specific handler that displays a msg box */
146 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
148 /* Create task message queue */
149 if ( !GetFastQueue() ) return 0;
151 return 1;
154 /**********************************************************************
155 * USER_ModuleUnload
157 static void USER_ModuleUnload( HMODULE16 hModule )
159 HOOK_FreeModuleHooks( hModule );
160 CLASS_FreeModuleClasses( hModule );
163 /**********************************************************************
164 * USER_QueueCleanup
166 void USER_QueueCleanup( HQUEUE16 hQueue )
168 if ( hQueue )
170 WND* desktop = WIN_GetDesktop();
172 /* Patch resident popup menu window */
173 MENU_PatchResidentPopup( hQueue, NULL );
175 TIMER_RemoveQueueTimers( hQueue );
177 QUEUE_FlushMessages( hQueue );
178 HOOK_FreeQueueHooks( hQueue );
180 QUEUE_SetExitingQueue( hQueue );
181 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
182 CLIPBOARD_ResetLock( hQueue, 0 );
183 QUEUE_SetExitingQueue( 0 );
185 /* Free the message queue */
186 QUEUE_DeleteMsgQueue( hQueue );
190 /**********************************************************************
191 * USER_AppExit
193 static void USER_AppExit( HTASK16 hTask, HINSTANCE16 hInstance, HQUEUE16 hQueue )
195 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
196 * only complains about them but does nothing);
199 WND* desktop = WIN_GetDesktop();
201 /* Patch desktop window */
202 if( desktop->hmemTaskQ == hQueue )
203 desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
205 USER_QueueCleanup(hQueue);
207 /* ModuleUnload() in "Internals" */
209 hInstance = GetExePtr( hInstance );
210 if( GetModuleUsage( hInstance ) <= 1 )
211 USER_ModuleUnload( hInstance );
215 /***********************************************************************
216 * USER_ExitWindows
218 * Clean-up everything and exit the Wine process.
219 * This is the back-end of ExitWindows(), called when all windows
220 * have agreed to be terminated.
222 void USER_ExitWindows(void)
224 /* Do the clean-up stuff */
226 WriteOutProfiles();
227 SHELL_SaveRegistry();
229 exit(0);
233 /***********************************************************************
234 * USER_SignalProc (USER.314)
236 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
237 UINT16 uExitFn, HINSTANCE16 hInstance,
238 HQUEUE16 hQueue )
240 switch( uCode )
242 case USIG_GPF:
243 case USIG_TERMINATION:
244 USER_AppExit( hTaskOrModule, hInstance, hQueue ); /* task */
245 break;
247 case USIG_DLL_LOAD:
248 USER_InstallRsrcHandler( hTaskOrModule ); /* module */
249 break;
251 case USIG_DLL_UNLOAD:
252 USER_ModuleUnload( hTaskOrModule ); /* module */
253 break;
255 default:
256 FIXME(msg,"Unimplemented USER signal: %i\n", (int)uCode );
261 /***********************************************************************
262 * ExitWindows16 (USER.7)
264 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
266 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
270 /***********************************************************************
271 * ExitWindowsExec16 (USER.246)
273 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
275 TRACE(system, "Should run the following in DOS-mode: \"%s %s\"\n",
276 lpszExe, lpszParams);
277 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
281 /***********************************************************************
282 * ExitWindowsEx (USER32.196)
284 BOOL32 WINAPI ExitWindowsEx( UINT32 flags, DWORD reserved )
286 int i;
287 BOOL32 result;
288 WND **list, **ppWnd;
290 /* We have to build a list of all windows first, as in EnumWindows */
292 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) return FALSE;
294 /* Send a WM_QUERYENDSESSION message to every window */
296 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
298 /* Make sure that the window still exists */
299 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
300 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
301 break;
303 result = !(*ppWnd);
305 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
307 for (ppWnd = list; i > 0; i--, ppWnd++)
309 if (!IsWindow32( (*ppWnd)->hwndSelf )) continue;
310 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
312 HeapFree( SystemHeap, 0, list );
314 if (result) USER_ExitWindows();
315 return FALSE;
319 /***********************************************************************
320 * ChangeDisplaySettingA (USER32.589)
322 LONG WINAPI ChangeDisplaySettings32A( LPDEVMODE32A devmode, DWORD flags )
324 FIXME(system, ": stub\n");
325 if (devmode==NULL)
326 FIXME(system," devmode=NULL (return to default mode)\n");
327 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
328 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
329 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
333 if (devmode->dmFields & DM_BITSPERPEL)
334 FIXME(system," bpp=%ld\n",devmode->dmBitsPerPel);
335 if (devmode->dmFields & DM_PELSWIDTH)
336 FIXME(system," width=%ld\n",devmode->dmPelsWidth);
337 if (devmode->dmFields & DM_PELSHEIGHT)
338 FIXME(system," height=%ld\n",devmode->dmPelsHeight);
339 FIXME(system," (Putting X in this mode beforehand might help)\n");
340 /* we don't, but the program ... does not need to know */
341 return DISP_CHANGE_SUCCESSFUL;
343 return DISP_CHANGE_SUCCESSFUL;
346 /***********************************************************************
347 * EnumDisplaySettingsA (USER32.592)
348 * FIXME: Currently uses static list of modes.
350 * RETURNS
351 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
352 * FALSE if we do not have the nth setting
354 BOOL32 WINAPI EnumDisplaySettings32A(
355 LPCSTR name, /* [in] huh? */
356 DWORD n, /* [in] nth entry in display settings list*/
357 LPDEVMODE32A devmode /* [out] devmode for that setting */
359 #define NRMODES 5
360 #define NRDEPTHS 4
361 struct {
362 int w,h;
363 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
364 int depths[4] = {8,16,24,32};
366 TRACE(system,"(%s,%ld,%p)\n",name,n,devmode);
367 if (n==0) {
368 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
369 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
370 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
371 return TRUE;
373 if ((n-1)<NRMODES*NRDEPTHS) {
374 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
375 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
376 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
377 return TRUE;
379 return FALSE;
382 /***********************************************************************
383 * EnumDisplaySettingsW (USER32.593)
385 BOOL32 WINAPI EnumDisplaySettings32W(LPCWSTR name,DWORD n,LPDEVMODE32W devmode) {
386 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
387 DEVMODE32A devmodeA;
388 BOOL32 ret = EnumDisplaySettings32A(nameA,n,&devmodeA);
390 if (ret) {
391 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
392 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
393 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
394 /* FIXME: convert rest too, if they are ever returned */
396 HeapFree(GetProcessHeap(),0,nameA);
397 return ret;
400 /***********************************************************************
401 * SetEventHook (USER.321)
403 * Used by Turbo Debugger for Windows
405 FARPROC16 WINAPI SetEventHook(FARPROC16 lpfnEventHook)
407 FIXME(hook, "(lpfnEventHook=%08x): stub\n", (UINT32)lpfnEventHook);
408 return NULL;
411 /***********************************************************************
412 * UserSeeUserDo (USER.216)
414 DWORD WINAPI UserSeeUserDo(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
416 switch (wReqType)
418 case USUD_LOCALALLOC:
419 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
420 case USUD_LOCALFREE:
421 return LOCAL_Free(USER_HeapSel, wParam1);
422 case USUD_LOCALCOMPACT:
423 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
424 case USUD_LOCALHEAP:
425 return USER_HeapSel;
426 case USUD_FIRSTCLASS:
427 FIXME(local, "return a pointer to the first window class.\n");
428 return (DWORD)-1;
429 default:
430 WARN(local, "wReqType %04x (unknown)", wReqType);
431 return (DWORD)-1;
435 /***********************************************************************
436 * RegisterLogonProcess (USER32.434)
438 DWORD WINAPI RegisterLogonProcess(HANDLE32 hprocess,BOOL32 x) {
439 FIXME(win32,"(%d,%d),stub!\n",hprocess,x);
440 return 1;
443 /***********************************************************************
444 * CreateWindowStation32W (USER32.86)
446 HWINSTA32 WINAPI CreateWindowStation32W(
447 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
448 LPSECURITY_ATTRIBUTES lpsa
450 FIXME(win32,"(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
451 res1,desiredaccess,lpsa
453 return 0xdeadcafe;
456 /***********************************************************************
457 * SetProcessWindowStation (USER32.496)
459 BOOL32 WINAPI SetProcessWindowStation(HWINSTA32 hWinSta) {
460 FIXME(win32,"(%d),stub!\n",hWinSta);
461 return TRUE;
464 /***********************************************************************
465 * SetUserObjectSecurity (USER32.514)
467 BOOL32 WINAPI SetUserObjectSecurity(
468 HANDLE32 hObj,
469 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
470 PSECURITY_DESCRIPTOR pSID
472 FIXME(win32,"(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
473 return TRUE;
476 /***********************************************************************
477 * CreateDesktop32W (USER32.69)
479 HDESK32 WINAPI CreateDesktop32W(
480 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODE32W pDevmode,
481 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
483 FIXME(win32,"(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
484 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
485 dwFlags,dwDesiredAccess,lpsa
487 return 0xcafedead;
490 /***********************************************************************
491 * SetWindowStationUser (USER32.521)
493 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
494 FIXME(win32,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
495 return 1;
498 /***********************************************************************
499 * SetLogonNotifyWindow (USER32.486)
501 DWORD WINAPI SetLogonNotifyWindow(HWINSTA32 hwinsta,HWND32 hwnd) {
502 FIXME(win32,"(0x%x,%04x),stub!\n",hwinsta,hwnd);
503 return 1;
506 /***********************************************************************
507 * LoadLocalFonts (USER32.486)
509 VOID WINAPI LoadLocalFonts(VOID) {
510 /* are loaded. */
511 return;
513 /***********************************************************************
514 * GetUserObjectInformation32A (USER32.299)
516 BOOL32 WINAPI GetUserObjectInformation32A( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
517 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
518 return TRUE;
520 /***********************************************************************
521 * GetUserObjectInformation32W (USER32.300)
523 BOOL32 WINAPI GetUserObjectInformation32W( HANDLE32 hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
524 { FIXME(win32,"(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
525 return TRUE;
527 /***********************************************************************
528 * GetUserObjectSecurity32 (USER32.300)
530 BOOL32 WINAPI GetUserObjectSecurity32(HANDLE32 hObj, SECURITY_INFORMATION * pSIRequested,
531 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
532 { FIXME(win32,"(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
533 return TRUE;