more rendering corrections
[AROS.git] / workbench / libs / desktop / desktop_init.c
blobb0c2435b25809e47b20bf01337af01053a38eaec
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <exec/resident.h>
10 #include <exec/memory.h>
11 #include <proto/exec.h>
12 #include <aros/symbolsets.h>
13 #include <libraries/desktop.h>
14 #include <libraries/mui.h>
16 #include <proto/exec.h>
17 #include <proto/muimaster.h>
19 #include "desktop_intern.h"
20 #include LC_LIBDEFS_FILE
21 #include "support.h"
23 #include "observer.h"
24 #include "presentation.h"
25 #include "iconcontainerclass.h"
26 #include "iconclass.h"
27 #include "diskiconclass.h"
28 #include "drawericonclass.h"
29 #include "tooliconclass.h"
30 #include "projecticonclass.h"
31 #include "trashcaniconclass.h"
32 #include "iconcontainerobserver.h"
33 #include "iconobserver.h"
34 #include "diskiconobserver.h"
35 #include "drawericonobserver.h"
36 #include "tooliconobserver.h"
37 #include "projecticonobserver.h"
38 #include "trashcaniconobserver.h"
39 #include "desktopobserver.h"
40 #include "operationclass.h"
41 #include "internaliconopsclass.h"
42 #include "internalwindowopsclass.h"
43 #include "internaldesktopopsclass.h"
44 #include "desktopclass.h"
45 #include "containericonobserver.h"
46 #include "abstracticon.h"
47 #include "abstracticoncontainer.h"
49 #include "desktop_intern_protos.h"
51 #define DEBUG 1
52 #include <aros/debug.h>
54 struct DesktopBase *DesktopBase;
56 static int Init(LIBBASETYPEPTR desktopbase)
59 This function is single-threaded by exec by calling Forbid. If you break
60 the Forbid() another task may enter this function at the same time. Take
61 care.
63 DesktopBase = desktopbase;
65 InitSemaphore(&DesktopBase->db_BaseMutex);
66 InitSemaphore(&DesktopBase->db_HandlerSafety);
68 D(bug("*** Entering DesktopBase::init...\n"));
70 DesktopBase->db_libsOpen = FALSE;
71 DesktopBase->db_HandlerPort = NULL;
73 these will be moved into a new DesktopContext area
75 DesktopBase->db_DefaultWindow = NULL;
76 DesktopBase->db_DefaultWindowArguments = NULL;
78 // TEMPORARY! see note in DesktopOperation struct, in desktop_intern.h
79 NEWLIST(&DesktopBase->db_OperationList);
80 // END TEMPORARY!
82 D(bug("*** Exitiing DesktopBase::init...\n"));
85 You would return NULL here if the init failed.
87 return TRUE;
91 static int Open(LIBBASETYPEPTR LIBBASE)
93 struct DesktopOperation *dob;
94 struct List *subList;
97 This function is single-threaded by exec by calling Forbid. If you break
98 the Forbid() another task may enter this function at the same time. Take
99 care.
102 D(bug("*** Entered DesktopBase::open...\n"));
104 ObtainSemaphore(&DesktopBase->db_BaseMutex);
106 if (DesktopBase->db_libsOpen == FALSE)
108 // Any of these could potentially break the Forbid(),
109 // so we have a semaphore
110 DesktopBase->db_InputIO =
111 AllocVec(sizeof(struct IORequest), MEMF_ANY);
112 if (OpenDevice
113 ("input.device", NULL,
114 (struct IORequest *) DesktopBase->db_InputIO, NULL))
115 return FALSE;
116 DesktopBase->db_InputBase =
117 (struct Library *) DesktopBase->db_InputIO->io_Device;
119 DesktopBase->db_Presentation =
120 MUI_CreateCustomClass(NULL, MUIC_Area, NULL,
121 sizeof(struct PresentationClassData),
122 presentationDispatcher);
123 if (!DesktopBase->db_Presentation)
124 return FALSE;
126 DesktopBase->db_AbstractIconContainer =
127 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Presentation,
128 sizeof(struct AbstractIconContainerData),
129 abstractIconContainerDispatcher);
130 if (!DesktopBase->db_AbstractIconContainer)
131 return FALSE;
135 DesktopBase->db_IconContainer =
136 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_AbstractIconContainer,
137 sizeof(struct IconContainerClassData),
138 iconContainerDispatcher);
139 if (!DesktopBase->db_IconContainer)
140 return FALSE;
143 DesktopBase->db_Observer =
144 MUI_CreateCustomClass(NULL, MUIC_Notify, NULL,
145 sizeof(struct ObserverClassData),
146 observerDispatcher);
147 if (!DesktopBase->db_Observer)
148 return FALSE;
150 DesktopBase->db_IconObserver =
151 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Observer,
152 sizeof(struct IconObserverClassData),
153 iconObserverDispatcher);
154 if (!DesktopBase->db_IconObserver)
155 return FALSE;
157 DesktopBase->db_ContainerIconObserver =
158 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_IconObserver,
159 sizeof(struct
160 ContainerIconObserverClassData),
161 containerIconObserverDispatcher);
162 if (!DesktopBase->db_ContainerIconObserver)
163 return FALSE;
165 DesktopBase->db_DiskIconObserver =
166 MUI_CreateCustomClass(NULL, NULL,
167 DesktopBase->db_ContainerIconObserver,
168 sizeof(struct DiskIconObserverClassData),
169 diskIconObserverDispatcher);
170 if (!DesktopBase->db_DiskIconObserver)
171 return FALSE;
173 DesktopBase->db_DrawerIconObserver =
174 MUI_CreateCustomClass(NULL, NULL,
175 DesktopBase->db_ContainerIconObserver,
176 sizeof(struct DrawerIconObserverClassData),
177 drawerIconObserverDispatcher);
178 if (!DesktopBase->db_DrawerIconObserver)
179 return FALSE;
181 DesktopBase->db_ToolIconObserver =
182 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_IconObserver,
183 sizeof(struct ToolIconObserverClassData),
184 toolIconObserverDispatcher);
185 if (!DesktopBase->db_ToolIconObserver)
186 return FALSE;
188 DesktopBase->db_ProjectIconObserver =
189 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_IconObserver,
190 sizeof(struct ProjectIconObserverClassData),
191 projectIconObserverDispatcher);
192 if (!DesktopBase->db_ProjectIconObserver)
193 return FALSE;
195 DesktopBase->db_TrashcanIconObserver =
196 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_IconObserver,
197 sizeof(struct
198 TrashcanIconObserverClassData),
199 trashcanIconObserverDispatcher);
200 if (!DesktopBase->db_TrashcanIconObserver)
201 return FALSE;
203 DesktopBase->db_IconContainerObserver =
204 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Observer,
205 sizeof(struct
206 IconContainerObserverClassData),
207 iconContainerObserverDispatcher);
208 if (!DesktopBase->db_IconContainerObserver)
209 return FALSE;
211 DesktopBase->db_DesktopObserver =
212 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Observer,
213 sizeof(struct DesktopObserverClassData),
214 desktopObserverDispatcher);
215 if (!DesktopBase->db_DesktopObserver)
216 return FALSE;
218 DesktopBase->db_AbstractIcon=MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Presentation, sizeof(struct AbstractIconClassData), abstractIconDispatcher);
219 if(!DesktopBase->db_AbstractIcon)
220 return FALSE;
222 DesktopBase->db_Icon =
223 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_AbstractIcon,
224 sizeof(struct IconClassData),
225 iconDispatcher);
226 if (!DesktopBase->db_Icon)
227 return FALSE;
229 DesktopBase->db_DiskIcon =
230 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Icon,
231 sizeof(struct DiskIconClassData),
232 diskIconDispatcher);
233 if (!DesktopBase->db_DiskIcon)
234 return FALSE;
236 DesktopBase->db_DrawerIcon =
237 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Icon,
238 sizeof(struct DrawerIconClassData),
239 drawerIconDispatcher);
240 if (!DesktopBase->db_DrawerIcon)
241 return FALSE;
243 DesktopBase->db_TrashcanIcon =
244 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Icon,
245 sizeof(struct TrashcanIconClassData),
246 trashcanIconDispatcher);
247 if (!DesktopBase->db_TrashcanIcon)
248 return FALSE;
250 DesktopBase->db_ToolIcon =
251 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Icon,
252 sizeof(struct ToolIconClassData),
253 toolIconDispatcher);
254 if (!DesktopBase->db_ToolIcon)
255 return FALSE;
257 DesktopBase->db_ProjectIcon =
258 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Icon,
259 sizeof(struct ProjectIconClassData),
260 projectIconDispatcher);
261 if (!DesktopBase->db_ProjectIcon)
262 return FALSE;
264 DesktopBase->db_Desktop =
265 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_IconContainer,
266 sizeof(struct DesktopClassData),
267 desktopDispatcher);
268 if (!DesktopBase->db_Desktop)
269 return FALSE;
271 // TEMPORARY! see note in DesktopOperation struct, in desktop_intern.h
272 DesktopBase->db_Operation =
273 MUI_CreateCustomClass(NULL, MUIC_Notify, NULL,
274 sizeof(struct OperationClassData),
275 operationDispatcher);
276 if (!DesktopBase->db_Operation)
277 return FALSE;
279 // 1
280 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
281 dob->do_Code = (DOC_ICONOP | 1);
282 dob->do_Name = "Open...";
283 dob->do_MutualExclude = 0;
284 dob->do_Flags = 0;
285 dob->do_Number = 1;
286 NEWLIST(&dob->do_SubItems);
287 dob->do_Impl =
288 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
289 sizeof(struct InternalIconOpsClassData),
290 internalIconOpsDispatcher);
291 AddTail(&DesktopBase->db_OperationList, (struct Node *) dob);
293 // 2
294 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
295 dob->do_Code = (DOC_WINDOWOP | 1);
296 dob->do_Name = "Close";
297 dob->do_MutualExclude = 0;
298 dob->do_Flags = 0;
299 dob->do_Number = 2;
300 NEWLIST(&dob->do_SubItems);
301 dob->do_Impl =
302 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
303 sizeof(struct InternalWindowOpsClassData),
304 internalWindowOpsDispatcher);
305 AddTail(&DesktopBase->db_OperationList, (struct Node *) dob);
307 // 3
308 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
309 dob->do_Code = (DOC_WINDOWOP | 2);
310 dob->do_Name = "View by";
311 dob->do_MutualExclude = 0;
312 dob->do_Flags = 0;
313 dob->do_Number = 3;
314 NEWLIST(&dob->do_SubItems);
315 subList = &dob->do_SubItems;
316 dob->do_Impl =
317 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
318 sizeof(struct InternalWindowOpsClassData),
319 internalWindowOpsDispatcher);
320 AddTail(&DesktopBase->db_OperationList, (struct Node *) dob);
322 // 4
323 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
324 dob->do_Code = (DOC_WINDOWOP | 3);
325 dob->do_Name = "Large icons";
326 dob->do_MutualExclude = (1 << 5) | (1 << 6);
327 dob->do_Flags = DOF_CHECKED | DOF_CHECKABLE | DOF_MUTUALEXCLUDE;
328 dob->do_Number = 4;
329 NEWLIST(&dob->do_SubItems);
330 dob->do_Impl =
331 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
332 sizeof(struct InternalWindowOpsClassData),
333 internalWindowOpsDispatcher);
334 AddTail(subList, (struct Node *) dob);
336 // 5
337 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
338 dob->do_Code = (DOC_WINDOWOP | 4);
339 dob->do_Name = "Small icons";
340 dob->do_MutualExclude = (1 << 4) | (1 << 6);
341 dob->do_Flags = DOF_CHECKABLE | DOF_MUTUALEXCLUDE;
342 dob->do_Number = 5;
343 NEWLIST(&dob->do_SubItems);
344 dob->do_Impl =
345 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
346 sizeof(struct InternalWindowOpsClassData),
347 internalWindowOpsDispatcher);
348 AddTail(subList, (struct Node *) dob);
350 // 6
351 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
352 dob->do_Code = (DOC_WINDOWOP | 5);
353 dob->do_Name = "Detail";
354 dob->do_MutualExclude = (1 << 4) | (1 << 5);
355 dob->do_Flags = DOF_CHECKABLE | DOF_MUTUALEXCLUDE;
356 dob->do_Number = 6;
357 NEWLIST(&dob->do_SubItems);
358 dob->do_Impl =
359 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
360 sizeof(struct InternalWindowOpsClassData),
361 internalWindowOpsDispatcher);
362 AddTail(subList, (struct Node *) dob);
364 // 7
365 dob = AllocVec(sizeof(struct DesktopOperation), MEMF_ANY);
366 dob->do_Code = (DOC_DESKTOPOP | 1);
367 dob->do_Name = "Quit";
368 dob->do_MutualExclude = 0;
369 dob->do_Flags = 0;
370 dob->do_Number = 7;
371 NEWLIST(&dob->do_SubItems);
372 dob->do_Impl =
373 MUI_CreateCustomClass(NULL, NULL, DesktopBase->db_Operation,
374 sizeof(struct InternalDesktopOpsClassData),
375 internalDesktopOpsDispatcher);
376 AddTail(&DesktopBase->db_OperationList, (struct Node *) dob);
377 // END TEMPORARY!
379 DesktopBase->db_libsOpen = TRUE;
382 if (!DesktopBase->db_HandlerPort)
383 startDesktopHandler();
385 handlerAddUser();
387 D(bug("*** Exiting DesktopBase::open...\n"));
389 ReleaseSemaphore(&DesktopBase->db_BaseMutex);
391 return TRUE;
395 static void Close(LIBBASETYPEPTR LIBBASE)
398 This function is single-threaded by exec by calling Forbid. If you
399 break the Forbid() another task may enter this function at the same
400 time. Take care.
402 D(bug("*** Entering DesktopBase::close...\n"));
404 handlerSubUser();
406 D(bug("*** Exiting DesktopBase::close...\n"));
409 static int Expunge(LIBBASETYPEPTR LIBBASE)
411 struct DesktopOperation *dob;
414 This function is single-threaded by exec by calling Forbid. Never break
415 the Forbid() or strange things might happen.
417 D(bug("*** Entering DesktopBase::expunge...\n"));
419 // TEMPORARY!
420 dob = (struct DesktopOperation *) DesktopBase->db_OperationList.lh_Head;
421 while (dob->do_Node.ln_Succ)
423 if (dob->do_Impl)
424 MUI_DeleteCustomClass(dob->do_Impl);
425 dob = (struct DesktopOperation *) dob->do_Node.ln_Succ;
427 FreeVec(dob);
429 if (DesktopBase->db_Operation)
430 MUI_DeleteCustomClass(DesktopBase->db_Operation);
431 // END TEMPORARY
433 if (DesktopBase->db_DiskIconObserver)
434 MUI_DeleteCustomClass(DesktopBase->db_DiskIconObserver);
435 if (DesktopBase->db_DrawerIconObserver)
436 MUI_DeleteCustomClass(DesktopBase->db_DrawerIconObserver);
437 if (DesktopBase->db_ToolIconObserver)
438 MUI_DeleteCustomClass(DesktopBase->db_ToolIconObserver);
439 if (DesktopBase->db_Desktop)
440 MUI_DeleteCustomClass(DesktopBase->db_Desktop);
441 if (DesktopBase->db_ProjectIconObserver)
442 MUI_DeleteCustomClass(DesktopBase->db_ProjectIconObserver);
443 if (DesktopBase->db_TrashcanIconObserver)
444 MUI_DeleteCustomClass(DesktopBase->db_TrashcanIconObserver);
445 if (DesktopBase->db_IconObserver)
446 MUI_DeleteCustomClass(DesktopBase->db_IconObserver);
447 if (DesktopBase->db_DesktopObserver)
448 MUI_DeleteCustomClass(DesktopBase->db_DesktopObserver);
449 if (DesktopBase->db_IconContainerObserver)
450 MUI_DeleteCustomClass(DesktopBase->db_IconContainerObserver);
451 if (DesktopBase->db_ContainerIconObserver)
452 MUI_DeleteCustomClass(DesktopBase->db_ContainerIconObserver);
453 if (DesktopBase->db_Observer)
454 MUI_DeleteCustomClass(DesktopBase->db_Observer);
455 if (DesktopBase->db_ToolIcon)
456 MUI_DeleteCustomClass(DesktopBase->db_ToolIcon);
457 if (DesktopBase->db_DiskIcon)
458 MUI_DeleteCustomClass(DesktopBase->db_DiskIcon);
459 if (DesktopBase->db_DrawerIcon)
460 MUI_DeleteCustomClass(DesktopBase->db_DrawerIcon);
461 if (DesktopBase->db_TrashcanIcon)
462 MUI_DeleteCustomClass(DesktopBase->db_TrashcanIcon);
463 if (DesktopBase->db_ProjectIcon)
464 MUI_DeleteCustomClass(DesktopBase->db_ProjectIcon);
465 if (DesktopBase->db_Icon)
466 MUI_DeleteCustomClass(DesktopBase->db_Icon);
467 if (DesktopBase->db_IconContainer)
468 MUI_DeleteCustomClass(DesktopBase->db_IconContainer);
469 if (DesktopBase->db_Presentation)
470 MUI_DeleteCustomClass(DesktopBase->db_Presentation);
472 if (DesktopBase->db_InputBase)
473 CloseDevice(&DesktopBase->db_InputIO);
475 return TRUE;
478 ADD2INITLIB(Init, 0);
479 ADD2OPENLIB(Open, 0);
480 ADD2CLOSELIB(Close, 0);
481 ADD2EXPUNGELIB(Expunge, 0);