use consistent hidd naming
[AROS.git] / rom / intuition / intuition_init.c
blob983f8f2750a83baac9a9eded1711275cf6f49b4c
1 /*
2 Copyright © 1995-2013, 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/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_BitMap, &GetPrivIBase(LIBBASE)->HiddBitMapAttrBase},
88 {IID_Hidd_PixFmt, &GetPrivIBase(LIBBASE)->HiddPixFmtAttrBase},
89 {NULL , NULL }
92 DEBUG_INIT(dprintf("LIB_Init: base 0x%p\n", LIBBASE));
94 /* Open our dependencies */
95 if (!(GetPrivIBase(LIBBASE)->UtilityBase = OpenLibrary("utility.library", 0))) {
96 return FALSE;
97 } else if (!(GfxBase = GetPrivIBase(LIBBASE)->GfxBase = (APTR)OpenLibrary("graphics.library", 41))) {
98 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
99 return FALSE;
100 } else if (!(GetPrivIBase(LIBBASE)->LayersBase = (APTR)OpenLibrary("layers.library", 41))) {
101 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
102 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
103 return FALSE;
104 } else if (!(GetPrivIBase(LIBBASE)->KeymapBase = (APTR)OpenLibrary("keymap.library", 41))) {
105 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
106 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
107 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
108 return FALSE;
109 } else if (!(OOPBase = GetPrivIBase(LIBBASE)->OOPBase = (APTR)OpenLibrary("oop.library", 41))) {
110 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->KeymapBase);
111 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->LayersBase);
112 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->GfxBase);
113 CloseLibrary((APTR)GetPrivIBase(LIBBASE)->UtilityBase);
114 return FALSE;
117 LIBBASE->ib_HiddBitMapBase = OOP_GetMethodID(IID_Hidd_BitMap, 0);
118 LIBBASE->ib_HiddGfxBase = OOP_GetMethodID(IID_Hidd_Gfx, 0);
120 if (!OOP_ObtainAttrBases(attrbases))
121 return FALSE;
123 /* FIXME: This libInit is all broken if something should fail, but do we care? */
124 /* FIXME: If something fails we're screwed anyway... */
126 /* We have to open this here, but it doesn't do any allocations,
127 so it shouldn't fail...
130 /* Create semaphore and initialize it */
131 GetPrivIBase(LIBBASE)->IBaseLock = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
133 if (!GetPrivIBase(LIBBASE)->IBaseLock)
134 return FALSE;
136 InitSemaphore(GetPrivIBase(LIBBASE)->IBaseLock);
138 InitSemaphore(&GetPrivIBase(LIBBASE)->WinDecorSem);
139 InitSemaphore(&GetPrivIBase(LIBBASE)->ScrDecorSem);
140 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuDecorSem);
142 /* Initialize global stringgadget edit hook */
143 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Entry = (APTR)AROS_ASMSYMNAME(GlobalEditFunc);
144 GetPrivIBase(LIBBASE)->DefaultEditHook.h_SubEntry = NULL;
145 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Data = LIBBASE;
147 GetPrivIBase(LIBBASE)->GlobalEditHook = &(GetPrivIBase(LIBBASE)->DefaultEditHook);
149 GetPrivIBase(LIBBASE)->DefaultPubScreen = NULL;
150 NEWLIST(&GetPrivIBase(LIBBASE)->PubScreenList);
151 InitSemaphore(&GetPrivIBase(LIBBASE)->PubScrListLock);
153 InitSemaphore(&GetPrivIBase(LIBBASE)->ScreenNotificationListLock);
154 NEWLIST(&GetPrivIBase(LIBBASE)->ScreenNotificationList);
156 NEWLIST(&GetPrivIBase(LIBBASE)->Decorations);
159 InitSemaphore(&GetPrivIBase(LIBBASE)->GadgetLock);
160 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuLock);
161 InitSemaphore(&GetPrivIBase(LIBBASE)->WindowLock);
162 InitSemaphore(&GetPrivIBase(LIBBASE)->IntuiActionLock);
163 InitSemaphore(&GetPrivIBase(LIBBASE)->InputHandlerLock);
165 #ifdef SKINS
166 InitSemaphore(&GetPrivIBase(LIBBASE)->DataTypesSem);
167 GetPrivIBase(LIBBASE)->DataTypesBase = 0;
169 GetPrivIBase(LIBBASE)->transphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
170 GetPrivIBase(LIBBASE)->transphook.h_Entry = (HOOKFUNC)HookEntry;
171 GetPrivIBase(LIBBASE)->transphook.h_SubEntry = (HOOKFUNC)WindowTranspFunc;
173 GetPrivIBase(LIBBASE)->notransphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
174 GetPrivIBase(LIBBASE)->notransphook.h_Entry = (HOOKFUNC)HookEntry;
175 GetPrivIBase(LIBBASE)->notransphook.h_SubEntry = (HOOKFUNC)WindowNoTranspFunc;
176 #endif
178 #ifdef __MORPHOS__
179 memset(GetPrivIBase(LIBBASE)->Pad, 0xee, sizeof(GetPrivIBase(LIBBASE)->Pad));
180 GetPrivIBase(LIBBASE)->SystemRequestTitle = "System Request";
181 GetPrivIBase(LIBBASE)->WorkbenchTitle = "Ambient Screen";
182 #endif
184 * Setup the default pens to the default
185 * colors so that screens have proper color
186 * even before IPrefs is loaded.
189 struct Color32 *p;
190 ULONG i;
192 p = GetPrivIBase(LIBBASE)->Colors;
194 for (i = 0; i < COLORTABLEENTRIES; i++)
196 p[i].red = coltab[i*3];
197 p[i].green = coltab[i*3+1];
198 p[i].blue = coltab[i*3+2];
201 LIBBASE->PointerAlpha = 0x9F9F;
203 #ifdef __MORPHOS__
204 GetPrivIBase(LIBBASE)->mosmenuclass = InitMuiMenuClass(LIBBASE);
205 #endif
207 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
208 /* FIXME: no cleanup routines for MenuHandler task */
209 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
210 return FALSE;
212 /* FIXME: no cleanup routines for ScreennotifyHandler task */
213 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
214 return FALSE;
217 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
218 LoadDefaultPreferences(GetPubIBase(LIBBASE));
219 #ifdef USEGETIPREFS
220 GetPrivIBase(LIBBASE)->IPrefsLoaded = FALSE;
221 #endif
223 #ifdef SKINS
224 if (!GetPrivIBase(LIBBASE)->SmallMenuPool)
226 if (!(GetPrivIBase(LIBBASE)->SmallMenuPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct SmallMenuEntry))*20,(sizeof (struct SmallMenuEntry))*20))) return NULL;
228 #endif
230 if (!(GetPrivIBase(LIBBASE)->IDCMPPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct IntIntuiMessage)) * 100,sizeof (struct IntIntuiMessage)))) return FALSE;
232 #ifdef SKINS
233 strcpy(GetPrivIBase(LIBBASE)->IControlExtensions.ice_ClockFormat,"%X");
234 #endif
236 GetPrivIBase(LIBBASE)->FrameSize = FRAMESIZE_THIN;
239 WORD i;
241 for(i = 0; i < RESOURCELIST_HASHSIZE; i++)
243 NewList((struct List *)&GetPrivIBase(LIBBASE)->ResourceList[i]);
247 GetPrivIBase(LIBBASE)->ScrDecorClass = FindClass(SCRDECORCLASS);
248 GetPrivIBase(LIBBASE)->ScrDecorTags = NULL;
249 GetPrivIBase(LIBBASE)->MenuDecorClass = FindClass(MENUDECORCLASS);
250 GetPrivIBase(LIBBASE)->MenuDecorTags = NULL;
251 GetPrivIBase(LIBBASE)->WinDecorClass = FindClass(WINDECORCLASS);
252 GetPrivIBase(LIBBASE)->WinDecorTags = NULL;
253 LIBBASE->ViewLord_ok = FALSE;
255 DEBUG_INIT(dprintf("LIB_Init: Setting up pointers...\n"));
257 GetPrivIBase(LIBBASE)->DefaultPointer = MakePointerFromPrefs
259 GetPubIBase(LIBBASE), &GetPrivIBase(LIBBASE)->ActivePreferences
261 GetPrivIBase(LIBBASE)->BusyPointer = MakePointerFromPrefs
263 GetPubIBase(LIBBASE), &GetPrivIBase(LIBBASE)->ActivePreferences
268 !GetPrivIBase(LIBBASE)->DefaultPointer
269 || !GetPrivIBase(LIBBASE)->BusyPointer
272 return FALSE;
275 NEWLIST(&GetPrivIBase(LIBBASE)->MonitorList);
276 InitSemaphore(&GetPrivIBase(LIBBASE)->MonitorListSem);
277 SetDisplayDriverCallback(DisplayDriverNotify, LIBBASE);
279 #if defined(__AROS_ARCH_pc__) /* for now */
280 /* Install reset handler to display manual shutdown screen */
281 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Node.ln_Pri = -96;
282 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Code =
283 (VOID_FUNC)ShutdownScreenHandler;
284 GetPrivIBase(LIBBASE)->ShutdownHandler.is_Data =
285 &GetPrivIBase(LIBBASE)->ShutdownHandler;
286 AddResetCallback(&GetPrivIBase(LIBBASE)->ShutdownHandler);
287 #endif
289 DEBUG_INIT(dprintf("LIB_Init: done\n"));
291 return TRUE;
294 static int InitRootClass(LIBBASETYPEPTR LIBBASE)
296 InitSemaphore(&GetPrivIBase(LIBBASE)->ClassListLock);
297 NEWLIST(&GetPrivIBase(LIBBASE)->ClassList);
299 /* Setup root class */
301 GetPrivIBase(LIBBASE)->RootClass.cl_Dispatcher.h_Entry = (APTR)AROS_ASMSYMNAME(rootDispatcher);
302 GetPrivIBase(LIBBASE)->RootClass.cl_ID = (ClassID)ROOTCLASS;
303 GetPrivIBase(LIBBASE)->RootClass.cl_UserData = (IPTR)LIBBASE;
304 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
305 AddClass(&(GetPrivIBase(LIBBASE)->RootClass));
307 return TRUE;
310 /****************************************************************************************/
312 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE)
314 struct GfxBase *GfxBase = GetPrivIBase(LIBBASE)->GfxBase;
315 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE));
317 /* Open the input device */
319 if (!GetPrivIBase(LIBBASE)->InputMP)
321 if (!(GetPrivIBase(LIBBASE)->InputMP = CreateMsgPort()))
323 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
324 return FALSE;
328 if (!GetPrivIBase(LIBBASE)->InputIO)
330 if (!(GetPrivIBase(LIBBASE)->InputIO = (struct IOStdReq *)
331 CreateIORequest(GetPrivIBase(LIBBASE)->InputMP, sizeof (struct IOStdReq))) )
333 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
334 return FALSE;
338 if (!GetPrivIBase(LIBBASE)->InputDeviceOpen)
340 if (!OpenDevice("input.device", -1, (struct IORequest *)GetPrivIBase(LIBBASE)->InputIO, 0))
342 GetPrivIBase(LIBBASE)->InputDeviceOpen = TRUE;
343 GetPrivIBase(LIBBASE)->InputBase = (struct Library *)GetPrivIBase(LIBBASE)->InputIO->io_Device;
345 else
347 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
348 return FALSE;
352 if (!GetPrivIBase(LIBBASE)->InputHandler)
354 D(bug("Initializing inputhandler\n"));
355 if ( !(GetPrivIBase(LIBBASE)->InputHandler = InitIIH(GetPubIBase(LIBBASE))) )
357 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
358 return FALSE;
361 D(bug("Adding inputhandler\n"));
362 GetPrivIBase(LIBBASE)->InputIO->io_Data = (APTR)GetPrivIBase(LIBBASE)->InputHandler;
363 GetPrivIBase(LIBBASE)->InputIO->io_Command = IND_ADDHANDLER;
365 D(bug("Calling DoIO()\n"));
366 DoIO((struct IORequest *)GetPrivIBase(LIBBASE)->InputIO);
367 D(bug("DoIO() called\n"));
370 if (!LIBBASE->ViewLord_ok)
372 #ifdef __MORPHOS__
373 struct ViewExtra *ve;
375 if (!(ve = GfxNew(VIEW_EXTRA_TYPE)))
377 GetPrivIBase(LIBBASE)->GfxBase = NULL;
378 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
379 return FALSE;
381 #endif
382 D(bug("[intuition] Calling InitView()\n"));
383 InitView(&LIBBASE->Base.ViewLord);
384 InitSemaphore(&LIBBASE->ViewLordLock);
385 #ifdef __MORPHOS__
386 GfxAssociate(&LIBBASE->Base.ViewLord, ve);
388 GetPrivIBase(LIBBASE)->ViewLordExtra = ve;
389 GetPrivIBase(LIBBASE)->SpriteNum = -1;
390 #endif
391 LIBBASE->ViewLord_ok = TRUE;
394 if (!GetPrivIBase(LIBBASE)->ScreenFont)
395 GetPrivIBase(LIBBASE)->ScreenFont = GetPrivIBase(LIBBASE)->GfxBase->DefaultFont;
397 #if 0 /* CHECKME: stegerg: backport, disabled */
398 if (!(GetPrivIBase(LIBBASE)->TopazFont))
400 struct TextAttr textattr = {"topaz.font",8,0,FPF_ROMFONT};
401 GetPrivIBase(LIBBASE)->TopazFont = OpenFont(&textattr);
403 #endif
405 if (!GetPrivIBase(LIBBASE)->TimerBase)
407 if (!(GetPrivIBase(LIBBASE)->TimerMP = CreateMsgPort()))
409 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
410 return FALSE; /* don't close anything */
413 if (!(GetPrivIBase(LIBBASE)->TimerIO = (struct timerequest *)CreateIORequest(GetPrivIBase(LIBBASE)->TimerMP, sizeof(struct timerequest))))
415 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
416 return FALSE; /* don't close anything */
419 if (OpenDevice(TIMERNAME,UNIT_VBLANK, (struct IORequest *)GetPrivIBase(LIBBASE)->TimerIO,0))
421 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
422 return FALSE; /* don't close anything */
425 GetPrivIBase(LIBBASE)->TimerBase = (struct Library *)GetPrivIBase(LIBBASE)->TimerIO->tr_node.io_Device;
427 SetPrefs(&GetPrivIBase(LIBBASE)->DefaultPreferences, sizeof(struct Preferences), FALSE);
430 #if 0
431 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
433 //check if dos is opened!!!
434 ((struct DosLibrary *)DOSBase)->dl_IntuitionBase =
435 (struct Library *)LIBBASE;
437 /* Install intuition's version of DisplayError() that puts up
438 a requester with Retry/Cancel options */
439 GetPrivIBase(LIBBASE)->OldDisplayErrorFunc =
440 SetFunction(DOSBase, -81*LIB_VECTSIZE,
441 AROS_SLIB_ENTRY(DisplayError, Intuition, 81));
443 #else
444 # ifdef SKINS
445 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
447 InitSkinManager(GetPubIBase(LIBBASE));
449 # endif
450 #endif
452 /* FIXME: no cleanup routines for MenuHandler task */
453 if (!GetPrivIBase(LIBBASE)->MenuHandlerPort)
455 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
456 return FALSE;
459 /* FIXME: no cleanup routines for ScreennotifyHandler task */
460 if (!GetPrivIBase(LIBBASE)->ScreenNotifyReplyPort)
462 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
463 return FALSE;
466 #ifdef INTUITION_NOTIFY_SUPPORT
467 /* Add screennotify.library base if not there yet - Piru
469 if (!GetPrivIBase(LIBBASE)->ScreenNotifyBase)
471 GetPrivIBase(LIBBASE)->ScreenNotifyBase = sn_Init(GetPubIBase(LIBBASE));
474 # if 0 /* not finished yet - Piru */
475 /* Add notifyintuition.library base if not there yet - Piru
477 if (!GetPrivIBase(LIBBASE)->NotifyIntuitionBase)
479 GetPrivIBase(LIBBASE)->NotifyIntuitionBase = ni_Init(GetPubIBase(LIBBASE));
481 # endif
482 #endif
484 return TRUE;
487 DECLARESET(CLASSESINIT);
488 ADD2SET(InitRootClass, CLASSESINIT, -20);
489 ADD2INITLIB(IntuitionInit, 0);
490 ADD2OPENLIB(IntuitionOpen, 0);