4 * Copyright 1993 Robert J. Amstadt
9 #include "wine/winbase16.h"
17 #include "clipboard.h"
19 #include "cursoricon.h"
30 #include "debugtools.h"
32 DECLARE_DEBUG_CHANNEL(hook)
33 DECLARE_DEBUG_CHANNEL(local)
34 DECLARE_DEBUG_CHANNEL(system)
35 DECLARE_DEBUG_CHANNEL(win)
36 DECLARE_DEBUG_CHANNEL(win32)
38 /***********************************************************************
39 * GetFreeSystemResources (USER.284)
41 WORD WINAPI GetFreeSystemResources16( WORD resType )
43 int userPercent, gdiPercent;
47 case GFSR_USERRESOURCES:
48 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
49 LOCAL_HeapSize( USER_HeapSel );
53 case GFSR_GDIRESOURCES:
54 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
55 LOCAL_HeapSize( GDI_HeapSel );
59 case GFSR_SYSTEMRESOURCES:
60 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
61 LOCAL_HeapSize( USER_HeapSel );
62 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
63 LOCAL_HeapSize( GDI_HeapSel );
69 return (WORD)MIN( userPercent, gdiPercent );
73 /***********************************************************************
74 * SystemHeapInfo (TOOLHELP.71)
76 BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
78 pHeapInfo->wUserFreePercent = GetFreeSystemResources16( GFSR_USERRESOURCES );
79 pHeapInfo->wGDIFreePercent = GetFreeSystemResources16( GFSR_GDIRESOURCES );
80 pHeapInfo->hUserSegment = USER_HeapSel;
81 pHeapInfo->hGDISegment = GDI_HeapSel;
86 /***********************************************************************
87 * TimerCount (TOOLHELP.80)
89 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
92 * In standard mode, dwmsSinceStart = dwmsThisVM
94 * I tested this, under Windows in enhanced mode, and
95 * if you never switch VM (ie start/stop DOS) these
96 * values should be the same as well.
98 * Also, Wine should adjust for the hardware timer
99 * to reduce the amount of error to ~1ms.
100 * I can't be bothered, can you?
102 pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
106 /**********************************************************************
109 INT16 WINAPI InitApp16( HINSTANCE16 hInstance )
111 /* Hack: restore the divide-by-zero handler */
112 /* FIXME: should set a USER-specific handler that displays a msg box */
113 INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
115 /* Create task message queue */
116 if ( !GetFastQueue16() ) return 0;
121 /**********************************************************************
124 static void USER_ModuleUnload( HMODULE16 hModule )
126 HOOK_FreeModuleHooks( hModule );
127 CLASS_FreeModuleClasses( hModule );
128 CURSORICON_FreeModuleIcons( hModule );
131 /**********************************************************************
134 static void USER_QueueCleanup( HQUEUE16 hQueue )
138 WND* desktop = WIN_GetDesktop();
140 /* Patch desktop window */
141 if ( desktop->hmemTaskQ == hQueue )
143 HTASK16 nextTask = TASK_GetNextTask( GetCurrentTask() );
144 desktop->hmemTaskQ = GetTaskQueue16( nextTask );
147 /* Patch resident popup menu window */
148 MENU_PatchResidentPopup( hQueue, NULL );
150 TIMER_RemoveQueueTimers( hQueue );
152 HOOK_FreeQueueHooks( hQueue );
154 QUEUE_SetExitingQueue( hQueue );
155 WIN_ResetQueueWindows( desktop, hQueue, (HQUEUE16)0);
156 QUEUE_SetExitingQueue( 0 );
158 /* Free the message queue */
159 QUEUE_DeleteMsgQueue( hQueue );
161 WIN_ReleaseDesktop();
165 /**********************************************************************
168 static void USER_AppExit( HINSTANCE16 hInstance )
170 /* FIXME: maybe destroy menus (Windows only complains about them
174 /* TODO: Start up persistant WINE X clipboard server process which will
175 * take ownership of the X selection and continue to service selection
176 * requests from other apps.
179 /* ModuleUnload() in "Internals" */
181 hInstance = GetExePtr( hInstance );
182 if( GetModuleUsage16( hInstance ) <= 1 )
183 USER_ModuleUnload( hInstance );
187 /***********************************************************************
188 * USER_SignalProc (USER.314)
190 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
191 UINT16 uExitFn, HINSTANCE16 hInstance,
194 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
197 /***********************************************************************
198 * FinalUserInit (USER.400)
200 void WINAPI FinalUserInit16( void )
202 /* FIXME: Should chain to FinalGdiInit now. */
205 /***********************************************************************
206 * UserSignalProc (USER.610) (USER32.559)
208 * For comments about the meaning of uCode and dwFlags
209 * see PROCESS_CallUserSignalProc.
212 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
213 DWORD dwFlags, HMODULE16 hModule )
217 /* FIXME: Proper reaction to most signals still missing. */
221 case USIG_DLL_UNLOAD_WIN16:
222 case USIG_DLL_UNLOAD_WIN32:
223 USER_ModuleUnload( hModule );
226 case USIG_DLL_UNLOAD_ORPHANS:
229 case USIG_FAULT_DIALOG_PUSH:
230 case USIG_FAULT_DIALOG_POP:
233 case USIG_THREAD_INIT:
236 case USIG_THREAD_EXIT:
237 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID ) );
238 SetThreadQueue16( dwThreadOrProcessID, 0 );
241 case USIG_PROCESS_CREATE:
242 case USIG_PROCESS_INIT:
243 case USIG_PROCESS_LOADED:
244 case USIG_PROCESS_RUNNING:
247 case USIG_PROCESS_EXIT:
250 case USIG_PROCESS_DESTROY:
251 hInst = GetProcessDword( dwThreadOrProcessID, GPD_HINSTANCE16 );
252 USER_AppExit( hInst );
256 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
257 uCode, dwThreadOrProcessID, dwFlags, hModule );
261 /* FIXME: Should chain to GdiSignalProc now. */
268 /***********************************************************************
269 * ExitWindows16 (USER.7)
271 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
273 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
277 /***********************************************************************
278 * ExitWindowsExec16 (USER.246)
280 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
282 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
283 lpszExe, lpszParams);
284 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
288 /***********************************************************************
289 * ExitWindowsEx (USER32.196)
291 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
297 /* We have to build a list of all windows first, as in EnumWindows */
299 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
301 WIN_ReleaseDesktop();
305 /* Send a WM_QUERYENDSESSION message to every window */
307 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
309 /* Make sure that the window still exists */
310 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
311 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
316 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
318 for (ppWnd = list; i > 0; i--, ppWnd++)
320 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
321 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
323 WIN_ReleaseWinArray(list);
325 if (result) ExitKernel16();
326 WIN_ReleaseDesktop();
331 /***********************************************************************
332 * ChangeDisplaySettingA (USER32.589)
334 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
336 FIXME_(system)(": stub\n");
338 FIXME_(system)(" devmode=NULL (return to default mode)\n");
339 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
340 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
341 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
345 if (devmode->dmFields & DM_BITSPERPEL)
346 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
347 if (devmode->dmFields & DM_PELSWIDTH)
348 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
349 if (devmode->dmFields & DM_PELSHEIGHT)
350 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
351 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
352 /* we don't, but the program ... does not need to know */
353 return DISP_CHANGE_SUCCESSFUL;
355 return DISP_CHANGE_SUCCESSFUL;
358 /***********************************************************************
359 * EnumDisplaySettingsA (USER32.592)
360 * FIXME: Currently uses static list of modes.
363 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
364 * FALSE if we do not have the nth setting
366 BOOL WINAPI EnumDisplaySettingsA(
367 LPCSTR name, /* [in] huh? */
368 DWORD n, /* [in] nth entry in display settings list*/
369 LPDEVMODEA devmode /* [out] devmode for that setting */
375 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
376 int depths[4] = {8,16,24,32};
378 TRACE_(system)("(%s,%ld,%p)\n",name,n,devmode);
380 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
381 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
382 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
385 if ((n-1)<NRMODES*NRDEPTHS) {
386 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
387 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
388 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
394 /***********************************************************************
395 * EnumDisplaySettingsW (USER32.593)
397 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) {
398 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
400 BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
403 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
404 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
405 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
406 /* FIXME: convert rest too, if they are ever returned */
408 HeapFree(GetProcessHeap(),0,nameA);
412 /***********************************************************************
413 * EnumDisplayDevicesA (USER32.184)
415 BOOL WINAPI EnumDisplayDevicesA(
416 LPVOID unused,DWORD i,LPDISPLAY_DEVICEA lpDisplayDevice,DWORD dwFlags
420 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
421 strcpy(lpDisplayDevice->DeviceName,"X11");
422 strcpy(lpDisplayDevice->DeviceString,"X 11 Windowing System");
423 lpDisplayDevice->StateFlags =
424 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
425 DISPLAY_DEVICE_PRIMARY_DEVICE |
426 DISPLAY_DEVICE_VGA_COMPATIBLE;
430 /***********************************************************************
431 * EnumDisplayDevicesW (USER32.185)
433 BOOL WINAPI EnumDisplayDevicesW(
434 LPVOID unused,DWORD i,LPDISPLAY_DEVICEW lpDisplayDevice,DWORD dwFlags
438 FIXME_(system)("(%p,%ld,%p,0x%08lx), stub!\n",unused,i,lpDisplayDevice,dwFlags);
439 lstrcpyAtoW(lpDisplayDevice->DeviceName,"X11");
440 lstrcpyAtoW(lpDisplayDevice->DeviceString,"X 11 Windowing System");
441 lpDisplayDevice->StateFlags =
442 DISPLAY_DEVICE_ATTACHED_TO_DESKTOP |
443 DISPLAY_DEVICE_PRIMARY_DEVICE |
444 DISPLAY_DEVICE_VGA_COMPATIBLE;
448 /***********************************************************************
449 * SetEventHook (USER.321)
451 * Used by Turbo Debugger for Windows
453 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
455 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
459 /***********************************************************************
460 * UserSeeUserDo (USER.216)
462 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
466 case USUD_LOCALALLOC:
467 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
469 return LOCAL_Free(USER_HeapSel, wParam1);
470 case USUD_LOCALCOMPACT:
471 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
474 case USUD_FIRSTCLASS:
475 FIXME_(local)("return a pointer to the first window class.\n");
478 WARN_(local)("wReqType %04x (unknown)", wReqType);
483 /***********************************************************************
484 * GetSystemDebugState16 (USER.231)
486 WORD WINAPI GetSystemDebugState16(void)
488 return 0; /* FIXME */
491 /***********************************************************************
492 * RegisterLogonProcess (USER32.434)
494 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
495 FIXME_(win32)("(%d,%d),stub!\n",hprocess,x);
499 /***********************************************************************
500 * CreateWindowStation32W (USER32.86)
502 HWINSTA WINAPI CreateWindowStationW(
503 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
504 LPSECURITY_ATTRIBUTES lpsa
506 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
507 res1,desiredaccess,lpsa
512 /***********************************************************************
513 * SetProcessWindowStation (USER32.496)
515 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
516 FIXME_(win32)("(%d),stub!\n",hWinSta);
520 /***********************************************************************
521 * SetUserObjectSecurity (USER32.514)
523 BOOL WINAPI SetUserObjectSecurity(
525 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
526 PSECURITY_DESCRIPTOR pSID
528 FIXME_(win32)("(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
532 /***********************************************************************
533 * CreateDesktop32W (USER32.69)
535 HDESK WINAPI CreateDesktopW(
536 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
537 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
539 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
540 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
541 dwFlags,dwDesiredAccess,lpsa
546 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
548 FIXME_(win32)("(0x%08x)\n", hWinSta);
551 BOOL WINAPI CloseDesktop(HDESK hDesk)
553 FIXME_(win32)("(0x%08x)\n", hDesk);
557 /***********************************************************************
558 * SetWindowStationUser (USER32.521)
560 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
561 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
565 /***********************************************************************
566 * SetLogonNotifyWindow (USER32.486)
568 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
569 FIXME_(win32)("(0x%x,%04x),stub!\n",hwinsta,hwnd);
573 /***********************************************************************
574 * LoadLocalFonts (USER32.486)
576 VOID WINAPI LoadLocalFonts(VOID) {
580 /***********************************************************************
581 * GetUserObjectInformation32A (USER32.299)
583 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
584 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
587 /***********************************************************************
588 * GetUserObjectInformation32W (USER32.300)
590 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
591 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
594 /***********************************************************************
595 * GetUserObjectSecurity32 (USER32.300)
597 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, SECURITY_INFORMATION * pSIRequested,
598 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
599 { FIXME_(win32)("(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
603 /***********************************************************************
604 * SetSystemCursor (USER32.507)
606 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
607 { FIXME_(win32)("(%08x,%08lx),stub!\n", hcur, id);
611 /***********************************************************************
612 * RegisterSystemThread (USER32.435)
614 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
616 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);