binutils 2.32 courtesy of NicJA.
[AROS.git] / rom / intuition / intuition_init.c
blob8edfa30d2fed3e4b114afcc9495c4175b74266f0
1 /*
2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2013, 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/gfx.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_Sync , &GetPrivIBase(LIBBASE)->HiddSyncAttrBase },
88 {IID_Hidd_BitMap, &GetPrivIBase(LIBBASE)->HiddBitMapAttrBase},
89 {IID_Hidd_PixFmt, &GetPrivIBase(LIBBASE)->HiddPixFmtAttrBase},
90 {NULL , NULL }
93 DEBUG_INIT(dprintf("LIB_Init: base 0x%p\n", LIBBASE));
94 #if defined(__AROSEXEC_SMP__)
95 GetPrivIBase(LIBBASE)->ExecLockBase = OpenResource("execlock.resource");
96 #endif
97 /* Open our dependencies */
98 if (!(GetPrivIBase(LIBBASE)->UtilityBase = OpenLibrary("utility.library", 0))) {
99 return FALSE;
100 } else if (!(GfxBase = GetPrivIBase(LIBBASE)->GfxBase = (APTR)OpenLibrary("graphics.library", 41))) {
101 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
102 return FALSE;
103 } else if (!(GetPrivIBase(LIBBASE)->LayersBase = (APTR)OpenLibrary("layers.library", 41))) {
104 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
105 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
106 return FALSE;
107 } else if (!(GetPrivIBase(LIBBASE)->KeymapBase = (APTR)OpenLibrary("keymap.library", 41))) {
108 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
109 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
110 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
111 return FALSE;
112 } else if (!(OOPBase = GetPrivIBase(LIBBASE)->OOPBase = (APTR)OpenLibrary("oop.library", 41))) {
113 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->KeymapBase);
114 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
115 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
116 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
117 return FALSE;
120 LIBBASE->ib_HiddBitMapBase = OOP_GetMethodID(IID_Hidd_BitMap, 0);
121 LIBBASE->ib_HiddGfxBase = OOP_GetMethodID(IID_Hidd_Gfx, 0);
123 if (!OOP_ObtainAttrBases(attrbases))
124 return FALSE;
126 /* FIXME: This libInit is all broken if something should fail, but do we care? */
127 /* FIXME: If something fails we're screwed anyway... */
129 /* We have to open this here, but it doesn't do any allocations,
130 so it shouldn't fail...
133 /* Create semaphore and initialize it */
134 GetPrivIBase(LIBBASE)->IBaseLock = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
136 if (!GetPrivIBase(LIBBASE)->IBaseLock)
137 return FALSE;
139 InitSemaphore(GetPrivIBase(LIBBASE)->IBaseLock);
141 InitSemaphore(&GetPrivIBase(LIBBASE)->WinDecorSem);
142 InitSemaphore(&GetPrivIBase(LIBBASE)->ScrDecorSem);
143 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuDecorSem);
145 /* Initialize global stringgadget edit hook */
146 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Entry = (APTR)AROS_ASMSYMNAME(GlobalEditFunc);
147 GetPrivIBase(LIBBASE)->DefaultEditHook.h_SubEntry = NULL;
148 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Data = LIBBASE;
150 GetPrivIBase(LIBBASE)->GlobalEditHook = &(GetPrivIBase(LIBBASE)->DefaultEditHook);
152 GetPrivIBase(LIBBASE)->DefaultPubScreen = NULL;
153 NEWLIST(&GetPrivIBase(LIBBASE)->PubScreenList);
154 InitSemaphore(&GetPrivIBase(LIBBASE)->PubScrListLock);
156 InitSemaphore(&GetPrivIBase(LIBBASE)->ScreenNotificationListLock);
157 NEWLIST(&GetPrivIBase(LIBBASE)->ScreenNotificationList);
159 NEWLIST(&GetPrivIBase(LIBBASE)->Decorations);
162 InitSemaphore(&GetPrivIBase(LIBBASE)->GadgetLock);
163 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuLock);
164 InitSemaphore(&GetPrivIBase(LIBBASE)->WindowLock);
165 InitSemaphore(&GetPrivIBase(LIBBASE)->IntuiActionLock);
166 InitSemaphore(&GetPrivIBase(LIBBASE)->InputHandlerLock);
168 #ifdef SKINS
169 InitSemaphore(&GetPrivIBase(LIBBASE)->DataTypesSem);
170 GetPrivIBase(LIBBASE)->DataTypesBase = 0;
172 GetPrivIBase(LIBBASE)->transphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
173 GetPrivIBase(LIBBASE)->transphook.h_Entry = (HOOKFUNC)HookEntry;
174 GetPrivIBase(LIBBASE)->transphook.h_SubEntry = (HOOKFUNC)WindowTranspFunc;
176 GetPrivIBase(LIBBASE)->notransphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
177 GetPrivIBase(LIBBASE)->notransphook.h_Entry = (HOOKFUNC)HookEntry;
178 GetPrivIBase(LIBBASE)->notransphook.h_SubEntry = (HOOKFUNC)WindowNoTranspFunc;
179 #endif
181 #ifdef __MORPHOS__
182 memset(GetPrivIBase(LIBBASE)->Pad, 0xee, sizeof(GetPrivIBase(LIBBASE)->Pad));
183 GetPrivIBase(LIBBASE)->SystemRequestTitle = "System Request";
184 GetPrivIBase(LIBBASE)->WorkbenchTitle = "Ambient Screen";
185 #endif
187 * Setup the default pens to the default
188 * colors so that screens have proper color
189 * even before IPrefs is loaded.
192 struct Color32 *p;
193 ULONG i;
195 p = GetPrivIBase(LIBBASE)->Colors;
197 for (i = 0; i < COLORTABLEENTRIES; i++)
199 p[i].red = coltab[i*3];
200 p[i].green = coltab[i*3+1];
201 p[i].blue = coltab[i*3+2];
204 LIBBASE->PointerAlpha = 0x9F9F;
206 #ifdef __MORPHOS__
207 GetPrivIBase(LIBBASE)->mosmenuclass = InitMuiMenuClass(LIBBASE);
208 #endif
210 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
211 /* FIXME: no cleanup routines for MenuHandler task */
212 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
213 return FALSE;
215 /* FIXME: no cleanup routines for ScreennotifyHandler task */
216 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
217 return FALSE;
220 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
221 LoadDefaultPreferences(GetPubIBase(LIBBASE));
222 #ifdef USEGETIPREFS
223 GetPrivIBase(LIBBASE)->IPrefsLoaded = FALSE;
224 #endif
226 #ifdef SKINS
227 if (!GetPrivIBase(LIBBASE)->SmallMenuPool)
229 if (!(GetPrivIBase(LIBBASE)->SmallMenuPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct SmallMenuEntry))*20,(sizeof (struct SmallMenuEntry))*20))) return NULL;
231 #endif
233 if (!(GetPrivIBase(LIBBASE)->IDCMPPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct IntIntuiMessage)) * 100,sizeof (struct IntIntuiMessage)))) return FALSE;
235 #ifdef SKINS
236 strcpy(GetPrivIBase(LIBBASE)->IControlExtensions.ice_ClockFormat,"%X");
237 #endif
239 GetPrivIBase(LIBBASE)->FrameSize = FRAMESIZE_THIN;
242 WORD i;
244 for(i = 0; i < RESOURCELIST_HASHSIZE; i++)
246 NewList((struct List *)&GetPrivIBase(LIBBASE)->ResourceList[i]);
250 GetPrivIBase(LIBBASE)->ScrDecorClass = FindClass(SCRDECORCLASS);
251 GetPrivIBase(LIBBASE)->ScrDecorTags = NULL;
252 GetPrivIBase(LIBBASE)->MenuDecorClass = FindClass(MENUDECORCLASS);
253 GetPrivIBase(LIBBASE)->MenuDecorTags = NULL;
254 GetPrivIBase(LIBBASE)->WinDecorClass = FindClass(WINDECORCLASS);
255 GetPrivIBase(LIBBASE)->WinDecorTags = NULL;
256 LIBBASE->ViewLord_ok = FALSE;
258 DEBUG_INIT(dprintf("LIB_Init: Setting up pointers...\n"));
260 GetPrivIBase(LIBBASE)->DefaultPointer = MakePointerFromPrefs
262 GetPubIBase(LIBBASE), &GetPrivIBase(LIBBASE)->ActivePreferences
264 GetPrivIBase(LIBBASE)->BusyPointer = MakePointerFromPrefs
266 GetPubIBase(LIBBASE), &GetPrivIBase(LIBBASE)->ActivePreferences
271 !GetPrivIBase(LIBBASE)->DefaultPointer
272 || !GetPrivIBase(LIBBASE)->BusyPointer
275 return FALSE;
278 NEWLIST(&GetPrivIBase(LIBBASE)->MonitorList);
279 InitSemaphore(&GetPrivIBase(LIBBASE)->MonitorListSem);
280 SetDisplayDriverCallback(DisplayDriverNotify, LIBBASE);
282 /* Install reset handler to display manual shutdown screen */
283 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Node.ln_Name =
284 LIBBASE->Base.LibNode.lib_Node.ln_Name;
285 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Node.ln_Pri = -96;
286 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Code =
287 (VOID_FUNC)ShutdownScreenHandler;
288 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Data =
289 &GetPrivIBase(LIBBASE)->ShutdownHandler;
290 AddResetCallback(&GetPrivIBase(LIBBASE)->ShutdownHandler);
292 DEBUG_INIT(dprintf("LIB_Init: done\n"));
294 return TRUE;
297 static int InitRootClass(LIBBASETYPEPTR LIBBASE)
299 InitSemaphore(&GetPrivIBase(LIBBASE)->ClassListLock);
300 NEWLIST(&GetPrivIBase(LIBBASE)->ClassList);
302 /* Setup root class */
304 GetPrivIBase(LIBBASE)->RootClass.cl_Dispatcher.h_Entry = (APTR)AROS_ASMSYMNAME(rootDispatcher);
305 GetPrivIBase(LIBBASE)->RootClass.cl_ID = (ClassID)ROOTCLASS;
306 GetPrivIBase(LIBBASE)->RootClass.cl_UserData = (IPTR)LIBBASE;
307 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
308 AddClass(&(GetPrivIBase(LIBBASE)->RootClass));
310 return TRUE;
313 /****************************************************************************************/
315 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE)
317 struct GfxBase *GfxBase = GetPrivIBase(LIBBASE)->GfxBase;
318 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE));
320 /* Open the input device */
322 if (!GetPrivIBase(LIBBASE)->InputMP)
324 if (!(GetPrivIBase(LIBBASE)->InputMP = CreateMsgPort()))
326 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
327 return FALSE;
331 if (!GetPrivIBase(LIBBASE)->InputIO)
333 if (!(GetPrivIBase(LIBBASE)->InputIO = (struct IOStdReq *)
334 CreateIORequest(GetPrivIBase(LIBBASE)->InputMP, sizeof (struct IOStdReq))) )
336 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
337 return FALSE;
341 if (!GetPrivIBase(LIBBASE)->InputDeviceOpen)
343 if (!OpenDevice("input.device", -1, (struct IORequest *)GetPrivIBase(LIBBASE)->InputIO, 0))
345 GetPrivIBase(LIBBASE)->InputDeviceOpen = TRUE;
346 GetPrivIBase(LIBBASE)->InputBase = (struct Library *)GetPrivIBase(LIBBASE)->InputIO->io_Device;
348 else
350 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
351 return FALSE;
355 if (!GetPrivIBase(LIBBASE)->InputHandler)
357 D(bug("Initializing inputhandler\n"));
358 if ( !(GetPrivIBase(LIBBASE)->InputHandler = InitIIH(GetPubIBase(LIBBASE))) )
360 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
361 return FALSE;
364 D(bug("Adding inputhandler\n"));
365 GetPrivIBase(LIBBASE)->InputIO->io_Data = (APTR)GetPrivIBase(LIBBASE)->InputHandler;
366 GetPrivIBase(LIBBASE)->InputIO->io_Command = IND_ADDHANDLER;
368 D(bug("Calling DoIO()\n"));
369 DoIO((struct IORequest *)GetPrivIBase(LIBBASE)->InputIO);
370 D(bug("DoIO() called\n"));
373 if (!LIBBASE->ViewLord_ok)
375 #ifdef __MORPHOS__
376 struct ViewExtra *ve;
378 if (!(ve = GfxNew(VIEW_EXTRA_TYPE)))
380 GetPrivIBase(LIBBASE)->GfxBase = NULL;
381 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
382 return FALSE;
384 #endif
385 D(bug("[intuition] Calling InitView()\n"));
386 InitView(&LIBBASE->Base.ViewLord);
387 InitSemaphore(&LIBBASE->ViewLordLock);
388 #ifdef __MORPHOS__
389 GfxAssociate(&LIBBASE->Base.ViewLord, ve);
391 GetPrivIBase(LIBBASE)->ViewLordExtra = ve;
392 GetPrivIBase(LIBBASE)->SpriteNum = -1;
393 #endif
394 LIBBASE->ViewLord_ok = TRUE;
397 if (!GetPrivIBase(LIBBASE)->ScreenFont)
398 GetPrivIBase(LIBBASE)->ScreenFont = GetPrivIBase(LIBBASE)->GfxBase->DefaultFont;
400 #if 0 /* CHECKME: stegerg: backport, disabled */
401 if (!(GetPrivIBase(LIBBASE)->TopazFont))
403 struct TextAttr textattr = {"topaz.font",8,0,FPF_ROMFONT};
404 GetPrivIBase(LIBBASE)->TopazFont = OpenFont(&textattr);
406 #endif
408 if (!GetPrivIBase(LIBBASE)->TimerBase)
410 if (!(GetPrivIBase(LIBBASE)->TimerMP = CreateMsgPort()))
412 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
413 return FALSE; /* don't close anything */
416 if (!(GetPrivIBase(LIBBASE)->TimerIO = (struct timerequest *)CreateIORequest(GetPrivIBase(LIBBASE)->TimerMP, sizeof(struct timerequest))))
418 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
419 return FALSE; /* don't close anything */
422 if (OpenDevice(TIMERNAME,UNIT_VBLANK, (struct IORequest *)GetPrivIBase(LIBBASE)->TimerIO,0))
424 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
425 return FALSE; /* don't close anything */
428 GetPrivIBase(LIBBASE)->TimerBase = (struct Library *)GetPrivIBase(LIBBASE)->TimerIO->tr_node.io_Device;
430 SetPrefs(&GetPrivIBase(LIBBASE)->DefaultPreferences, sizeof(struct Preferences), FALSE);
433 #if 0
434 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
436 //check if dos is opened!!!
437 ((struct DosLibrary *)DOSBase)->dl_IntuitionBase =
438 (struct Library *)LIBBASE;
440 /* Install intuition's version of DisplayError() that puts up
441 a requester with Retry/Cancel options */
442 GetPrivIBase(LIBBASE)->OldDisplayErrorFunc =
443 SetFunction(DOSBase, -81*LIB_VECTSIZE,
444 AROS_SLIB_ENTRY(DisplayError, Intuition, 81));
446 #else
447 # ifdef SKINS
448 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
450 InitSkinManager(GetPubIBase(LIBBASE));
452 # endif
453 #endif
455 /* FIXME: no cleanup routines for MenuHandler task */
456 if (!GetPrivIBase(LIBBASE)->MenuHandlerPort)
458 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
459 return FALSE;
462 /* FIXME: no cleanup routines for ScreennotifyHandler task */
463 if (!GetPrivIBase(LIBBASE)->ScreenNotifyReplyPort)
465 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
466 return FALSE;
469 #ifdef INTUITION_NOTIFY_SUPPORT
470 /* Add screennotify.library base if not there yet - Piru
472 if (!GetPrivIBase(LIBBASE)->ScreenNotifyBase)
474 GetPrivIBase(LIBBASE)->ScreenNotifyBase = sn_Init(GetPubIBase(LIBBASE));
477 # if 0 /* not finished yet - Piru */
478 /* Add notifyintuition.library base if not there yet - Piru
480 if (!GetPrivIBase(LIBBASE)->NotifyIntuitionBase)
482 GetPrivIBase(LIBBASE)->NotifyIntuitionBase = ni_Init(GetPubIBase(LIBBASE));
484 # endif
485 #endif
487 return TRUE;
490 DECLARESET(CLASSESINIT)
491 ADD2SET(InitRootClass, CLASSESINIT, -20)
492 ADD2INITLIB(IntuitionInit, 0)
493 ADD2OPENLIB(IntuitionOpen, 0)