Bugfixes & further updates for the month calendar common control.
[wine/dcerpc.git] / windows / user.c
blobea30472f0c6dcaa29ab3f71d4c6c9f35da93fe66
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 "desktop.h"
29 #include "process.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;
45 switch(resType)
47 case GFSR_USERRESOURCES:
48 userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
49 LOCAL_HeapSize( USER_HeapSel );
50 gdiPercent = 100;
51 break;
53 case GFSR_GDIRESOURCES:
54 gdiPercent = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
55 LOCAL_HeapSize( GDI_HeapSel );
56 userPercent = 100;
57 break;
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 );
64 break;
66 default:
67 return 0;
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;
82 return TRUE;
86 /***********************************************************************
87 * TimerCount (TOOLHELP.80)
89 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
91 /* FIXME
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();
103 return TRUE;
106 /**********************************************************************
107 * InitApp (USER.5)
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;
118 return 1;
121 /**********************************************************************
122 * USER_ModuleUnload
124 static void USER_ModuleUnload( HMODULE16 hModule )
126 HOOK_FreeModuleHooks( hModule );
127 CLASS_FreeModuleClasses( hModule );
128 CURSORICON_FreeModuleIcons( hModule );
131 /**********************************************************************
132 * USER_QueueCleanup
134 static void USER_QueueCleanup( HQUEUE16 hQueue )
136 if ( 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 CLIPBOARD_ResetLock( hQueue, 0 );
157 QUEUE_SetExitingQueue( 0 );
159 /* Free the message queue */
160 QUEUE_DeleteMsgQueue( hQueue );
162 WIN_ReleaseDesktop();
166 /**********************************************************************
167 * USER_AppExit
169 static void USER_AppExit( HINSTANCE16 hInstance )
171 /* FIXME: empty clipboard if needed, maybe destroy menus (Windows
172 * only complains about them but does nothing);
175 /* ModuleUnload() in "Internals" */
177 hInstance = GetExePtr( hInstance );
178 if( GetModuleUsage16( hInstance ) <= 1 )
179 USER_ModuleUnload( hInstance );
183 /***********************************************************************
184 * USER_SignalProc (USER.314)
186 void WINAPI USER_SignalProc( HANDLE16 hTaskOrModule, UINT16 uCode,
187 UINT16 uExitFn, HINSTANCE16 hInstance,
188 HQUEUE16 hQueue )
190 FIXME_(win)("Win 3.1 USER signal %04x\n", uCode );
193 /***********************************************************************
194 * FinalUserInit (USER.400)
196 void WINAPI FinalUserInit16( void )
198 /* FIXME: Should chain to FinalGdiInit now. */
201 /***********************************************************************
202 * UserSignalProc (USER.610) (USER32.559)
204 * For comments about the meaning of uCode and dwFlags
205 * see PROCESS_CallUserSignalProc.
208 WORD WINAPI UserSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
209 DWORD dwFlags, HMODULE16 hModule )
211 HINSTANCE16 hInst;
213 /* FIXME: Proper reaction to most signals still missing. */
215 switch ( uCode )
217 case USIG_DLL_UNLOAD_WIN16:
218 case USIG_DLL_UNLOAD_WIN32:
219 USER_ModuleUnload( hModule );
220 break;
222 case USIG_DLL_UNLOAD_ORPHANS:
223 break;
225 case USIG_FAULT_DIALOG_PUSH:
226 case USIG_FAULT_DIALOG_POP:
227 break;
229 case USIG_THREAD_INIT:
230 break;
232 case USIG_THREAD_EXIT:
233 USER_QueueCleanup( GetThreadQueue16( dwThreadOrProcessID ) );
234 SetThreadQueue16( dwThreadOrProcessID, 0 );
235 break;
237 case USIG_PROCESS_CREATE:
238 case USIG_PROCESS_INIT:
239 case USIG_PROCESS_LOADED:
240 case USIG_PROCESS_RUNNING:
241 break;
243 case USIG_PROCESS_EXIT:
244 break;
246 case USIG_PROCESS_DESTROY:
247 hInst = GetProcessDword( dwThreadOrProcessID, GPD_HINSTANCE16 );
248 USER_AppExit( hInst );
249 break;
251 default:
252 FIXME_(win)("(%04x, %08lx, %04lx, %04x)\n",
253 uCode, dwThreadOrProcessID, dwFlags, hModule );
254 break;
257 /* FIXME: Should chain to GdiSignalProc now. */
259 return 0;
264 /***********************************************************************
265 * ExitWindows16 (USER.7)
267 BOOL16 WINAPI ExitWindows16( DWORD dwReturnCode, UINT16 wReserved )
269 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
273 /***********************************************************************
274 * ExitWindowsExec16 (USER.246)
276 BOOL16 WINAPI ExitWindowsExec16( LPCSTR lpszExe, LPCSTR lpszParams )
278 TRACE_(system)("Should run the following in DOS-mode: \"%s %s\"\n",
279 lpszExe, lpszParams);
280 return ExitWindowsEx( EWX_LOGOFF, 0xffffffff );
284 /***********************************************************************
285 * ExitWindowsEx (USER32.196)
287 BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reserved )
289 int i;
290 BOOL result;
291 WND **list, **ppWnd;
293 /* We have to build a list of all windows first, as in EnumWindows */
295 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
297 WIN_ReleaseDesktop();
298 return FALSE;
301 /* Send a WM_QUERYENDSESSION message to every window */
303 for (ppWnd = list, i = 0; *ppWnd; ppWnd++, i++)
305 /* Make sure that the window still exists */
306 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
307 if (!SendMessage16( (*ppWnd)->hwndSelf, WM_QUERYENDSESSION, 0, 0 ))
308 break;
310 result = !(*ppWnd);
312 /* Now notify all windows that got a WM_QUERYENDSESSION of the result */
314 for (ppWnd = list; i > 0; i--, ppWnd++)
316 if (!IsWindow( (*ppWnd)->hwndSelf )) continue;
317 SendMessage16( (*ppWnd)->hwndSelf, WM_ENDSESSION, result, 0 );
319 WIN_ReleaseWinArray(list);
321 if (result) ExitKernel16();
322 WIN_ReleaseDesktop();
323 return FALSE;
327 /***********************************************************************
328 * ChangeDisplaySettingA (USER32.589)
330 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
332 FIXME_(system)(": stub\n");
333 if (devmode==NULL)
334 FIXME_(system)(" devmode=NULL (return to default mode)\n");
335 else if ( (devmode->dmBitsPerPel != DESKTOP_GetScreenDepth())
336 || (devmode->dmPelsHeight != DESKTOP_GetScreenHeight())
337 || (devmode->dmPelsWidth != DESKTOP_GetScreenWidth()) )
341 if (devmode->dmFields & DM_BITSPERPEL)
342 FIXME_(system)(" bpp=%ld\n",devmode->dmBitsPerPel);
343 if (devmode->dmFields & DM_PELSWIDTH)
344 FIXME_(system)(" width=%ld\n",devmode->dmPelsWidth);
345 if (devmode->dmFields & DM_PELSHEIGHT)
346 FIXME_(system)(" height=%ld\n",devmode->dmPelsHeight);
347 FIXME_(system)(" (Putting X in this mode beforehand might help)\n");
348 /* we don't, but the program ... does not need to know */
349 return DISP_CHANGE_SUCCESSFUL;
351 return DISP_CHANGE_SUCCESSFUL;
354 /***********************************************************************
355 * EnumDisplaySettingsA (USER32.592)
356 * FIXME: Currently uses static list of modes.
358 * RETURNS
359 * TRUE if nth setting exists found (described in the LPDEVMODE32A struct)
360 * FALSE if we do not have the nth setting
362 BOOL WINAPI EnumDisplaySettingsA(
363 LPCSTR name, /* [in] huh? */
364 DWORD n, /* [in] nth entry in display settings list*/
365 LPDEVMODEA devmode /* [out] devmode for that setting */
367 #define NRMODES 5
368 #define NRDEPTHS 4
369 struct {
370 int w,h;
371 } modes[NRMODES]={{512,384},{640,400},{640,480},{800,600},{1024,768}};
372 int depths[4] = {8,16,24,32};
374 TRACE_(system)("(%s,%ld,%p)\n",name,n,devmode);
375 if (n==0) {
376 devmode->dmBitsPerPel = DESKTOP_GetScreenDepth();
377 devmode->dmPelsHeight = DESKTOP_GetScreenHeight();
378 devmode->dmPelsWidth = DESKTOP_GetScreenWidth();
379 return TRUE;
381 if ((n-1)<NRMODES*NRDEPTHS) {
382 devmode->dmBitsPerPel = depths[(n-1)/NRMODES];
383 devmode->dmPelsHeight = modes[(n-1)%NRMODES].h;
384 devmode->dmPelsWidth = modes[(n-1)%NRMODES].w;
385 return TRUE;
387 return FALSE;
390 /***********************************************************************
391 * EnumDisplaySettingsW (USER32.593)
393 BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) {
394 LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name);
395 DEVMODEA devmodeA;
396 BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA);
398 if (ret) {
399 devmode->dmBitsPerPel = devmodeA.dmBitsPerPel;
400 devmode->dmPelsHeight = devmodeA.dmPelsHeight;
401 devmode->dmPelsWidth = devmodeA.dmPelsWidth;
402 /* FIXME: convert rest too, if they are ever returned */
404 HeapFree(GetProcessHeap(),0,nameA);
405 return ret;
408 /***********************************************************************
409 * SetEventHook (USER.321)
411 * Used by Turbo Debugger for Windows
413 FARPROC16 WINAPI SetEventHook16(FARPROC16 lpfnEventHook)
415 FIXME_(hook)("(lpfnEventHook=%08x): stub\n", (UINT)lpfnEventHook);
416 return NULL;
419 /***********************************************************************
420 * UserSeeUserDo (USER.216)
422 DWORD WINAPI UserSeeUserDo16(WORD wReqType, WORD wParam1, WORD wParam2, WORD wParam3)
424 switch (wReqType)
426 case USUD_LOCALALLOC:
427 return LOCAL_Alloc(USER_HeapSel, wParam1, wParam3);
428 case USUD_LOCALFREE:
429 return LOCAL_Free(USER_HeapSel, wParam1);
430 case USUD_LOCALCOMPACT:
431 return LOCAL_Compact(USER_HeapSel, wParam3, 0);
432 case USUD_LOCALHEAP:
433 return USER_HeapSel;
434 case USUD_FIRSTCLASS:
435 FIXME_(local)("return a pointer to the first window class.\n");
436 return (DWORD)-1;
437 default:
438 WARN_(local)("wReqType %04x (unknown)", wReqType);
439 return (DWORD)-1;
443 /***********************************************************************
444 * GetSystemDebugState16 (USER.231)
446 WORD WINAPI GetSystemDebugState16(void)
448 return 0; /* FIXME */
451 /***********************************************************************
452 * RegisterLogonProcess (USER32.434)
454 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x) {
455 FIXME_(win32)("(%d,%d),stub!\n",hprocess,x);
456 return 1;
459 /***********************************************************************
460 * CreateWindowStation32W (USER32.86)
462 HWINSTA WINAPI CreateWindowStationW(
463 LPWSTR winstation,DWORD res1,DWORD desiredaccess,
464 LPSECURITY_ATTRIBUTES lpsa
466 FIXME_(win32)("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation),
467 res1,desiredaccess,lpsa
469 return 0xdeadcafe;
472 /***********************************************************************
473 * SetProcessWindowStation (USER32.496)
475 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta) {
476 FIXME_(win32)("(%d),stub!\n",hWinSta);
477 return TRUE;
480 /***********************************************************************
481 * SetUserObjectSecurity (USER32.514)
483 BOOL WINAPI SetUserObjectSecurity(
484 HANDLE hObj,
485 /*LPSECURITY_INFORMATION*/LPVOID pSIRequested,
486 PSECURITY_DESCRIPTOR pSID
488 FIXME_(win32)("(0x%08x,%p,%p),stub!\n",hObj,pSIRequested,pSID);
489 return TRUE;
492 /***********************************************************************
493 * CreateDesktop32W (USER32.69)
495 HDESK WINAPI CreateDesktopW(
496 LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
497 DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa
499 FIXME_(win32)("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
500 debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
501 dwFlags,dwDesiredAccess,lpsa
503 return 0xcafedead;
506 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
508 FIXME_(win32)("(0x%08x)\n", hWinSta);
509 return TRUE;
511 BOOL WINAPI CloseDesktop(HDESK hDesk)
513 FIXME_(win32)("(0x%08x)\n", hDesk);
514 return TRUE;
517 /***********************************************************************
518 * SetWindowStationUser (USER32.521)
520 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2) {
521 FIXME_(win32)("(0x%08lx,0x%08lx),stub!\n",x1,x2);
522 return 1;
525 /***********************************************************************
526 * SetLogonNotifyWindow (USER32.486)
528 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd) {
529 FIXME_(win32)("(0x%x,%04x),stub!\n",hwinsta,hwnd);
530 return 1;
533 /***********************************************************************
534 * LoadLocalFonts (USER32.486)
536 VOID WINAPI LoadLocalFonts(VOID) {
537 /* are loaded. */
538 return;
540 /***********************************************************************
541 * GetUserObjectInformation32A (USER32.299)
543 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
544 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
545 return TRUE;
547 /***********************************************************************
548 * GetUserObjectInformation32W (USER32.300)
550 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, int nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
551 { FIXME_(win32)("(0x%x %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
552 return TRUE;
554 /***********************************************************************
555 * GetUserObjectSecurity32 (USER32.300)
557 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, SECURITY_INFORMATION * pSIRequested,
558 PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
559 { FIXME_(win32)("(0x%x %p %p len=%ld %p),stub!\n", hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
560 return TRUE;
563 /***********************************************************************
564 * SetSystemCursor (USER32.507)
566 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
567 { FIXME_(win32)("(%08x,%08lx),stub!\n", hcur, id);
568 return TRUE;
571 /***********************************************************************
572 * RegisterSystemThread (USER32.435)
574 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
576 FIXME_(win32)("(%08lx, %08lx)\n", flags, reserved);