fix properties
[AROS.git] / rom / intuition / intuition_init.c
blobae39b7b61d2e16b38ad7a600886fe3f7f6292b9e
1 /*
2 Copyright 1995-2010, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 /****************************************************************************************/
9 #define INIT AROS_SLIB_ENTRY(init,Intuition)
11 #include <string.h>
12 #include <exec/lists.h>
13 #include <exec/resident.h>
14 #include <exec/memory.h>
15 #include <exec/execbase.h>
16 #include <exec/alerts.h>
17 #include <oop/oop.h>
18 #include <proto/graphics.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/oop.h>
22 #include <proto/alib.h>
23 //#include <proto/arossupport.h>
24 #include <devices/input.h>
25 #ifndef INTUITION_CLASSES_H
26 # include <intuition/classes.h>
27 #endif
28 #include <intuition/pointerclass.h>
29 #ifndef UTILITY_HOOKS_H
30 # include <utility/hooks.h>
31 #endif
32 #include <utility/utility.h>
33 #include <aros/symbolsets.h>
34 #include LC_LIBDEFS_FILE
35 #include "intuition_intern.h"
36 #include "strgadgets.h" /* To get GlobalEditFunc prototype */
37 #include "inputhandler.h"
38 #include "menutask.h"
39 #include "screennotifytask.h"
41 #ifdef SKINS
42 #include "transplayers.h"
43 #include "smallmenu.h"
44 #endif
46 #define DEBUG 0
47 #include <aros/debug.h>
49 #ifdef INTUITION_NOTIFY_SUPPORT
50 /* screennotify/notifyintuition init routines from notify.c */
51 struct Library *sn_Init(struct IntuitionBase *IntuitionBase);
52 struct Library *ni_Init(struct IntuitionBase *IntuitionBase);
53 #endif
55 /* There has to be a better way... */
57 AROS_UFP3(ULONG, rootDispatcher,
58 AROS_UFPA(Class *, cl, A0),
59 AROS_UFPA(Object *, obj, A2),
60 AROS_UFPA(Msg, msg, A1)
63 /****************************************************************************************/
65 /* Default colors for the new screen, the same as in AmigaOS 3.1 */
67 const ULONG coltab[] =
69 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
70 0x00000000, 0x00000000, 0x00000000, /* Black */
71 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
72 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
74 0xEEEEEEEE, 0x44444444, 0x44444444, /* Red */
75 0x55555555, 0xDDDDDDDD, 0x55555555, /* Green */
76 0x00000000, 0x44444444, 0xDDDDDDDD, /* Dark Blue */
77 0xEEEEEEEE, 0x99999999, 0x00000000, /* Yellow */
79 0xbbbbbbbb, 0x00000000, 0x00000000, /* Default colors for mouse pointer */
80 0xdddddddd, 0x00000000, 0x00000000,
81 0xeeeeeeee, 0x00000000, 0x00000000
84 static int IntuitionInit(LIBBASETYPEPTR LIBBASE)
86 struct OOP_ABDescr attrbases[] = {
87 {IID_Hidd , &GetPrivIBase(LIBBASE)->HiddAttrBase },
88 {IID_Hidd_Gfx , &GetPrivIBase(LIBBASE)->HiddGfxAttrBase },
89 {IID_Hidd_PixFmt, &GetPrivIBase(LIBBASE)->HiddPixFmtAttrBase},
90 {NULL , NULL }
93 DEBUG_INIT(dprintf("LIB_Init: base 0x%lx\n", (ULONG) LIBBASE));
95 /* Open our dependencies */
96 if (!(UtilityBase = (APTR)OpenLibrary("utility.library", 0))) {
97 return FALSE;
98 } else if (!(GfxBase = (APTR)OpenLibrary("graphics.library", 41))) {
99 CloseLibrary((APTR)UtilityBase);
100 return FALSE;
101 } else if (!(LayersBase = (APTR)OpenLibrary("layers.library", 41))) {
102 CloseLibrary((APTR)GfxBase);
103 CloseLibrary((APTR)UtilityBase);
104 return FALSE;
105 } else if (!(KeymapBase = (APTR)OpenLibrary("keymap.library", 41))) {
106 CloseLibrary((APTR)LayersBase);
107 CloseLibrary((APTR)GfxBase);
108 CloseLibrary((APTR)UtilityBase);
109 return FALSE;
110 } else if (!(OOPBase = (APTR)OpenLibrary("oop.library", 41))) {
111 CloseLibrary((APTR)KeymapBase);
112 CloseLibrary((APTR)LayersBase);
113 CloseLibrary((APTR)GfxBase);
114 CloseLibrary((APTR)UtilityBase);
115 return FALSE;
118 if (!OOP_ObtainAttrBases(attrbases))
119 return FALSE;
121 /* FIXME: This libInit is all broken if something should fail, but do we care? */
122 /* FIXME: If something fails we're screwed anyway... */
124 /* We have to open this here, but it doesn't do any allocations,
125 so it shouldn't fail...
128 /* Create semaphore and initialize it */
129 GetPrivIBase(LIBBASE)->IBaseLock = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
131 if (!GetPrivIBase(LIBBASE)->IBaseLock)
132 return FALSE;
134 InitSemaphore(GetPrivIBase(LIBBASE)->IBaseLock);
136 InitSemaphore(&GetPrivIBase(LIBBASE)->WinDecorSem);
137 InitSemaphore(&GetPrivIBase(LIBBASE)->ScrDecorSem);
138 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuDecorSem);
140 /* Initialize global stringgadget edit hook */
141 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Entry = (APTR)AROS_ASMSYMNAME(GlobalEditFunc);
142 GetPrivIBase(LIBBASE)->DefaultEditHook.h_SubEntry = NULL;
143 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Data = LIBBASE;
145 GetPrivIBase(LIBBASE)->GlobalEditHook = &(GetPrivIBase(LIBBASE)->DefaultEditHook);
147 GetPrivIBase(LIBBASE)->DefaultPubScreen = NULL;
148 NEWLIST(&GetPrivIBase(LIBBASE)->PubScreenList);
149 InitSemaphore(&GetPrivIBase(LIBBASE)->PubScrListLock);
151 InitSemaphore(&GetPrivIBase(LIBBASE)->ScreenNotificationListLock);
152 NEWLIST(&GetPrivIBase(LIBBASE)->ScreenNotificationList);
154 NEWLIST(&GetPrivIBase(LIBBASE)->Decorations);
157 InitSemaphore(&GetPrivIBase(LIBBASE)->GadgetLock);
158 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuLock);
159 InitSemaphore(&GetPrivIBase(LIBBASE)->WindowLock);
160 InitSemaphore(&GetPrivIBase(LIBBASE)->IntuiActionLock);
161 InitSemaphore(&GetPrivIBase(LIBBASE)->InputHandlerLock);
163 #ifdef SKINS
164 InitSemaphore(&GetPrivIBase(LIBBASE)->DataTypesSem);
165 GetPrivIBase(LIBBASE)->DataTypesBase = 0;
167 GetPrivIBase(LIBBASE)->transphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
168 GetPrivIBase(LIBBASE)->transphook.h_Entry = (HOOKFUNC)HookEntry;
169 GetPrivIBase(LIBBASE)->transphook.h_SubEntry = (HOOKFUNC)WindowTranspFunc;
171 GetPrivIBase(LIBBASE)->notransphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
172 GetPrivIBase(LIBBASE)->notransphook.h_Entry = (HOOKFUNC)HookEntry;
173 GetPrivIBase(LIBBASE)->notransphook.h_SubEntry = (HOOKFUNC)WindowNoTranspFunc;
174 #endif
176 #ifdef __MORPHOS__
177 memset(GetPrivIBase(LIBBASE)->Pad, 0xee, sizeof(GetPrivIBase(LIBBASE)->Pad));
178 GetPrivIBase(LIBBASE)->SystemRequestTitle = "System Request";
179 GetPrivIBase(LIBBASE)->WorkbenchTitle = "Ambient Screen";
180 #endif
182 * Setup the default pens to the default
183 * colors so that screens have proper color
184 * even before IPrefs is loaded.
187 struct Color32 *p;
188 ULONG i;
190 p = GetPrivIBase(LIBBASE)->Colors;
192 for (i = 0; i < COLORTABLEENTRIES; i++)
194 p[i].red = coltab[i*3];
195 p[i].green = coltab[i*3+1];
196 p[i].blue = coltab[i*3+2];
199 LIBBASE->PointerAlpha = 0x9F9F;
201 #ifdef __MORPHOS__
202 GetPrivIBase(LIBBASE)->mosmenuclass = InitMuiMenuClass(LIBBASE);
203 #endif
205 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
206 /* FIXME: no cleanup routines for MenuHandler task */
207 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
208 return FALSE;
210 /* FIXME: no cleanup routines for ScreennotifyHandler task */
211 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
212 return FALSE;
215 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
216 LoadDefaultPreferences(GetPubIBase(LIBBASE));
217 #ifdef USEGETIPREFS
218 GetPrivIBase(LIBBASE)->IPrefsLoaded = FALSE;
219 #endif
221 #ifdef SKINS
222 if (!GetPrivIBase(LIBBASE)->SmallMenuPool)
224 if (!(GetPrivIBase(LIBBASE)->SmallMenuPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct SmallMenuEntry))*20,(sizeof (struct SmallMenuEntry))*20))) return NULL;
226 #endif
228 if (!(GetPrivIBase(LIBBASE)->IDCMPPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct IntIntuiMessage)) * 100,sizeof (struct IntIntuiMessage)))) return FALSE;
230 #ifdef SKINS
231 strcpy(GetPrivIBase(LIBBASE)->IControlExtensions.ice_ClockFormat,"%X");
232 #endif
234 GetPrivIBase(LIBBASE)->FrameSize = FRAMESIZE_THIN;
237 WORD i;
239 for(i = 0; i < RESOURCELIST_HASHSIZE; i++)
241 NewList((struct List *)&GetPrivIBase(LIBBASE)->ResourceList[i]);
245 if (!(GetPrivIBase(LIBBASE)->WinDecorObj = NewObjectA(NULL, WINDECORCLASS, NULL))) return FALSE;
246 if (!(GetPrivIBase(LIBBASE)->ScrDecorObj = NewObjectA(NULL, SCRDECORCLASS, NULL))) return FALSE;
247 if (!(GetPrivIBase(LIBBASE)->MenuDecorObj = NewObjectA(NULL, MENUDECORCLASS, NULL))) return FALSE;
249 GetPrivIBase(LIBBASE)->DefWinDecorObj = GetPrivIBase(LIBBASE)->WinDecorObj;
250 GetPrivIBase(LIBBASE)->DefScrDecorObj = GetPrivIBase(LIBBASE)->ScrDecorObj;
251 GetPrivIBase(LIBBASE)->DefMenuDecorObj = GetPrivIBase(LIBBASE)->MenuDecorObj;
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 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE));
305 /* Open the input device */
307 if (!GetPrivIBase(LIBBASE)->InputMP)
309 if (!(GetPrivIBase(LIBBASE)->InputMP = CreateMsgPort()))
311 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
312 return FALSE;
316 if (!GetPrivIBase(LIBBASE)->InputIO)
318 if (!(GetPrivIBase(LIBBASE)->InputIO = (struct IOStdReq *)
319 CreateIORequest(GetPrivIBase(LIBBASE)->InputMP, sizeof (struct IOStdReq))) )
321 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
322 return FALSE;
326 if (!GetPrivIBase(LIBBASE)->InputDeviceOpen)
328 if (!OpenDevice("input.device", -1, (struct IORequest *)GetPrivIBase(LIBBASE)->InputIO, 0))
330 GetPrivIBase(LIBBASE)->InputDeviceOpen = TRUE;
331 InputBase = (struct Library *)GetPrivIBase(LIBBASE)->InputIO->io_Device;
333 else
335 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
336 return FALSE;
340 if (!GetPrivIBase(LIBBASE)->InputHandler)
342 D(bug("Initializing inputhandler\n"));
343 if ( !(GetPrivIBase(LIBBASE)->InputHandler = InitIIH(GetPubIBase(LIBBASE))) )
345 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
346 return FALSE;
349 D(bug("Adding inputhandler\n"));
350 GetPrivIBase(LIBBASE)->InputIO->io_Data = (APTR)GetPrivIBase(LIBBASE)->InputHandler;
351 GetPrivIBase(LIBBASE)->InputIO->io_Command = IND_ADDHANDLER;
353 D(bug("Calling DoIO()\n"));
354 DoIO((struct IORequest *)GetPrivIBase(LIBBASE)->InputIO);
355 D(bug("DoIO() called\n"));
358 if (!LIBBASE->ViewLord_ok)
360 #ifdef __MORPHOS__
361 struct ViewExtra *ve;
363 if (!(ve = GfxNew(VIEW_EXTRA_TYPE)))
365 GfxBase = NULL;
366 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
367 return FALSE;
369 #endif
370 D(bug("[intuition] Calling InitView()\n"));
371 InitView(&LIBBASE->IBase.ViewLord);
372 #ifdef __MORPHOS__
373 GfxAssociate(&LIBBASE->IBase.ViewLord, ve);
375 GetPrivIBase(LIBBASE)->ViewLordExtra = ve;
376 GetPrivIBase(LIBBASE)->SpriteNum = -1;
377 #endif
378 LIBBASE->ViewLord_ok = TRUE;
381 if (!GetPrivIBase(LIBBASE)->ScreenFont)
382 GetPrivIBase(LIBBASE)->ScreenFont = GfxBase->DefaultFont;
384 #if 0 /* CHECKME: stegerg: backport, disabled */
385 if (!(GetPrivIBase(LIBBASE)->TopazFont))
387 struct TextAttr textattr = {"topaz.font",8,0,FPF_ROMFONT};
388 GetPrivIBase(LIBBASE)->TopazFont = OpenFont(&textattr);
390 #endif
392 if (!TimerBase)
394 if (!(TimerMP = CreateMsgPort()))
396 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
397 return FALSE; /* don't close anything */
400 if (!(TimerIO = (struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))))
402 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
403 return FALSE; /* don't close anything */
406 if (OpenDevice(TIMERNAME,UNIT_VBLANK, (struct IORequest *)TimerIO,0))
408 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
409 return FALSE; /* don't close anything */
412 TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
414 SetPrefs(GetPrivIBase(LIBBASE)->DefaultPreferences, sizeof(struct Preferences), FALSE);
417 #if 0
418 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
420 //check if dos is opened!!!
421 ((struct DosLibrary *)DOSBase)->dl_IntuitionBase =
422 (struct Library *)LIBBASE;
424 /* Install intuition's version of DisplayError() that puts up
425 a requester with Retry/Cancel options */
426 GetPrivIBase(LIBBASE)->OldDisplayErrorFunc =
427 SetFunction(DOSBase, -81*LIB_VECTSIZE,
428 AROS_SLIB_ENTRY(DisplayError, Intuition));
430 #else
431 # ifdef SKINS
432 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
434 InitSkinManager(GetPubIBase(LIBBASE));
436 # endif
437 #endif
439 /* FIXME: no cleanup routines for MenuHandler task */
440 if (!GetPrivIBase(LIBBASE)->MenuHandlerPort)
442 if (!InitDefaultMenuHandler(GetPubIBase(LIBBASE)))
443 return FALSE;
446 /* FIXME: no cleanup routines for ScreennotifyHandler task */
447 if (!GetPrivIBase(LIBBASE)->ScreenNotifyReplyPort)
449 if (!InitDefaultScreennotifyHandler(GetPubIBase(LIBBASE)))
450 return FALSE;
453 #ifdef INTUITION_NOTIFY_SUPPORT
454 /* Add screennotify.library base if not there yet - Piru
456 if (!GetPrivIBase(LIBBASE)->ScreenNotifyBase)
458 GetPrivIBase(LIBBASE)->ScreenNotifyBase = sn_Init(GetPubIBase(LIBBASE));
461 # if 0 /* not finished yet - Piru */
462 /* Add notifyintuition.library base if not there yet - Piru
464 if (!GetPrivIBase(LIBBASE)->NotifyIntuitionBase)
466 GetPrivIBase(LIBBASE)->NotifyIntuitionBase = ni_Init(GetPubIBase(LIBBASE));
468 # endif
469 #endif
471 return TRUE;
474 DECLARESET(CLASSESINIT);
475 ADD2SET(InitRootClass, classesinit, -20);
476 ADD2INITLIB(IntuitionInit, 0);
477 ADD2OPENLIB(IntuitionOpen, 0);