Minor fixes to comments.
[AROS.git] / rom / intuition / intuition_init.c
blob36d35b041cef82d211c07b58f100727a767d1aa0
1 /*
2 Copyright 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 /****************************************************************************************/
9 #include <string.h>
10 #include <exec/lists.h>
11 #include <exec/resident.h>
12 #include <exec/memory.h>
13 #include <exec/execbase.h>
14 #include <exec/alerts.h>
15 #include <hidd/graphics.h>
16 #include <oop/oop.h>
17 #include <proto/graphics.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/oop.h>
21 #include <proto/alib.h>
22 #include <devices/input.h>
23 #include <intuition/classes.h>
24 #include <intuition/pointerclass.h>
25 #include <utility/hooks.h>
26 #include <utility/utility.h>
27 #include <aros/symbolsets.h>
29 #include LC_LIBDEFS_FILE
31 #include "intuition_intern.h"
32 #include "strgadgets.h" /* To get GlobalEditFunc prototype */
33 #include "inputhandler.h"
34 #include "menutask.h"
35 #include "screennotifytask.h"
37 #ifdef SKINS
38 #include "transplayers.h"
39 #include "smallmenu.h"
40 #endif
42 #define DEBUG 0
43 #include <aros/debug.h>
45 #ifdef INTUITION_NOTIFY_SUPPORT
46 /* screennotify/notifyintuition init routines from notify.c */
47 struct Library *sn_Init(struct IntuitionBase *IntuitionBase);
48 struct Library *ni_Init(struct IntuitionBase *IntuitionBase);
49 #endif
51 /* There has to be a better way... */
53 AROS_UFP3(ULONG, rootDispatcher,
54 AROS_UFPA(Class *, cl, A0),
55 AROS_UFPA(Object *, obj, A2),
56 AROS_UFPA(Msg, msg, A1)
59 /****************************************************************************************/
61 /* Default colors for the new screen, the same as in AmigaOS 3.1 */
63 const ULONG coltab[] =
65 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
66 0x00000000, 0x00000000, 0x00000000, /* Black */
67 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
68 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
70 0xEEEEEEEE, 0x44444444, 0x44444444, /* Red */
71 0x55555555, 0xDDDDDDDD, 0x55555555, /* Green */
72 0x00000000, 0x44444444, 0xDDDDDDDD, /* Dark Blue */
73 0xEEEEEEEE, 0x99999999, 0x00000000, /* Yellow */
75 0xbbbbbbbb, 0x00000000, 0x00000000, /* Default colors for mouse pointer */
76 0xdddddddd, 0x00000000, 0x00000000,
77 0xeeeeeeee, 0x00000000, 0x00000000
80 static int IntuitionInit(LIBBASETYPEPTR LIBBASE)
82 struct Library *OOPBase;
83 struct GfxBase *GfxBase;
84 struct OOP_ABDescr attrbases[] = {
85 {IID_Hidd , &GetPrivIBase(LIBBASE)->HiddAttrBase },
86 {IID_Hidd_Gfx , &GetPrivIBase(LIBBASE)->HiddGfxAttrBase },
87 {IID_Hidd_PixFmt, &GetPrivIBase(LIBBASE)->HiddPixFmtAttrBase},
88 {NULL , NULL }
91 DEBUG_INIT(dprintf("LIB_Init: base 0x%p\n", LIBBASE));
93 /* Open our dependencies */
94 if (!(GetPrivIBase(LIBBASE)->UtilityBase = OpenLibrary("utility.library", 0))) {
95 return FALSE;
96 } else if (!(GfxBase = GetPrivIBase(LIBBASE)->GfxBase = (APTR)OpenLibrary("graphics.library", 41))) {
97 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
98 return FALSE;
99 } else if (!(GetPrivIBase(LIBBASE)->LayersBase = (APTR)OpenLibrary("layers.library", 41))) {
100 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
101 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
102 return FALSE;
103 } else if (!(GetPrivIBase(LIBBASE)->KeymapBase = (APTR)OpenLibrary("keymap.library", 41))) {
104 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
105 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
106 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
107 return FALSE;
108 } else if (!(OOPBase = GetPrivIBase(LIBBASE)->OOPBase = (APTR)OpenLibrary("oop.library", 41))) {
109 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->KeymapBase);
110 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
111 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
112 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
113 return FALSE;
116 LIBBASE->ib_HiddBitMapBase = OOP_GetMethodID(IID_Hidd_BitMap, 0);
117 LIBBASE->ib_HiddGfxBase = OOP_GetMethodID(IID_Hidd_Gfx, 0);
119 if (!OOP_ObtainAttrBases(attrbases))
120 return FALSE;
122 /* FIXME: This libInit is all broken if something should fail, but do we care? */
123 /* FIXME: If something fails we're screwed anyway... */
125 /* We have to open this here, but it doesn't do any allocations,
126 so it shouldn't fail...
129 /* Create semaphore and initialize it */
130 GetPrivIBase(LIBBASE)->IBaseLock = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
132 if (!GetPrivIBase(LIBBASE)->IBaseLock)
133 return FALSE;
135 InitSemaphore(GetPrivIBase(LIBBASE)->IBaseLock);
137 InitSemaphore(&GetPrivIBase(LIBBASE)->WinDecorSem);
138 InitSemaphore(&GetPrivIBase(LIBBASE)->ScrDecorSem);
139 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuDecorSem);
141 /* Initialize global stringgadget edit hook */
142 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Entry = (APTR)AROS_ASMSYMNAME(GlobalEditFunc);
143 GetPrivIBase(LIBBASE)->DefaultEditHook.h_SubEntry = NULL;
144 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Data = LIBBASE;
146 GetPrivIBase(LIBBASE)->GlobalEditHook = &(GetPrivIBase(LIBBASE)->DefaultEditHook);
148 GetPrivIBase(LIBBASE)->DefaultPubScreen = NULL;
149 NEWLIST(&GetPrivIBase(LIBBASE)->PubScreenList);
150 InitSemaphore(&GetPrivIBase(LIBBASE)->PubScrListLock);
152 InitSemaphore(&GetPrivIBase(LIBBASE)->ScreenNotificationListLock);
153 NEWLIST(&GetPrivIBase(LIBBASE)->ScreenNotificationList);
155 NEWLIST(&GetPrivIBase(LIBBASE)->Decorations);
158 InitSemaphore(&GetPrivIBase(LIBBASE)->GadgetLock);
159 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuLock);
160 InitSemaphore(&GetPrivIBase(LIBBASE)->WindowLock);
161 InitSemaphore(&GetPrivIBase(LIBBASE)->IntuiActionLock);
162 InitSemaphore(&GetPrivIBase(LIBBASE)->InputHandlerLock);
164 #ifdef SKINS
165 InitSemaphore(&GetPrivIBase(LIBBASE)->DataTypesSem);
166 GetPrivIBase(LIBBASE)->DataTypesBase = 0;
168 GetPrivIBase(LIBBASE)->transphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
169 GetPrivIBase(LIBBASE)->transphook.h_Entry = (HOOKFUNC)HookEntry;
170 GetPrivIBase(LIBBASE)->transphook.h_SubEntry = (HOOKFUNC)WindowTranspFunc;
172 GetPrivIBase(LIBBASE)->notransphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
173 GetPrivIBase(LIBBASE)->notransphook.h_Entry = (HOOKFUNC)HookEntry;
174 GetPrivIBase(LIBBASE)->notransphook.h_SubEntry = (HOOKFUNC)WindowNoTranspFunc;
175 #endif
177 #ifdef __MORPHOS__
178 memset(GetPrivIBase(LIBBASE)->Pad, 0xee, sizeof(GetPrivIBase(LIBBASE)->Pad));
179 GetPrivIBase(LIBBASE)->SystemRequestTitle = "System Request";
180 GetPrivIBase(LIBBASE)->WorkbenchTitle = "Ambient Screen";
181 #endif
183 * Setup the default pens to the default
184 * colors so that screens have proper color
185 * even before IPrefs is loaded.
188 struct Color32 *p;
189 ULONG i;
191 p = GetPrivIBase(LIBBASE)->Colors;
193 for (i = 0; i < COLORTABLEENTRIES; i++)
195 p[i].red = coltab[i*3];
196 p[i].green = coltab[i*3+1];
197 p[i].blue = coltab[i*3+2];
200 LIBBASE->PointerAlpha = 0x9F9F;
202 #ifdef __MORPHOS__
203 GetPrivIBase(LIBBASE)->mosmenuclass = InitMuiMenuClass(LIBBASE);
204 #endif
206 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
207 /* FIXME: no cleanup routines for MenuHandler task */
208 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
209 return FALSE;
211 /* FIXME: no cleanup routines for ScreennotifyHandler task */
212 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
213 return FALSE;
216 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
217 LoadDefaultPreferences(GetPubIBase(LIBBASE));
218 #ifdef USEGETIPREFS
219 GetPrivIBase(LIBBASE)->IPrefsLoaded = FALSE;
220 #endif
222 #ifdef SKINS
223 if (!GetPrivIBase(LIBBASE)->SmallMenuPool)
225 if (!(GetPrivIBase(LIBBASE)->SmallMenuPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct SmallMenuEntry))*20,(sizeof (struct SmallMenuEntry))*20))) return NULL;
227 #endif
229 if (!(GetPrivIBase(LIBBASE)->IDCMPPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct IntIntuiMessage)) * 100,sizeof (struct IntIntuiMessage)))) return FALSE;
231 #ifdef SKINS
232 strcpy(GetPrivIBase(LIBBASE)->IControlExtensions.ice_ClockFormat,"%X");
233 #endif
235 GetPrivIBase(LIBBASE)->FrameSize = FRAMESIZE_THIN;
238 WORD i;
240 for(i = 0; i < RESOURCELIST_HASHSIZE; i++)
242 NewList((struct List *)&GetPrivIBase(LIBBASE)->ResourceList[i]);
246 GetPrivIBase(LIBBASE)->ScrDecorClass = FindClass(SCRDECORCLASS);
247 GetPrivIBase(LIBBASE)->ScrDecorTags = NULL;
248 GetPrivIBase(LIBBASE)->MenuDecorClass = FindClass(MENUDECORCLASS);
249 GetPrivIBase(LIBBASE)->MenuDecorTags = NULL;
250 GetPrivIBase(LIBBASE)->WinDecorClass = FindClass(WINDECORCLASS);
251 GetPrivIBase(LIBBASE)->WinDecorTags = NULL;
252 LIBBASE->ViewLord_ok = FALSE;
254 DEBUG_INIT(dprintf("LIB_Init: Setting up pointers...\n"));
256 GetPrivIBase(LIBBASE)->DefaultPointer = MakePointerFromPrefs
258 GetPubIBase(LIBBASE), GetPrivIBase(LIBBASE)->ActivePreferences
260 GetPrivIBase(LIBBASE)->BusyPointer = MakePointerFromPrefs
262 GetPubIBase(LIBBASE), GetPrivIBase(LIBBASE)->ActivePreferences
267 !GetPrivIBase(LIBBASE)->DefaultPointer
268 || !GetPrivIBase(LIBBASE)->BusyPointer
271 return FALSE;
274 NEWLIST(&GetPrivIBase(LIBBASE)->MonitorList);
275 InitSemaphore(&GetPrivIBase(LIBBASE)->MonitorListSem);
276 SetDisplayDriverCallback(DisplayDriverNotify, LIBBASE);
278 DEBUG_INIT(dprintf("LIB_Init: done\n"));
280 return TRUE;
283 static int InitRootClass(LIBBASETYPEPTR LIBBASE)
285 InitSemaphore(&GetPrivIBase(LIBBASE)->ClassListLock);
286 NEWLIST(&GetPrivIBase(LIBBASE)->ClassList);
288 /* Setup root class */
290 GetPrivIBase(LIBBASE)->RootClass.cl_Dispatcher.h_Entry = (APTR)AROS_ASMSYMNAME(rootDispatcher);
291 GetPrivIBase(LIBBASE)->RootClass.cl_ID = (ClassID)ROOTCLASS;
292 GetPrivIBase(LIBBASE)->RootClass.cl_UserData = (IPTR)LIBBASE;
293 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
294 AddClass(&(GetPrivIBase(LIBBASE)->RootClass));
296 return TRUE;
299 /****************************************************************************************/
301 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE)
303 struct GfxBase *GfxBase = GetPrivIBase(LIBBASE)->GfxBase;
304 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE));
306 /* Open the input device */
308 if (!GetPrivIBase(LIBBASE)->InputMP)
310 if (!(GetPrivIBase(LIBBASE)->InputMP = CreateMsgPort()))
312 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
313 return FALSE;
317 if (!GetPrivIBase(LIBBASE)->InputIO)
319 if (!(GetPrivIBase(LIBBASE)->InputIO = (struct IOStdReq *)
320 CreateIORequest(GetPrivIBase(LIBBASE)->InputMP, sizeof (struct IOStdReq))) )
322 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
323 return FALSE;
327 if (!GetPrivIBase(LIBBASE)->InputDeviceOpen)
329 if (!OpenDevice("input.device", -1, (struct IORequest *)GetPrivIBase(LIBBASE)->InputIO, 0))
331 GetPrivIBase(LIBBASE)->InputDeviceOpen = TRUE;
332 GetPrivIBase(LIBBASE)->InputBase = (struct Library *)GetPrivIBase(LIBBASE)->InputIO->io_Device;
334 else
336 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
337 return FALSE;
341 if (!GetPrivIBase(LIBBASE)->InputHandler)
343 D(bug("Initializing inputhandler\n"));
344 if ( !(GetPrivIBase(LIBBASE)->InputHandler = InitIIH(GetPubIBase(LIBBASE))) )
346 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
347 return FALSE;
350 D(bug("Adding inputhandler\n"));
351 GetPrivIBase(LIBBASE)->InputIO->io_Data = (APTR)GetPrivIBase(LIBBASE)->InputHandler;
352 GetPrivIBase(LIBBASE)->InputIO->io_Command = IND_ADDHANDLER;
354 D(bug("Calling DoIO()\n"));
355 DoIO((struct IORequest *)GetPrivIBase(LIBBASE)->InputIO);
356 D(bug("DoIO() called\n"));
359 if (!LIBBASE->ViewLord_ok)
361 #ifdef __MORPHOS__
362 struct ViewExtra *ve;
364 if (!(ve = GfxNew(VIEW_EXTRA_TYPE)))
366 GetPrivIBase(LIBBASE)->GfxBase = NULL;
367 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
368 return FALSE;
370 #endif
371 D(bug("[intuition] Calling InitView()\n"));
372 InitView(&LIBBASE->IBase.ViewLord);
373 #ifdef __MORPHOS__
374 GfxAssociate(&LIBBASE->IBase.ViewLord, ve);
376 GetPrivIBase(LIBBASE)->ViewLordExtra = ve;
377 GetPrivIBase(LIBBASE)->SpriteNum = -1;
378 #endif
379 LIBBASE->ViewLord_ok = TRUE;
382 if (!GetPrivIBase(LIBBASE)->ScreenFont)
383 GetPrivIBase(LIBBASE)->ScreenFont = GetPrivIBase(LIBBASE)->GfxBase->DefaultFont;
385 #if 0 /* CHECKME: stegerg: backport, disabled */
386 if (!(GetPrivIBase(LIBBASE)->TopazFont))
388 struct TextAttr textattr = {"topaz.font",8,0,FPF_ROMFONT};
389 GetPrivIBase(LIBBASE)->TopazFont = OpenFont(&textattr);
391 #endif
393 if (!GetPrivIBase(LIBBASE)->TimerBase)
395 if (!(GetPrivIBase(LIBBASE)->TimerMP = CreateMsgPort()))
397 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
398 return FALSE; /* don't close anything */
401 if (!(GetPrivIBase(LIBBASE)->TimerIO = (struct timerequest *)CreateIORequest(GetPrivIBase(LIBBASE)->TimerMP, sizeof(struct timerequest))))
403 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
404 return FALSE; /* don't close anything */
407 if (OpenDevice(TIMERNAME,UNIT_VBLANK, (struct IORequest *)GetPrivIBase(LIBBASE)->TimerIO,0))
409 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
410 return FALSE; /* don't close anything */
413 GetPrivIBase(LIBBASE)->TimerBase = (struct Library *)GetPrivIBase(LIBBASE)->TimerIO->tr_node.io_Device;
415 SetPrefs(GetPrivIBase(LIBBASE)->DefaultPreferences, sizeof(struct Preferences), FALSE);
418 #if 0
419 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
421 //check if dos is opened!!!
422 ((struct DosLibrary *)DOSBase)->dl_IntuitionBase =
423 (struct Library *)LIBBASE;
425 /* Install intuition's version of DisplayError() that puts up
426 a requester with Retry/Cancel options */
427 GetPrivIBase(LIBBASE)->OldDisplayErrorFunc =
428 SetFunction(DOSBase, -81*LIB_VECTSIZE,
429 AROS_SLIB_ENTRY(DisplayError, Intuition, 81));
431 #else
432 # ifdef SKINS
433 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
435 InitSkinManager(GetPubIBase(LIBBASE));
437 # endif
438 #endif
440 /* FIXME: no cleanup routines for MenuHandler task */
441 if (!GetPrivIBase(LIBBASE)->MenuHandlerPort)
443 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
444 return FALSE;
447 /* FIXME: no cleanup routines for ScreennotifyHandler task */
448 if (!GetPrivIBase(LIBBASE)->ScreenNotifyReplyPort)
450 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
451 return FALSE;
454 #ifdef INTUITION_NOTIFY_SUPPORT
455 /* Add screennotify.library base if not there yet - Piru
457 if (!GetPrivIBase(LIBBASE)->ScreenNotifyBase)
459 GetPrivIBase(LIBBASE)->ScreenNotifyBase = sn_Init(GetPubIBase(LIBBASE));
462 # if 0 /* not finished yet - Piru */
463 /* Add notifyintuition.library base if not there yet - Piru
465 if (!GetPrivIBase(LIBBASE)->NotifyIntuitionBase)
467 GetPrivIBase(LIBBASE)->NotifyIntuitionBase = ni_Init(GetPubIBase(LIBBASE));
469 # endif
470 #endif
472 return TRUE;
475 DECLARESET(CLASSESINIT);
476 ADD2SET(InitRootClass, CLASSESINIT, -20);
477 ADD2INITLIB(IntuitionInit, 0);
478 ADD2OPENLIB(IntuitionOpen, 0);