Release 940804
[wine/gsoc-2012-control.git] / loader / task.c
blob569c64bff6b27088060db809cb6d09355c7b48f7
1 /*
2 * Tasks functions
3 */
4 static char Copyright[] = "Copyright Martin Ayotte, 1994";
6 /*
7 #define DEBUG_TASK
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "windows.h"
14 #include "wine.h"
15 #include "task.h"
17 static LPWINETASKENTRY lpTaskList = NULL;
18 static int nTaskCount = 0;
21 /**********************************************************************
22 * GetCurrentTask [KERNEL.36]
24 HTASK GetCurrentTask()
26 LPWINETASKENTRY lpTask = lpTaskList;
27 int pid = getpid();
28 #ifdef DEBUG_TASK
29 printf("GetCurrentTask() // unix_pid=%08X !\n", pid);
30 #endif
31 if (lpTask == NULL) return 0;
32 while (TRUE) {
33 if (lpTask->unix_pid == pid) break;
34 if (lpTask->lpNextTask == NULL) return 0;
35 lpTask = lpTask->lpNextTask;
37 #ifdef DEBUG_TASK
38 printf("GetCurrentTask() returned hTask=%04X !\n", lpTask->te.hTask);
39 #endif
40 return lpTask->te.hTask;
44 /**********************************************************************
45 * GetNumTasks [KERNEL.152]
47 WORD GetNumTasks()
49 printf("GetNumTasks() returned %d !\n", nTaskCount);
50 return nTaskCount;
54 /**********************************************************************
55 * GetWindowTask [USER.224]
57 HTASK GetWindowTask(HWND hWnd)
59 HWND *wptr;
60 int count;
61 LPWINETASKENTRY lpTask = lpTaskList;
62 printf("GetWindowTask(%04X) !\n", hWnd);
63 while (lpTask != NULL) {
64 wptr = lpTask->lpWndList;
65 if (wptr != NULL) {
66 count = 0;
67 while (++count < MAXWIN_PER_TASK) {
68 printf("GetWindowTask // searching %04X %04X !\n",
69 lpTask->te.hTask, *(wptr));
70 if (*(wptr) == hWnd) {
71 printf("GetWindowTask(%04X) found hTask=%04X !\n",
72 hWnd, lpTask->te.hTask);
73 return lpTask->te.hTask;
75 wptr++;
78 lpTask = lpTask->lpNextTask;
80 return 0;
84 /**********************************************************************
85 * EnumTaskWindows [USER.225]
87 BOOL EnumTaskWindows(HANDLE hTask, FARPROC lpEnumFunc, LONG lParam)
89 HWND *wptr, hWnd;
90 BOOL bRet;
91 int count = 0;
92 LPWINETASKENTRY lpTask = lpTaskList;
93 printf("EnumTaskWindows(%04X, %08X, %08X) !\n", hTask, lpEnumFunc, lParam);
94 while (TRUE) {
95 if (lpTask->te.hTask == hTask) break;
96 if (lpTask == NULL) {
97 printf("EnumTaskWindows // hTask=%04X not found !\n", hTask);
98 return FALSE;
100 lpTask = lpTask->lpNextTask;
102 printf("EnumTaskWindows // found hTask=%04X !\n", hTask);
103 wptr = lpTask->lpWndList;
104 if (wptr == NULL) return FALSE;
105 if (lpEnumFunc == NULL) return FALSE;
106 while ((hWnd = *(wptr++)) != 0) {
107 if (++count >= MAXWIN_PER_TASK) return FALSE;
108 printf("EnumTaskWindows // hWnd=%04X count=%d !\n", hWnd, count);
109 #ifdef WINELIB
110 bRet = (*lpEnumFunc)(hWnd, lParam);
111 #else
112 bRet = CallBack16(lpEnumFunc, 2, 0, (int)hWnd, 2, (int)lParam);
113 #endif
114 if (bRet == 0) break;
116 return TRUE;
120 /**********************************************************************
121 * CreateNewTask [internal]
123 HANDLE CreateNewTask(HINSTANCE hInst, HTASK hTaskParent)
125 HANDLE hTask;
126 LPWINETASKENTRY lpTask = lpTaskList;
127 LPWINETASKENTRY lpNewTask;
128 if (lpTask != NULL) {
129 while (TRUE) {
130 if (lpTask->lpNextTask == NULL) break;
131 lpTask = lpTask->lpNextTask;
134 hTask = GlobalAlloc(GMEM_MOVEABLE, sizeof(WINETASKENTRY));
135 lpNewTask = (LPWINETASKENTRY) GlobalLock(hTask);
136 #ifdef DEBUG_TASK
137 printf("CreateNewTask entry allocated %08X\n", lpNewTask);
138 #endif
139 if (lpNewTask == NULL) return 0;
140 if (lpTaskList == NULL) {
141 lpTaskList = lpNewTask;
142 lpNewTask->lpPrevTask = NULL;
144 else {
145 lpTask->lpNextTask = lpNewTask;
146 lpTask->te.hNext = lpNewTask->te.hTask;
147 lpNewTask->lpPrevTask = lpTask;
149 lpNewTask->lpNextTask = NULL;
150 lpNewTask->hIcon = 0;
151 lpNewTask->te.dwSize = sizeof(TASKENTRY);
152 lpNewTask->te.hModule = 0;
153 lpNewTask->te.hInst = hInst;
154 lpNewTask->te.hTask = hTask;
155 lpNewTask->te.hTaskParent = hTaskParent;
156 lpNewTask->te.wSS = 0;
157 lpNewTask->te.wSP = 0;
158 lpNewTask->te.wStackTop = 0;
159 lpNewTask->te.wStackMinimum = 0;
160 lpNewTask->te.wStackBottom = 0;
161 lpNewTask->te.wcEvents = 0;
162 lpNewTask->te.hQueue = 0;
163 sprintf(lpNewTask->te.szModule, "TASK%04X", hInst);
164 lpNewTask->te.wPSPOffset = 0;
165 lpNewTask->unix_pid = getpid();
166 lpNewTask->lpWndList = (HWND *) malloc(MAXWIN_PER_TASK * sizeof(HWND));
167 if (lpNewTask->lpWndList != NULL)
168 memset((LPSTR)lpNewTask->lpWndList, 0, MAXWIN_PER_TASK * sizeof(HWND));
169 #ifdef DEBUG_TASK
170 printf("CreateNewTask // unix_pid=%08X return hTask=%04X\n",
171 lpNewTask->unix_pid, hTask);
172 #endif
173 GlobalUnlock(hTask);
174 nTaskCount++;
175 return hTask;
179 /**********************************************************************
180 * AddWindowToTask [internal]
182 BOOL AddWindowToTask(HTASK hTask, HWND hWnd)
184 HWND *wptr;
185 int count = 0;
186 LPWINETASKENTRY lpTask = lpTaskList;
187 #ifdef DEBUG_TASK
188 printf("AddWindowToTask(%04X, %04X); !\n", hTask, hWnd);
189 #endif
190 while (TRUE) {
191 if (lpTask->te.hTask == hTask) break;
192 if (lpTask == NULL) {
193 printf("AddWindowToTask // hTask=%04X not found !\n", hTask);
194 return FALSE;
196 lpTask = lpTask->lpNextTask;
198 wptr = lpTask->lpWndList;
199 if (wptr == NULL) return FALSE;
200 while (*(wptr) != 0) {
201 if (++count >= MAXWIN_PER_TASK) return FALSE;
202 wptr++;
204 *wptr = hWnd;
205 #ifdef DEBUG_TASK
206 printf("AddWindowToTask // window added, count=%d !\n", count);
207 #endif
208 return TRUE;
212 /**********************************************************************
213 * RemoveWindowFromTask [internal]
215 BOOL RemoveWindowFromTask(HTASK hTask, HWND hWnd)
217 HWND *wptr;
218 int count = 0;
219 LPWINETASKENTRY lpTask = lpTaskList;
220 #ifdef DEBUG_TASK
221 printf("RemoveWindowToTask(%04X, %04X); !\n", hTask, hWnd);
222 #endif
223 while (TRUE) {
224 if (lpTask->te.hTask == hTask) break;
225 if (lpTask == NULL) {
226 printf("RemoveWindowFromTask // hTask=%04X not found !\n", hTask);
227 return FALSE;
229 lpTask = lpTask->lpNextTask;
231 wptr = lpTask->lpWndList;
232 if (wptr == NULL) return FALSE;
233 while (*(wptr) != hWnd) {
234 if (++count >= MAXWIN_PER_TASK) return FALSE;
235 wptr++;
237 while (*(wptr) != 0) {
238 *(wptr) = *(wptr + 1);
239 if (++count >= MAXWIN_PER_TASK) return FALSE;
240 wptr++;
242 #ifdef DEBUG_TASK
243 printf("RemoveWindowFromTask // window removed, count=%d !\n", --count);
244 #endif
245 return TRUE;