Release 960428
[wine] / misc / user.c
1 /*
2  * Misc. USER functions
3  *
4  * Copyright 1993 Robert J. Amstadt
5  *           1996 Alex Korobka 
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "windows.h"
11 #include "gdi.h"
12 #include "user.h"
13 #include "task.h"
14 #include "queue.h"
15 #include "class.h"
16 #include "win.h"
17 #include "hook.h"
18 #include "debug.h"
19 #include "toolhelp.h"
20
21 #ifndef WINELIB
22 WORD USER_HeapSel = 0;
23
24 extern void     TIMER_NukeTimers(HWND, HQUEUE );
25 extern HTASK    TASK_GetNextTask(HTASK);
26
27 /***********************************************************************
28  *           GetFreeSystemResources   (USER.284)
29  */
30 WORD GetFreeSystemResources( WORD resType )
31 {
32     int userPercent, gdiPercent;
33
34     switch(resType)
35     {
36     case GFSR_USERRESOURCES:
37         userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
38                                LOCAL_HeapSize( USER_HeapSel );
39         gdiPercent  = 100;
40         break;
41
42     case GFSR_GDIRESOURCES:
43         gdiPercent  = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
44                                LOCAL_HeapSize( GDI_HeapSel );
45         userPercent = 100;
46         break;
47
48     case GFSR_SYSTEMRESOURCES:
49         userPercent = (int)LOCAL_CountFree( USER_HeapSel ) * 100 /
50                                LOCAL_HeapSize( USER_HeapSel );
51         gdiPercent  = (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
52                                LOCAL_HeapSize( GDI_HeapSel );
53         break;
54
55     default:
56         return 0;
57     }
58     return (WORD)MIN( userPercent, gdiPercent );
59 }
60
61
62 /***********************************************************************
63  *           SystemHeapInfo   (TOOLHELP.71)
64  */
65 BOOL SystemHeapInfo( SYSHEAPINFO *pHeapInfo )
66 {
67     pHeapInfo->wUserFreePercent = GetFreeSystemResources( GFSR_USERRESOURCES );
68     pHeapInfo->wGDIFreePercent  = GetFreeSystemResources( GFSR_GDIRESOURCES );
69     pHeapInfo->hUserSegment = USER_HeapSel;
70     pHeapInfo->hGDISegment  = GDI_HeapSel;
71     return TRUE;
72 }
73
74 #endif  /* WINELIB */
75
76 /***********************************************************************
77  *           TimerCount   (TOOLHELP.80)
78  */
79 BOOL TimerCount( TIMERINFO *pTimerInfo )
80 {
81     /* FIXME
82      * In standard mode, dwmsSinceStart = dwmsThisVM 
83      *
84      * I tested this, under Windows in enhanced mode, and
85      * if you never switch VM (ie start/stop DOS) these
86      * values should be the same as well. 
87      *
88      * Also, Wine should adjust for the hardware timer
89      * to reduce the amount of error to ~1ms. 
90      * I can't be bothered, can you?
91      */
92     pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
93     return TRUE;
94 }
95
96
97 /**********************************************************************
98  *                                      USER_InitApp
99  */
100 int USER_InitApp(HINSTANCE hInstance)
101 {
102     int queueSize;
103
104       /* Create task message queue */
105     queueSize = GetProfileInt( "windows", "DefaultQueueSize", 8 );
106     if (!SetMessageQueue( queueSize )) return 0;
107
108     return 1;
109 }
110
111 /**********************************************************************
112  *                                      USER_AppExit
113  */
114 void USER_AppExit(HTASK hTask, HINSTANCE hInstance, HQUEUE hQueue)
115 {
116     /* FIXME: flush send messages (which are not implemented yet),
117      *        empty clipboard if needed, maybe destroy menus (Windows
118      *        only complains about them but does nothing);
119      */
120
121     WND* desktop = WIN_GetDesktop();
122
123     /* Patch desktop window queue */
124     if( desktop->hmemTaskQ == hQueue )
125         desktop->hmemTaskQ = GetTaskQueue(TASK_GetNextTask(hTask));
126
127     /* Nuke timers */
128
129     TIMER_NukeTimers( 0, hQueue );
130
131     HOOK_FreeQueueHooks( hQueue );
132
133     /* Nuke orphaned windows */
134
135     WIN_DestroyQueueWindows( desktop->child, hQueue );
136
137     /* Free the message queue */
138
139     QUEUE_DeleteMsgQueue( hQueue );
140 }
141