- Now puts cursor position in window title properly instead of overwriting
[tangerine.git] / workbench / libs / desktop / support.c
bloba4f13fb54caa5a2162ba9ac8bd6e637f22c050ee
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <exec/memory.h>
10 #include <exec/nodes.h>
11 #include <dos/dos.h>
12 #include <dos/dostags.h>
13 #include <dos/dosextens.h>
14 #include <intuition/classes.h>
15 #include <libraries/desktop.h>
16 #include <libraries/gadtools.h>
17 #include <utility/tagitem.h>
19 #include <proto/dos.h>
20 #include <proto/exec.h>
21 #include <proto/intuition.h>
23 #include "desktop_intern.h"
24 #include "support.h"
26 #include "desktop_intern_protos.h"
28 #define DEBUG 1
29 #include <aros/debug.h>
31 BOOL startDesktopHandler(void)
34 NOTE: the OPEN vector (the only caller of this function)
35 already has a mutex on the library base at this point
37 struct Process *process = NULL;
38 struct Message *msg = NULL;
39 struct MsgPort *port = (struct MsgPort *) CreateMsgPort();
41 if (port == NULL)
43 D(bug("[desktop handler starter] ERROR: Could not create message port!\n"));
44 return FALSE;
47 D(bug("*** Starting desktop handler\n"));
48 process = CreateNewProcTags
50 NP_Entry, (IPTR) desktopHandler,
51 NP_Name, (IPTR) "Desktop Handler",
52 NP_StackSize, 8192,
53 NP_UserData, (IPTR) port,
55 TAG_DONE
58 if (process == NULL)
60 // FIXME: deallocate msgport??
61 D(bug("[desktop handler starter] ERROR: Could not start desktop handler process!\n"));
62 return FALSE;
65 WaitPort(port);
66 msg = GetMsg(port);
67 ReplyMsg(msg);
69 D(bug("*** Desktop Handler started OK\n"));
71 return TRUE;
74 BOOL handlerAddUser(void)
76 struct MsgPort *port;
77 struct DesktopInternMsg msg;
79 kprintf("/// Attempting to obtain semaphore\n");
80 if (!AttemptSemaphoreShared(&DesktopBase->db_HandlerSafety))
81 return FALSE;
83 port = CreateMsgPort();
84 if (port)
86 msg.di_Message.mn_Node.ln_Type = NT_MESSAGE;
87 msg.di_Message.mn_ReplyPort = port;
88 msg.di_Message.mn_Length = sizeof(struct DesktopInternMsg);
89 msg.di_Command = DIMC_ADDUSER;
91 PutMsg(DesktopBase->db_HandlerPort, (struct Message *) &msg);
93 kprintf("/// addmsg: awaitng reply from handler\n");
94 WaitPort(port);
95 GetMsg(port);
97 kprintf("/// addmsg: got reply, releasing semaphore\n");
99 ReleaseSemaphore(&DesktopBase->db_HandlerSafety);
101 return TRUE;
104 BOOL handlerSubUser(void)
106 struct MsgPort *port;
107 struct DesktopInternMsg msg;
109 port = CreateMsgPort();
110 if (port)
112 msg.di_Message.mn_Node.ln_Type = NT_MESSAGE;
113 msg.di_Message.mn_ReplyPort = port;
114 msg.di_Message.mn_Length = sizeof(struct DesktopInternMsg);
115 msg.di_Command = DIMC_SUBUSER;
117 PutMsg(DesktopBase->db_HandlerPort, (struct Message *) &msg);
119 WaitPort(port);
120 GetMsg(port);
123 return TRUE;
126 struct HandlerScanRequest *createScanMessage(ULONG command,
127 struct MsgPort *replyPort,
128 BPTR dirLock, Object * callback,
129 Object * app)
131 struct HandlerScanRequest *hsr;
133 hsr =
134 (struct HandlerScanRequest *)
135 AllocVec(sizeof(struct HandlerScanRequest), MEMF_ANY);
136 hsr->hsr_Message.di_Message.mn_Length = sizeof(struct HandlerScanRequest);
137 hsr->hsr_Message.di_Message.mn_Node.ln_Type = NT_MESSAGE;
138 hsr->hsr_Message.di_Message.mn_ReplyPort = replyPort;
139 hsr->hsr_Message.di_Command = command;
140 hsr->hsr_CallBack = callback;
141 hsr->hsr_DirLock = dirLock;
142 hsr->hsr_Application = app;
144 return hsr;
147 struct HandlerTopLevelRequest *createTLScanMessage(ULONG command,
148 struct MsgPort *replyPort,
149 ULONG types,
150 Object * callback,
151 Object * app)
153 struct HandlerTopLevelRequest *htl;
155 htl =
156 (struct HandlerTopLevelRequest *)
157 AllocVec(sizeof(struct HandlerTopLevelRequest), MEMF_ANY);
158 htl->htl_Message.di_Message.mn_Length = sizeof(struct HandlerScanRequest);
159 htl->htl_Message.di_Message.mn_Node.ln_Type = NT_MESSAGE;
160 htl->htl_Message.di_Message.mn_ReplyPort = replyPort;
161 htl->htl_Message.di_Command = command;
162 htl->htl_Types = types;
163 htl->htl_CallBack = callback;
164 htl->htl_Application = app;
166 return htl;
170 struct WorkingMessageNode *findWorkedMessage(struct MinList *list, ULONG id)
172 struct WorkingMessageNode *wmn;
173 BOOL found = FALSE;
175 wmn = (struct WorkingMessageNode *)list->mlh_Head;
176 while (!found && wmn->wm_Node.mln_Succ)
178 if (wmn->wm_ID == id)
179 found = TRUE;
180 else
181 wmn = (struct WorkingMessageNode *)wmn->wm_Node.mln_Succ;
184 return wmn;
188 BOOL findOperationItem(LONG menuNumber, struct DesktopOperationItem * doi,
189 struct NewMenu * menuDat, LONG * i)
191 LONG j = 0,
193 BOOL found = FALSE;
196 while (!found && doi[j].doi_Code != 0)
198 // find menu number in doi
199 if (doi[j].doi_Number == menuNumber)
201 // find matching entry in menudat
202 k = 0;
203 while (!found && menuDat[k].nm_Type != NM_END)
205 if (menuDat[k].nm_UserData == doi[j].doi_Code)
207 // kprintf("found mutex to exclude : %s\n", doi[j].doi_Name);
208 found = TRUE;
209 *i = k;
211 k++;
215 if (doi[j].doi_SubItems)
217 LONG m = 0;
219 while (!found && doi[j].doi_SubItems[m].doi_Code != 0)
221 if (doi[j].doi_SubItems[m].doi_Number == menuNumber)
223 // find matching entry in menudat
224 k = 0;
225 while (!found && menuDat[k].nm_Type != NM_END)
227 if (menuDat[k].nm_UserData ==
228 doi[j].doi_SubItems[m].doi_Code)
230 found = TRUE;
231 *i = k;
233 k++;
236 m++;
240 j++;
243 return found;
246 LONG getItemPosition(struct NewMenu * menuDat, LONG i)
248 LONG j = i - 1;
249 UBYTE menuType;
251 while (menuDat[j].nm_Type == menuDat[i].nm_Type)
252 j--;
254 return i - j - 1;
257 void doExclude(struct DesktopOperationItem *doi, struct NewMenu *menuDat,
258 LONG n)
260 LONG i = 0,
261 j = 0;
262 LONG bitNum;
264 while (doi[j].doi_Code != 0)
266 if (doi[j].doi_MutualExclude)
268 bitNum = 0;
269 while (bitNum < 32)
271 if (bitNum & doi[j].doi_MutualExclude)
273 if (findOperationItem(bitNum, doi, menuDat, &i))
274 menuDat[n].nm_MutualExclude |=
275 (1 << getItemPosition(menuDat, i));
278 bitNum++;
282 n++;
283 if (doi[j].doi_SubItems)
285 LONG k = 0;
287 while (doi[j].doi_SubItems[k].doi_Code != 0)
289 if (doi[j].doi_SubItems[k].doi_MutualExclude)
291 bitNum = 0;
292 while (bitNum < 32)
294 if ((1 << bitNum) & doi[j].doi_SubItems[k].
295 doi_MutualExclude)
297 if (findOperationItem(bitNum, doi, menuDat, &i))
298 menuDat[n].nm_MutualExclude |=
299 (1 << getItemPosition(menuDat, i));
302 bitNum++;
304 k++;
306 n++;
310 j++;
311 n++;
315 void processOperationItem(LONG * reali, LONG * realj,
316 struct DesktopOperationItem *doi,
317 struct NewMenu *menuDat)
319 LONG i = *reali,
320 j = *realj;
322 menuDat[i].nm_Type = NM_ITEM;
323 menuDat[i].nm_Label = doi[j].doi_Name;
324 menuDat[i].nm_CommKey = 0;
325 menuDat[i].nm_Flags = 0;
326 menuDat[i].nm_MutualExclude = 0;
328 if (doi[j].doi_Flags & DOIF_CHECKABLE)
330 menuDat[i].nm_Flags |= CHECKIT;
331 if (doi[j].doi_Flags & DOIF_CHECKED)
332 menuDat[i].nm_Flags |= CHECKED;
335 menuDat[i].nm_UserData = doi[j].doi_Code;
336 i++;
338 if (doi[j].doi_SubItems)
340 ULONG k = 0;
342 while (doi[j].doi_SubItems[k].doi_Code != 0
343 && doi[j].doi_SubItems[k].doi_Name != NULL)
345 menuDat[i].nm_Type = NM_SUB;
346 menuDat[i].nm_Label = doi[j].doi_SubItems[k].doi_Name;
347 menuDat[i].nm_CommKey = 0;
348 menuDat[i].nm_Flags = 0;
349 menuDat[i].nm_MutualExclude = 0;
351 if (doi[j].doi_SubItems[k].doi_Flags & DOIF_CHECKABLE)
353 menuDat[i].nm_Flags |= CHECKIT;
354 if (doi[j].doi_SubItems[k].doi_Flags & DOIF_CHECKED)
355 menuDat[i].nm_Flags |= CHECKED;
358 menuDat[i].nm_UserData = doi[j].doi_SubItems[k].doi_Code;
359 i++;
360 k++;
363 j++;
365 *reali = i;
366 *realj = j;