2 Copyright 1995-2006, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 /****************************************************************************************/
9 #define INIT AROS_SLIB_ENTRY(init,Intuition)
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>
26 #include <intuition/pointerclass.h>
27 #ifndef UTILITY_HOOKS_H
28 # include <utility/hooks.h>
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"
37 #include "screennotifytask.h"
40 #include "transplayers.h"
41 #include "smallmenu.h"
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
);
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 /* Default colors for the new screen, the same as in AmigaOS 3.1 */
65 const ULONG coltab
[] =
67 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
68 0x00000000, 0x00000000, 0x00000000, /* Black */
69 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
70 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
72 0xEEEEEEEE, 0x44444444, 0x44444444, /* Red */
73 0x55555555, 0xDDDDDDDD, 0x55555555, /* Green */
74 0x00000000, 0x44444444, 0xDDDDDDDD, /* Dark Blue */
75 0xEEEEEEEE, 0x99999999, 0x00000000, /* Yellow */
78 static int IntuitionInit(LIBBASETYPEPTR LIBBASE
)
80 DEBUG_INIT(dprintf("LIB_Init: base 0x%lx\n", (ULONG
) LIBBASE
));
82 #warning "FIXME: This libInit is all broken if something should fail, but do we care?"
83 #warning "FIXME: If something fails we're screwed anyway..."
85 /* We have to open this here, but it doesn't do any allocations,
86 so it shouldn't fail...
89 /* Create semaphore and initialize it */
90 GetPrivIBase(LIBBASE
)->IBaseLock
= AllocMem (sizeof(struct SignalSemaphore
), MEMF_PUBLIC
|MEMF_CLEAR
);
92 if (!GetPrivIBase(LIBBASE
)->IBaseLock
)
95 InitSemaphore(GetPrivIBase(LIBBASE
)->IBaseLock
);
97 InitSemaphore(&GetPrivIBase(LIBBASE
)->WinDecorSem
);
98 InitSemaphore(&GetPrivIBase(LIBBASE
)->ScrDecorSem
);
99 InitSemaphore(&GetPrivIBase(LIBBASE
)->MenuDecorSem
);
101 /* Initialize global stringgadget edit hook */
102 GetPrivIBase(LIBBASE
)->DefaultEditHook
.h_Entry
= (APTR
)AROS_ASMSYMNAME(GlobalEditFunc
);
103 GetPrivIBase(LIBBASE
)->DefaultEditHook
.h_SubEntry
= NULL
;
104 GetPrivIBase(LIBBASE
)->DefaultEditHook
.h_Data
= LIBBASE
;
106 GetPrivIBase(LIBBASE
)->GlobalEditHook
= &(GetPrivIBase(LIBBASE
)->DefaultEditHook
);
108 GetPrivIBase(LIBBASE
)->DefaultPubScreen
= NULL
;
109 NEWLIST(&GetPrivIBase(LIBBASE
)->PubScreenList
);
110 InitSemaphore(&GetPrivIBase(LIBBASE
)->PubScrListLock
);
112 InitSemaphore(&GetPrivIBase(LIBBASE
)->ScreenNotificationListLock
);
113 NEWLIST(&GetPrivIBase(LIBBASE
)->ScreenNotificationList
);
115 NEWLIST(&GetPrivIBase(LIBBASE
)->Decorations
);
118 InitSemaphore(&GetPrivIBase(LIBBASE
)->GadgetLock
);
119 InitSemaphore(&GetPrivIBase(LIBBASE
)->MenuLock
);
120 InitSemaphore(&GetPrivIBase(LIBBASE
)->WindowLock
);
121 InitSemaphore(&GetPrivIBase(LIBBASE
)->IntuiActionLock
);
122 InitSemaphore(&GetPrivIBase(LIBBASE
)->InputHandlerLock
);
125 InitSemaphore(&GetPrivIBase(LIBBASE
)->DataTypesSem
);
126 GetPrivIBase(LIBBASE
)->DataTypesBase
= 0;
128 GetPrivIBase(LIBBASE
)->transphook
.h_Data
= (APTR
)GetPrivIBase(LIBBASE
);
129 GetPrivIBase(LIBBASE
)->transphook
.h_Entry
= (HOOKFUNC
)HookEntry
;
130 GetPrivIBase(LIBBASE
)->transphook
.h_SubEntry
= (HOOKFUNC
)WindowTranspFunc
;
132 GetPrivIBase(LIBBASE
)->notransphook
.h_Data
= (APTR
)GetPrivIBase(LIBBASE
);
133 GetPrivIBase(LIBBASE
)->notransphook
.h_Entry
= (HOOKFUNC
)HookEntry
;
134 GetPrivIBase(LIBBASE
)->notransphook
.h_SubEntry
= (HOOKFUNC
)WindowNoTranspFunc
;
138 memset(GetPrivIBase(LIBBASE
)->Pad
, 0xee, sizeof(GetPrivIBase(LIBBASE
)->Pad
));
139 GetPrivIBase(LIBBASE
)->SystemRequestTitle
= "System Request";
140 GetPrivIBase(LIBBASE
)->WorkbenchTitle
= "Ambient Screen";
143 * Setup the default pens to the default
144 * colors so that screens have proper color
145 * even before IPrefs is loaded.
151 p
= GetPrivIBase(LIBBASE
)->Colors
;
153 for (i
= 0; i
< COLORTABLEENTRIES
; i
++)
155 p
[i
].red
= coltab
[i
*3];
156 p
[i
].green
= coltab
[i
*3+1];
157 p
[i
].blue
= coltab
[i
*3+2];
162 GetPrivIBase(LIBBASE
)->mosmenuclass
= InitMuiMenuClass(LIBBASE
);
165 DEBUG_INIT(dprintf("LIB_Init: create menu handler task\n"));
166 /* FIXME: no cleanup routines for MenuHandler task */
167 if (!InitDefaultMenuHandler(IntuitionBase
))
170 /* FIXME: no cleanup routines for ScreennotifyHandler task */
171 if (!InitDefaultScreennotifyHandler(IntuitionBase
))
175 DEBUG_INIT(dprintf("LIB_Init: load default preferences\n"));
176 LoadDefaultPreferences(LIBBASE
);
178 GetPrivIBase(LIBBASE
)->IPrefsLoaded
= FALSE
;
182 if (!GetPrivIBase(LIBBASE
)->SmallMenuPool
)
184 if (!(GetPrivIBase(LIBBASE
)->SmallMenuPool
= CreatePool(MEMF_SEM_PROTECTED
,(sizeof (struct SmallMenuEntry
))*20,(sizeof (struct SmallMenuEntry
))*20))) return NULL
;
188 if (!(GetPrivIBase(LIBBASE
)->IDCMPPool
= CreatePool(MEMF_SEM_PROTECTED
,(sizeof (struct IntIntuiMessage
)) * 100,sizeof (struct IntIntuiMessage
)))) return FALSE
;
191 strcpy(GetPrivIBase(IntuitionBase
)->IControlExtensions
.ice_ClockFormat
,"%X");
194 GetPrivIBase(LIBBASE
)->FrameSize
= FRAMESIZE_THIN
;
199 for(i
= 0; i
< RESOURCELIST_HASHSIZE
; i
++)
201 NewList((struct List
*)&GetPrivIBase(LIBBASE
)->ResourceList
[i
]);
205 if (!(GetPrivIBase(LIBBASE
)->WinDecorObj
= NewObjectA(NULL
, WINDECORCLASS
, NULL
))) return FALSE
;
206 if (!(GetPrivIBase(LIBBASE
)->ScrDecorObj
= NewObjectA(NULL
, SCRDECORCLASS
, NULL
))) return FALSE
;
207 if (!(GetPrivIBase(LIBBASE
)->MenuDecorObj
= NewObjectA(NULL
, MENUDECORCLASS
, NULL
))) return FALSE
;
209 GetPrivIBase(LIBBASE
)->DefWinDecorObj
= GetPrivIBase(LIBBASE
)->WinDecorObj
;
210 GetPrivIBase(LIBBASE
)->DefScrDecorObj
= GetPrivIBase(LIBBASE
)->ScrDecorObj
;
211 GetPrivIBase(LIBBASE
)->DefMenuDecorObj
= GetPrivIBase(LIBBASE
)->MenuDecorObj
;
213 DEBUG_INIT(dprintf("LIB_Init: done\n"));
218 static int InitRootClass(LIBBASETYPEPTR LIBBASE
)
220 InitSemaphore(&GetPrivIBase(LIBBASE
)->ClassListLock
);
221 NEWLIST(&GetPrivIBase(LIBBASE
)->ClassList
);
223 /* Setup root class */
225 GetPrivIBase(LIBBASE
)->RootClass
.cl_Dispatcher
.h_Entry
= (APTR
)AROS_ASMSYMNAME(rootDispatcher
);
226 GetPrivIBase(LIBBASE
)->RootClass
.cl_ID
= (ClassID
)ROOTCLASS
;
227 GetPrivIBase(LIBBASE
)->RootClass
.cl_UserData
= (IPTR
)LIBBASE
;
228 DEBUG_INIT(dprintf("LIB_Init: create rootclass\n"));
229 AddClass(&(GetPrivIBase(LIBBASE
)->RootClass
));
234 /****************************************************************************************/
236 static int IntuitionOpen(LIBBASETYPEPTR LIBBASE
)
238 DEBUG_OPEN(dprintf("LIB_Open: base 0x%lx\n", LIBBASE
));
240 /* Open the input device */
242 if (!GetPrivIBase(LIBBASE
)->InputMP
)
244 if (!(GetPrivIBase(LIBBASE
)->InputMP
= CreateMsgPort()))
246 DEBUG_OPEN(dprintf("LIB_Open: can't create port\n"));
251 if (!GetPrivIBase(LIBBASE
)->InputIO
)
253 if (!(GetPrivIBase(LIBBASE
)->InputIO
= (struct IOStdReq
*)
254 CreateIORequest(GetPrivIBase(LIBBASE
)->InputMP
, sizeof (struct IOStdReq
))) )
256 DEBUG_OPEN(dprintf("LIB_Open: can't create iorequest\n"));
261 if (!GetPrivIBase(LIBBASE
)->InputDeviceOpen
)
263 if (!OpenDevice("input.device", -1, (struct IORequest
*)GetPrivIBase(LIBBASE
)->InputIO
, NULL
))
265 GetPrivIBase(LIBBASE
)->InputDeviceOpen
= TRUE
;
266 InputBase
= (struct Library
*)GetPrivIBase(LIBBASE
)->InputIO
->io_Device
;
270 DEBUG_OPEN(dprintf("LIB_Open: can't open input.device\n"));
275 if (!GetPrivIBase(LIBBASE
)->InputHandler
)
277 D(bug("Initializing inputhandler\n"));
278 if ( !(GetPrivIBase(LIBBASE
)->InputHandler
= InitIIH(LIBBASE
)) )
280 DEBUG_OPEN(dprintf("LIB_Open: can't init input handler\n"));
284 D(bug("Adding inputhandler\n"));
285 GetPrivIBase(LIBBASE
)->InputIO
->io_Data
= (APTR
)GetPrivIBase(LIBBASE
)->InputHandler
;
286 GetPrivIBase(LIBBASE
)->InputIO
->io_Command
= IND_ADDHANDLER
;
288 D(bug("Calling DoIO()\n"));
289 DoIO((struct IORequest
*)GetPrivIBase(LIBBASE
)->InputIO
);
290 D(bug("DoIO() called\n"));
296 struct ViewExtra
*ve
;
298 if (!(ve
= GfxNew(VIEW_EXTRA_TYPE
)))
301 DEBUG_OPEN(dprintf("LIB_Open: can't create view extra\n"));
305 InitView(&IntuitionBase
->ViewLord
);
307 GfxAssociate(&IntuitionBase
->ViewLord
, ve
);
309 GetPrivIBase(LIBBASE
)->ViewLordExtra
= ve
;
311 GetPrivIBase(LIBBASE
)->SpriteNum
= -1;
316 if (!GetPrivIBase(LIBBASE
)->ScreenFont
)
317 GetPrivIBase(LIBBASE
)->ScreenFont
= GfxBase
->DefaultFont
;
319 #if 0 /* CHECKME: stegerg: backport, disabled */
320 if (!(GetPrivIBase(LIBBASE
)->TopazFont
))
322 struct TextAttr textattr
= {"topaz.font",8,0,FPF_ROMFONT
};
323 GetPrivIBase(LIBBASE
)->TopazFont
= OpenFont(&textattr
);
329 if (!(TimerMP
= CreateMsgPort()))
331 DEBUG_OPEN(dprintf("LIB_Open: can't create timer port\n"));
332 return FALSE
; /* don't close anything */
335 if (!(TimerIO
= (struct timerequest
*)CreateIORequest(TimerMP
, sizeof(struct timerequest
))))
337 DEBUG_OPEN(dprintf("LIB_Open: can't create timer ioreq\n"));
338 return FALSE
; /* don't close anything */
341 if (OpenDevice(TIMERNAME
,UNIT_VBLANK
, (struct IORequest
*)TimerIO
,0))
343 DEBUG_OPEN(dprintf("LIB_Open: can't open timer.device\n"));
344 return FALSE
; /* don't close anything */
347 TimerBase
= (struct Library
*)TimerIO
->tr_node
.io_Device
;
349 SetPrefs(GetPrivIBase(LIBBASE
)->DefaultPreferences
, sizeof(struct Preferences
), FALSE
);
353 if (((struct Library
*)LIBBASE
)->lib_OpenCnt
== 0)
355 //check if dos is opened!!!
356 ((struct DosLibrary
*)DOSBase
)->dl_IntuitionBase
=
357 (struct Library
*)LIBBASE
;
359 /* Install intuition's version of DisplayError() that puts up
360 a requester with Retry/Cancel options */
361 GetPrivIBase(LIBBASE
)->OldDisplayErrorFunc
=
362 SetFunction(DOSBase
, -81*LIB_VECTSIZE
,
363 AROS_SLIB_ENTRY(DisplayError
, Intuition
));
367 if (((struct Library
*)LIBBASE
)->lib_OpenCnt
== 0)
369 InitSkinManager(IntuitionBase
);
374 /* FIXME: no cleanup routines for MenuHandler task */
375 if (!GetPrivIBase(LIBBASE
)->MenuHandlerPort
)
377 if (!InitDefaultMenuHandler(LIBBASE
))
381 /* FIXME: no cleanup routines for ScreennotifyHandler task */
382 if (!GetPrivIBase(LIBBASE
)->ScreenNotifyReplyPort
)
384 if (!InitDefaultScreennotifyHandler(LIBBASE
))
388 #ifdef INTUITION_NOTIFY_SUPPORT
389 /* Add screennotify.library base if not there yet - Piru
391 if (!GetPrivIBase(LIBBASE
)->ScreenNotifyBase
)
393 GetPrivIBase(LIBBASE
)->ScreenNotifyBase
= sn_Init(IntuitionBase
);
396 # if 0 /* not finished yet - Piru */
397 /* Add notifyintuition.library base if not there yet - Piru
399 if (!GetPrivIBase(LIBBASE
)->NotifyIntuitionBase
)
401 GetPrivIBase(LIBBASE
)->NotifyIntuitionBase
= ni_Init(IntuitionBase
);
409 DECLARESET(CLASSESINIT
);
410 ADD2SET(InitRootClass
, classesinit
, -20);
411 ADD2INITLIB(IntuitionInit
, 0);
412 ADD2OPENLIB(IntuitionOpen
, 0);