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 * SetEventHook (USER.321)
415 * Used by Turbo Debugger for Windows
417 FARPROC16 WINAPI
SetEventHook16(FARPROC16 lpfnEventHook
)
419 FIXME_(hook
)("(lpfnEventHook=%08x): stub\n", (UINT
)lpfnEventHook
);
423 /***********************************************************************
424 * UserSeeUserDo (USER.216)
426 DWORD WINAPI
UserSeeUserDo16(WORD wReqType
, WORD wParam1
, WORD wParam2
, WORD wParam3
)
430 case USUD_LOCALALLOC
:
431 return LOCAL_Alloc(USER_HeapSel
, wParam1
, wParam3
);
433 return LOCAL_Free(USER_HeapSel
, wParam1
);
434 case USUD_LOCALCOMPACT
:
435 return LOCAL_Compact(USER_HeapSel
, wParam3
, 0);
438 case USUD_FIRSTCLASS
:
439 FIXME_(local
)("return a pointer to the first window class.\n");
442 WARN_(local
)("wReqType %04x (unknown)", wReqType
);
447 /***********************************************************************
448 * GetSystemDebugState16 (USER.231)
450 WORD WINAPI
GetSystemDebugState16(void)
452 return 0; /* FIXME */
455 /***********************************************************************
456 * RegisterLogonProcess (USER32.434)
458 DWORD WINAPI
RegisterLogonProcess(HANDLE hprocess
,BOOL x
) {
459 FIXME_(win32
)("(%d,%d),stub!\n",hprocess
,x
);
463 /***********************************************************************
464 * CreateWindowStation32W (USER32.86)
466 HWINSTA WINAPI
CreateWindowStationW(
467 LPWSTR winstation
,DWORD res1
,DWORD desiredaccess
,
468 LPSECURITY_ATTRIBUTES lpsa
470 FIXME_(win32
)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation
),
471 res1
,desiredaccess
,lpsa
476 /***********************************************************************
477 * SetProcessWindowStation (USER32.496)
479 BOOL WINAPI
SetProcessWindowStation(HWINSTA hWinSta
) {
480 FIXME_(win32
)("(%d),stub!\n",hWinSta
);
484 /***********************************************************************
485 * SetUserObjectSecurity (USER32.514)
487 BOOL WINAPI
SetUserObjectSecurity(
489 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested
,
490 PSECURITY_DESCRIPTOR pSID
492 FIXME_(win32
)("(0x%08x,%p,%p),stub!\n",hObj
,pSIRequested
,pSID
);
496 /***********************************************************************
497 * CreateDesktop32W (USER32.69)
499 HDESK WINAPI
CreateDesktopW(
500 LPWSTR lpszDesktop
,LPWSTR lpszDevice
,LPDEVMODEW pDevmode
,
501 DWORD dwFlags
,DWORD dwDesiredAccess
,LPSECURITY_ATTRIBUTES lpsa
503 FIXME_(win32
)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
504 debugstr_w(lpszDesktop
),debugstr_w(lpszDevice
),pDevmode
,
505 dwFlags
,dwDesiredAccess
,lpsa
510 BOOL WINAPI
CloseWindowStation(HWINSTA hWinSta
)
512 FIXME_(win32
)("(0x%08x)\n", hWinSta
);
515 BOOL WINAPI
CloseDesktop(HDESK hDesk
)
517 FIXME_(win32
)("(0x%08x)\n", hDesk
);
521 /***********************************************************************
522 * SetWindowStationUser (USER32.521)
524 DWORD WINAPI
SetWindowStationUser(DWORD x1
,DWORD x2
) {
525 FIXME_(win32
)("(0x%08lx,0x%08lx),stub!\n",x1
,x2
);
529 /***********************************************************************
530 * SetLogonNotifyWindow (USER32.486)
532 DWORD WINAPI
SetLogonNotifyWindow(HWINSTA hwinsta
,HWND hwnd
) {
533 FIXME_(win32
)("(0x%x,%04x),stub!\n",hwinsta
,hwnd
);
537 /***********************************************************************
538 * LoadLocalFonts (USER32.486)
540 VOID WINAPI
LoadLocalFonts(VOID
) {
544 /***********************************************************************
545 * GetUserObjectInformation32A (USER32.299)
547 BOOL WINAPI
GetUserObjectInformationA( 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
);
551 /***********************************************************************
552 * GetUserObjectInformation32W (USER32.300)
554 BOOL WINAPI
GetUserObjectInformationW( HANDLE hObj
, int nIndex
, LPVOID pvInfo
, DWORD nLength
, LPDWORD lpnLen
)
555 { FIXME_(win32
)("(0x%x %i %p %ld %p),stub!\n", hObj
, nIndex
, pvInfo
, nLength
, lpnLen
);
558 /***********************************************************************
559 * GetUserObjectSecurity32 (USER32.300)
561 BOOL WINAPI
GetUserObjectSecurity(HANDLE hObj
, SECURITY_INFORMATION
* pSIRequested
,
562 PSECURITY_DESCRIPTOR pSID
, DWORD nLength
, LPDWORD lpnLengthNeeded
)
563 { FIXME_(win32
)("(0x%x %p %p len=%ld %p),stub!\n", hObj
, pSIRequested
, pSID
, nLength
, lpnLengthNeeded
);
567 /***********************************************************************
568 * SetSystemCursor (USER32.507)
570 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
571 { FIXME_(win32
)("(%08x,%08lx),stub!\n", hcur
, id
);
575 /***********************************************************************
576 * RegisterSystemThread (USER32.435)
578 void WINAPI
RegisterSystemThread(DWORD flags
, DWORD reserved
)
580 FIXME_(win32
)("(%08lx, %08lx)\n", flags
, reserved
);