New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / intuition_init.c
blobf225e69e67af45c094310d76c696bf4a0f725fc1
1 /*
2 Copyright 1995-2006, 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 <proto/graphics.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/alib.h>
21 //#include <proto/arossupport.h>
22 #include <devices/input.h>
23 #ifndef INTUITION_CLASSES_H
24 # include <intuition/classes.h>
25 #endif
26 #include <intuition/pointerclass.h>
27 #ifndef UTILITY_HOOKS_H
28 # include <utility/hooks.h>
29 #endif
30 #include <utility/utility.h>
31 #include <aros/symbolsets.h>
32 #include LC_LIBDEFS_FILE
33 #include "intuition_intern.h"
34 #include "strgadgets.h" /* To get GlobalEditFunc prototype */
35 #include "inputhandler.h"
36 #include "menutask.h"
37 #include "screennotifytask.h"
39 #ifdef SKINS
40 #include "transplayers.h"
41 #include "smallmenu.h"
42 #endif
44 #define DEBUG 0
45 #include <aros/debug.h>
47 #ifdef INTUITION_NOTIFY_SUPPORT
48 /* screennotify/notifyintuition init routines from notify.c */
49 struct Library *sn_Init(struct IntuitionBase *IntuitionBase);
50 struct Library *ni_Init(struct IntuitionBase *IntuitionBase);
51 #endif
53 /* There has to be a better way... */
55 AROS_UFP3(ULONG, rootDispatcher,
56 AROS_UFPA(Class *, cl, A0),
57 AROS_UFPA(Object *, obj, A2),
58 AROS_UFPA(Msg, msg, A1)
61 /****************************************************************************************/
63 extern const ULONG coltab[];
65 static int IntuitionInit(LIBBASETYPEPTR LIBBASE)
67 DEBUG_INIT(dprintf("LIB_Init: base 0x%lx\n", (ULONG) LIBBASE));
69 #warning "FIXME: This libInit is all broken if something should fail, but do we care?"
70 #warning "FIXME: If something fails we're screwed anyway..."
72 /* We have to open this here, but it doesn't do any allocations,
73 so it shouldn't fail...
76 /* Create semaphore and initialize it */
77 GetPrivIBase(LIBBASE)->IBaseLock = AllocMem (sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR);
79 if (!GetPrivIBase(LIBBASE)->IBaseLock)
80 return FALSE;
82 InitSemaphore(GetPrivIBase(LIBBASE)->IBaseLock);
84 /* Initialize global stringgadget edit hook */
85 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Entry = (APTR)AROS_ASMSYMNAME(GlobalEditFunc);
86 GetPrivIBase(LIBBASE)->DefaultEditHook.h_SubEntry = NULL;
87 GetPrivIBase(LIBBASE)->DefaultEditHook.h_Data = LIBBASE;
89 GetPrivIBase(LIBBASE)->GlobalEditHook = &(GetPrivIBase(LIBBASE)->DefaultEditHook);
91 GetPrivIBase(LIBBASE)->DefaultPubScreen = NULL;
92 NEWLIST(&GetPrivIBase(LIBBASE)->PubScreenList);
93 InitSemaphore(&GetPrivIBase(LIBBASE)->PubScrListLock);
95 InitSemaphore(&GetPrivIBase(LIBBASE)->ScreenNotificationListLock);
96 NEWLIST(&GetPrivIBase(LIBBASE)->ScreenNotificationList);
99 InitSemaphore(&GetPrivIBase(LIBBASE)->GadgetLock);
100 InitSemaphore(&GetPrivIBase(LIBBASE)->MenuLock);
101 InitSemaphore(&GetPrivIBase(LIBBASE)->WindowLock);
102 InitSemaphore(&GetPrivIBase(LIBBASE)->IntuiActionLock);
103 InitSemaphore(&GetPrivIBase(LIBBASE)->InputHandlerLock);
105 #ifdef SKINS
106 InitSemaphore(&GetPrivIBase(LIBBASE)->DataTypesSem);
107 GetPrivIBase(LIBBASE)->DataTypesBase = 0;
109 GetPrivIBase(LIBBASE)->transphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
110 GetPrivIBase(LIBBASE)->transphook.h_Entry = (HOOKFUNC)HookEntry;
111 GetPrivIBase(LIBBASE)->transphook.h_SubEntry = (HOOKFUNC)WindowTranspFunc;
113 GetPrivIBase(LIBBASE)->notransphook.h_Data = (APTR)GetPrivIBase(LIBBASE);
114 GetPrivIBase(LIBBASE)->notransphook.h_Entry = (HOOKFUNC)HookEntry;
115 GetPrivIBase(LIBBASE)->notransphook.h_SubEntry = (HOOKFUNC)WindowNoTranspFunc;
116 #endif
118 #ifdef __MORPHOS__
119 memset(GetPrivIBase(LIBBASE)->Pad, 0xee, sizeof(GetPrivIBase(LIBBASE)->Pad));
120 GetPrivIBase(LIBBASE)->SystemRequestTitle = "System Request";
121 GetPrivIBase(LIBBASE)->WorkbenchTitle = "Ambient Screen";
124 * Setup the default pens to the default
125 * colors so that screens have proper color
126 * even before IPrefs is loaded.
129 struct Color32 *p;
130 ULONG i;
132 p = GetPrivIBase(LIBBASE)->Colors;
134 for (i = 0; i < 16; i++)
136 p[i].red = coltab[i + 1];
137 p[i].green = coltab[i + 2];
138 p[i].blue = coltab[i + 3];
142 #endif
144 #ifdef __MORPHOS__
145 GetPrivIBase(LIBBASE)->mosmenuclass = InitMuiMenuClass(LIBBASE);
146 #endif
148 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
149 /* FIXME: no cleanup routines for MenuHandler task */
150 if (!InitDefaultMenuHandler(IntuitionBase))
151 return FALSE;
153 /* FIXME: no cleanup routines for ScreennotifyHandler task */
154 if (!InitDefaultScreennotifyHandler(IntuitionBase))
155 return FALSE;
158 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
159 LoadDefaultPreferences(LIBBASE);
160 #ifdef USEGETIPREFS
161 GetPrivIBase(LIBBASE)->IPrefsLoaded = FALSE;
162 #endif
164 #ifdef SKINS
165 if (!GetPrivIBase(LIBBASE)->SmallMenuPool)
167 if (!(GetPrivIBase(LIBBASE)->SmallMenuPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct SmallMenuEntry))*20,(sizeof (struct SmallMenuEntry))*20))) return NULL;
169 #endif
171 if (!(GetPrivIBase(LIBBASE)->IDCMPPool = CreatePool(MEMF_SEM_PROTECTED,(sizeof (struct IntIntuiMessage)) * 100,sizeof (struct IntIntuiMessage)))) return FALSE;
173 #ifdef SKINS
174 strcpy(GetPrivIBase(IntuitionBase)->IControlExtensions.ice_ClockFormat,"%X");
175 #endif
177 GetPrivIBase(LIBBASE)->FrameSize = FRAMESIZE_THIN;
180 WORD i;
182 for(i = 0; i < RESOURCELIST_HASHSIZE; i++)
184 NewList((struct List *)&GetPrivIBase(LIBBASE)->ResourceList[i]);
188 DEBUG_INIT(dprintf("LIB_Init: done\n"));
190 return TRUE;
193 static int InitRootClass(LIBBASETYPEPTR LIBBASE)
195 InitSemaphore(&GetPrivIBase(LIBBASE)->ClassListLock);
196 NEWLIST(&GetPrivIBase(LIBBASE)->ClassList);
198 /* Setup root class */
200 GetPrivIBase(LIBBASE)->RootClass.cl_Dispatcher.h_Entry = (APTR)AROS_ASMSYMNAME(rootDispatcher);
201 GetPrivIBase(LIBBASE)->RootClass.cl_ID = (ClassID)ROOTCLASS;
202 GetPrivIBase(LIBBASE)->RootClass.cl_UserData = (IPTR)LIBBASE;
203 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
204 AddClass(&(GetPrivIBase(LIBBASE)->RootClass));
206 return TRUE;
209 /****************************************************************************************/
211 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE)
213 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE));
215 /* Open the input device */
217 if (!GetPrivIBase(LIBBASE)->InputMP)
219 if (!(GetPrivIBase(LIBBASE)->InputMP = CreateMsgPort()))
221 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
222 return FALSE;
226 if (!GetPrivIBase(LIBBASE)->InputIO)
228 if (!(GetPrivIBase(LIBBASE)->InputIO = (struct IOStdReq *)
229 CreateIORequest(GetPrivIBase(LIBBASE)->InputMP, sizeof (struct IOStdReq))) )
231 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
232 return FALSE;
236 if (!GetPrivIBase(LIBBASE)->InputDeviceOpen)
238 if (!OpenDevice("input.device", -1, (struct IORequest *)GetPrivIBase(LIBBASE)->InputIO, NULL))
240 GetPrivIBase(LIBBASE)->InputDeviceOpen = TRUE;
241 InputBase = (struct Library *)GetPrivIBase(LIBBASE)->InputIO->io_Device;
243 else
245 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
246 return FALSE;
250 if (!GetPrivIBase(LIBBASE)->InputHandler)
252 D(bug("Initializing inputhandler\n"));
253 if ( !(GetPrivIBase(LIBBASE)->InputHandler = InitIIH(LIBBASE)) )
255 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
256 return FALSE;
259 D(bug("Adding inputhandler\n"));
260 GetPrivIBase(LIBBASE)->InputIO->io_Data = (APTR)GetPrivIBase(LIBBASE)->InputHandler;
261 GetPrivIBase(LIBBASE)->InputIO->io_Command = IND_ADDHANDLER;
263 D(bug("Calling DoIO()\n"));
264 DoIO((struct IORequest *)GetPrivIBase(LIBBASE)->InputIO);
265 D(bug("DoIO() called\n"));
268 #ifdef __MORPHOS__
269 if (!GfxBase)
271 struct ViewExtra *ve;
273 if (!(ve = GfxNew(VIEW_EXTRA_TYPE)))
275 GfxBase = NULL;
276 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
277 return FALSE;
280 InitView(&IntuitionBase->ViewLord);
282 GfxAssociate(&IntuitionBase->ViewLord, ve);
284 GetPrivIBase(LIBBASE)->ViewLordExtra = ve;
286 GetPrivIBase(LIBBASE)->SpriteNum = -1;
289 #endif
291 if (!GetPrivIBase(LIBBASE)->ScreenFont)
292 GetPrivIBase(LIBBASE)->ScreenFont = GfxBase->DefaultFont;
294 #if 0 /* CHECKME: stegerg: backport, disabled */
295 if (!(GetPrivIBase(LIBBASE)->TopazFont))
297 struct TextAttr textattr = {"topaz.font",8,0,FPF_ROMFONT};
298 GetPrivIBase(LIBBASE)->TopazFont = OpenFont(&textattr);
300 #endif
302 if (!TimerBase)
304 if (!(TimerMP = CreateMsgPort()))
306 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
307 return FALSE; /* don't close anything */
310 if (!(TimerIO = (struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))))
312 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
313 return FALSE; /* don't close anything */
316 if (OpenDevice(TIMERNAME,UNIT_VBLANK, (struct IORequest *)TimerIO,0))
318 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
319 return FALSE; /* don't close anything */
322 TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
324 SetPrefs(GetPrivIBase(LIBBASE)->DefaultPreferences, sizeof(struct Preferences), FALSE);
327 #if 0
328 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
330 //check if dos is opened!!!
331 ((struct DosLibrary *)DOSBase)->dl_IntuitionBase =
332 (struct Library *)LIBBASE;
334 /* Install intuition's version of DisplayError() that puts up
335 a requester with Retry/Cancel options */
336 GetPrivIBase(LIBBASE)->OldDisplayErrorFunc =
337 SetFunction(DOSBase, -81*LIB_VECTSIZE,
338 AROS_SLIB_ENTRY(DisplayError, Intuition));
340 #else
341 # ifdef SKINS
342 if (((struct Library *)LIBBASE)->lib_OpenCnt == 0)
344 InitSkinManager(IntuitionBase);
346 # endif
347 #endif
349 /* FIXME: no cleanup routines for MenuHandler task */
350 if (!GetPrivIBase(LIBBASE)->MenuHandlerPort)
352 if (!InitDefaultMenuHandler(LIBBASE))
353 return FALSE;
356 /* FIXME: no cleanup routines for ScreennotifyHandler task */
357 if (!GetPrivIBase(LIBBASE)->ScreenNotifyReplyPort)
359 if (!InitDefaultScreennotifyHandler(LIBBASE))
360 return FALSE;
363 #ifdef INTUITION_NOTIFY_SUPPORT
364 /* Add screennotify.library base if not there yet - Piru
366 if (!GetPrivIBase(LIBBASE)->ScreenNotifyBase)
368 GetPrivIBase(LIBBASE)->ScreenNotifyBase = sn_Init(IntuitionBase);
371 # if 0 /* not finished yet - Piru */
372 /* Add notifyintuition.library base if not there yet - Piru
374 if (!GetPrivIBase(LIBBASE)->NotifyIntuitionBase)
376 GetPrivIBase(LIBBASE)->NotifyIntuitionBase = ni_Init(IntuitionBase);
378 # endif
379 #endif
381 return TRUE;
384 DECLARESET(CLASSESINIT);
385 ADD2SET(InitRootClass, classesinit, -20);
386 ADD2INITLIB(IntuitionInit, 0);
387 ADD2OPENLIB(IntuitionOpen, 0);