7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
14 * Revision 42.13 2004/07/11 17:10:21 stegerg
15 * LibInit() function may not leave out D0 param, even if unused,
16 * otherwise it crashes on machines where all arguments are passed
19 * Revision 42.12 2004/06/20 12:24:31 verhaegs
20 * Use REGFUNC macro's in BGUI source code, not AROS_UFH
22 * Revision 42.11 2004/06/19 20:27:48 verhaegs
23 * Added AROS_LIBFUNC_INIT/EXIT
25 * Revision 42.10 2003/01/18 19:09:58 chodorowski
26 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
28 * Revision 42.9 2002/03/07 21:33:00 stegerg
29 * These used still AROS_LHA for the arguments of libinit,
30 * instead of AROS_UFHA.
32 * Revision 42.8 2001/01/28 04:53:21 bergers
33 * Fixed some compiler complaints (some casts were missing.).
35 * Revision 42.7 2000/08/08 20:57:26 chodorowski
36 * Minor fixes to build on Amiga.
38 * Revision 42.6 2000/08/08 14:08:00 chodorowski
39 * Minor fixes to make BGUI compile on Amiga.
41 * Revision 42.5 2000/07/06 16:44:03 stegerg
42 * AddTaskMember can now be called. Problem was Cli()->cli_CommandName
43 * which BGUI expected to be a BSTR with size in first byte.
45 * Revision 42.4 2000/07/03 20:45:44 bergers
46 * Update. Test1 now successfully opens the library. In LibOpen the AddTaskMember function seems to trash the stack somehow (return address is trashed) and therefore I had to take it out.
48 * Revision 42.3 2000/06/01 01:41:37 bergers
49 * Only 2 linker problems left: stch_l & stcu_d. Somebody might want to replace them (embraced by #ifdef __AROS__), please.
51 * Revision 42.2 2000/05/31 01:23:10 bergers
52 * Changes to make BGUI compilable and linkable.
54 * Revision 42.1 2000/05/29 00:40:24 bergers
55 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
57 * Revision 42.0 2000/05/09 22:09:20 mlemos
58 * Bumped to revision 42.0 before handing BGUI to AROS team
60 * Revision 41.11 2000/05/09 19:54:31 mlemos
61 * Merged with the branch Manuel_Lemos_fixes.
63 * Revision 41.10.2.4 1999/07/24 17:08:08 mlemos
64 * Removed the code that flushed the memory to remove the current catalog.
66 * Revision 41.10.2.3 1998/10/01 04:25:58 mlemos
67 * Made the library call the functions to allocate and free the memory for the
68 * pre-allocated stack memory space for use by the input.device task.
70 * Revision 41.10.2.2 1998/06/18 23:14:15 mlemos
71 * Added code to outdate a given library build.
73 * Revision 41.10.2.1 1998/03/01 02:21:57 mlemos
74 * Added new memory allocation debugging functions to the library
76 * Revision 41.10 1998/02/25 21:12:24 mlemos
79 * Revision 1.1 1998/02/25 17:08:46 mlemos
85 #define NO_MEMORY_ALLOCATION_DEBUG_ALIASING
87 #include "include/classdefs.h"
90 #include <aros/debug.h>
94 * Global data (written to once at initalization time).
98 makeproto BOOL OS30
= FALSE
;
101 struct Library
*BGUIBase
= NULL
;
102 struct DosLibrary
*DOSBase
= NULL
;
103 struct ExecBase
*SysBase
= NULL
;
104 struct IntuitionBase
*IntuitionBase
= NULL
;
105 struct GfxBase
*GfxBase
= NULL
;
106 struct Library
*GadToolsBase
= NULL
; /* Menu stuff. */
108 struct UtilityBase
*UtilityBase
= NULL
;
110 struct Library
*UtilityBase
= NULL
;
112 struct Library
*LayersBase
= NULL
;
113 struct Library
*AslBase
= NULL
;
114 struct Library
*CxBase
= NULL
;
115 struct Library
*KeymapBase
= NULL
;
116 struct Library
*IFFParseBase
= NULL
;
117 struct Library
*DataTypesBase
= NULL
;
118 struct LocaleBase
*LocaleBase
= NULL
;
119 struct Library
*WorkbenchBase
= NULL
;
120 struct Catalog
*Catalog
= NULL
;
122 struct Task
*InputDevice
= NULL
;
123 APTR InputStack
= NULL
;
127 AROS_LD1(struct Library
*, LibOpen
,
128 AROS_LHA(ULONG
, version
, D0
),
129 struct Library
*, lib
, 1, BGUI
);
131 AROS_LD0(BPTR
, LibClose
,
132 struct Library
*, lib
, 2, BGUI
);
134 AROS_LD1(BPTR
, LibExpunge
,
135 AROS_LHA(struct Library
*, lib
, D0
),
136 struct ExecBase
*, sysBase
, 3, BGUI
);
138 AROS_LD0(LONG
, LibVoid
,
139 struct Library
*, lib
, 4, BGUI
);
141 extern BGUI_BGUI_GetClassPtr();
142 extern BGUI_BGUI_NewObjectA();
143 extern BGUI_BGUI_RequestA();
144 extern BGUI_BGUI_Help();
145 extern BGUI_BGUI_LockWindow();
146 extern BGUI_BGUI_UnlockWindow();
147 extern BGUI_BGUI_DoGadgetMethodA();
151 extern BGUI_BGUI_AllocPoolMem();
152 extern BGUI_BGUI_FreePoolMem();
156 extern BGUI_BGUI_AllocBitMap();
157 extern BGUI_BGUI_FreeBitMap();
158 extern BGUI_BGUI_CreateRPortBitMap();
159 extern BGUI_BGUI_FreeRPortBitMap();
160 extern BGUI_BGUI_InfoTextSize();
161 extern BGUI_BGUI_InfoText();
162 extern BGUI_BGUI_GetLocaleStr();
163 extern BGUI_BGUI_GetCatalogStr();
164 extern BGUI_BGUI_FillRectPattern();
165 extern BGUI_BGUI_PostRender();
166 extern BGUI_BGUI_MakeClassA();
167 extern BGUI_BGUI_FreeClass();
168 extern BGUI_BGUI_PackStructureTags();
169 extern BGUI_BGUI_UnpackStructureTags();
173 extern BGUI_BGUI_GetDefaultTags();
174 extern BGUI_BGUI_DefaultPrefs();
175 extern BGUI_BGUI_LoadPrefs();
176 extern BGUI_BGUI_AllocPoolMemDebug();
177 extern BGUI_BGUI_FreePoolMemDebug();
181 * Library function table.
183 STATIC
const IPTR Vectors
[] = {
190 (IPTR
)BGUI_LibExpunge
,
195 (IPTR
)BGUI_BGUI_GetClassPtr
,
196 (IPTR
)BGUI_BGUI_NewObjectA
,
197 (IPTR
)BGUI_BGUI_RequestA
,
198 (IPTR
)BGUI_BGUI_Help
,
199 (IPTR
)BGUI_BGUI_LockWindow
,
200 (IPTR
)BGUI_BGUI_UnlockWindow
,
201 (IPTR
)BGUI_BGUI_DoGadgetMethodA
,
205 (IPTR
)BGUI_BGUI_AllocPoolMem
,
206 (IPTR
)BGUI_BGUI_FreePoolMem
,
210 (IPTR
)BGUI_BGUI_AllocBitMap
,
211 (IPTR
)BGUI_BGUI_FreeBitMap
,
212 (IPTR
)BGUI_BGUI_CreateRPortBitMap
,
213 (IPTR
)BGUI_BGUI_FreeRPortBitMap
,
214 (IPTR
)BGUI_BGUI_InfoTextSize
,
215 (IPTR
)BGUI_BGUI_InfoText
,
216 (IPTR
)BGUI_BGUI_GetLocaleStr
,
217 (IPTR
)BGUI_BGUI_GetCatalogStr
,
218 (IPTR
)BGUI_BGUI_FillRectPattern
,
219 (IPTR
)BGUI_BGUI_PostRender
,
220 (IPTR
)BGUI_BGUI_MakeClassA
,
221 (IPTR
)BGUI_BGUI_FreeClass
,
222 (IPTR
)BGUI_BGUI_PackStructureTags
,
223 (IPTR
)BGUI_BGUI_UnpackStructureTags
,
227 (IPTR
)BGUI_BGUI_GetDefaultTags
,
228 (IPTR
)BGUI_BGUI_DefaultPrefs
,
229 (IPTR
)BGUI_BGUI_LoadPrefs
,
230 (IPTR
)BGUI_BGUI_AllocPoolMemDebug
,
231 (IPTR
)BGUI_BGUI_FreePoolMemDebug
,
244 (IPTR
)BGUI_GetClassPtr
,
245 (IPTR
)BGUI_NewObjectA
,
248 (IPTR
)BGUI_LockWindow
,
249 (IPTR
)BGUI_UnlockWindow
,
250 (IPTR
)BGUI_DoGadgetMethodA
,
254 (IPTR
)BGUI_AllocPoolMem
,
255 (IPTR
)BGUI_FreePoolMem
,
259 (IPTR
)BGUI_AllocBitMap
,
260 (IPTR
)BGUI_FreeBitMap
,
261 (IPTR
)BGUI_CreateRPortBitMap
,
262 (IPTR
)BGUI_FreeRPortBitMap
,
263 (IPTR
)BGUI_InfoTextSize
,
265 (IPTR
)BGUI_GetLocaleStr
,
266 (IPTR
)BGUI_GetCatalogStr
,
267 (IPTR
)BGUI_FillRectPattern
,
268 (IPTR
)BGUI_PostRender
,
269 (LONG
)BGUI_MakeClassA
,
270 (IPTR
)BGUI_FreeClass
,
271 (IPTR
)BGUI_PackStructureTags
,
272 (IPTR
)BGUI_UnpackStructureTags
,
276 (IPTR
)BGUI_GetDefaultTags
,
277 (IPTR
)BGUI_DefaultPrefs
,
278 (IPTR
)BGUI_LoadPrefs
,
279 (IPTR
)BGUI_AllocPoolMemDebug
,
280 (IPTR
)BGUI_FreePoolMemDebug
,
289 * Close opened libraries.
291 SAVEDS STATIC VOID
CloseLibs(void)
293 if( LocaleBase
) CloseLibrary( (struct Library
*) LocaleBase
);
294 if( KeymapBase
) CloseLibrary( KeymapBase
);
295 if( CxBase
) CloseLibrary( CxBase
);
296 if( AslBase
) CloseLibrary( AslBase
);
297 if( LayersBase
) CloseLibrary( LayersBase
);
298 if( UtilityBase
) CloseLibrary( (struct Library
*) UtilityBase
);
299 if( GadToolsBase
) CloseLibrary( GadToolsBase
);
300 if( DataTypesBase
) CloseLibrary( DataTypesBase
);
301 if( IFFParseBase
) CloseLibrary( IFFParseBase
);
302 if( WorkbenchBase
) CloseLibrary( WorkbenchBase
);
303 if( GfxBase
) CloseLibrary( (struct Library
*) GfxBase
);
304 if( IntuitionBase
) CloseLibrary( (struct Library
*) IntuitionBase
);
305 if( DOSBase
) CloseLibrary( (struct Library
*) DOSBase
);
309 * Setup localized strings.
311 makeproto VOID
InitLocale(void)
316 * locale.library opened?
323 ObtainSemaphore( &TaskLock
);
326 * Open up the catalog.
328 if ( Catalog
= OpenCatalog( NULL
, "BGUI.catalog", OC_BuiltInLanguage
, "english", OC_Version
, 2, TAG_END
)) {
332 for ( num
= 0; num
< NumCatCompStrings
; num
++ )
333 CatCompArray
[ num
].cca_Str
= GetCatalogStr( Catalog
, num
, CatCompArray
[ num
].cca_Str
);
339 ReleaseSemaphore( &TaskLock
);
344 * Library initialization.
346 //makeproto SAVEDS ASM struct Library *LibInit(REG(a0) BPTR segment, REG(a6) struct ExecBase *syslib)
352 ASM
REGFUNC3(struct Library
*, LibInit
,
353 REGPARAM(D0
, ULONG
, dummy
),
354 REGPARAM(A0
, BPTR
, segment
),
355 REGPARAM(A6
, struct ExecBase
*, syslib
)
367 * Open up system libraries.
370 DOSBase
= (struct DosLibrary
*) OpenLibrary("dos.library", 39);
371 IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39);
372 GfxBase
= (struct GfxBase
*) OpenLibrary("graphics.library", 39);
374 OS30
= (((struct Library
*)SysBase
)->lib_Version
>= 39);
376 DOSBase
= (struct DosLibrary
*) OpenLibrary("dos.library", 37);
377 IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 37);
378 GfxBase
= (struct GfxBase
*) OpenLibrary("graphics.library", 37);
381 LocaleBase
= (struct LocaleBase
*) OpenLibrary("locale.library", 38);
383 GadToolsBase
= OpenLibrary("gadtools.library", 37);
384 UtilityBase
= (struct UtilityBase
*) OpenLibrary("utility.library", 37);
385 LayersBase
= OpenLibrary("layers.library", 37);
386 AslBase
= OpenLibrary("asl.library", 37);
387 CxBase
= OpenLibrary("commodities.library", 37);
388 KeymapBase
= OpenLibrary("keymap.library", 37);
389 IFFParseBase
= OpenLibrary("iffparse.library", 37);
390 WorkbenchBase
= OpenLibrary("workbench.library", 37);
391 DataTypesBase
= OpenLibrary("datatypes.library", 39);
394 #warning Commented InitInputStack
402 static struct DateStamp expiry_date
=
406 struct DateStamp today
;
409 if(CompareDates(&today
,&expiry_date
)<0)
417 * All libraries open?
419 if (DOSBase
&& IntuitionBase
&& GfxBase
&& GadToolsBase
&& UtilityBase
&& LayersBase
&& IFFParseBase
&& WorkbenchBase
420 && AslBase
&& CxBase
&& KeymapBase
)
423 * Create the library.
425 if (BGUIBase
= lib
= MakeLibrary((APTR
)Vectors
, NULL
, NULL
, sizeof(struct Library
), NULL
))
428 * Initialize library structure.
430 lib
->lib_Node
.ln_Type
= NT_LIBRARY
;
431 lib
->lib_Node
.ln_Name
= (UBYTE
*)LibName
;
432 lib
->lib_Flags
= LIBF_CHANGED
| LIBF_SUMUSED
;
433 lib
->lib_Version
= LIBVER
;
434 lib
->lib_Revision
= LIBREV
;
435 lib
->lib_IdString
= (APTR
)LibID
;
438 * Globally assign the seglist.
443 * Add us to the system.
448 * Initialize the task-list.
465 AROS_LH1(struct Library
*, LibOpen
,
466 AROS_LHA(ULONG
, version
, D0
),
467 struct Library
*, lib
, 1, BGUI
)
469 makeproto SAVEDS ASM
struct Library
*LibOpen(REG(a6
) struct Library
*lib
, REG(d0
) ULONG libver
)
477 * Add this task to the list.
480 if ((tc
= AddTaskMember()) != TASK_FAILED
)
483 * Increase open counter when necessary.
485 if (tc
== TASK_ADDED
)
489 * Clear delayed expunge flag.
491 lib
->lib_Flags
&= ~LIBF_DELEXP
;
494 * Return library base or NULL upon failure.
508 AROS_LH0(BPTR
, LibClose
,
509 struct Library
*, lib
, 2, BGUI
)
511 makeproto SAVEDS ASM BPTR
LibClose(REG(a6
) struct Library
*lib
)
517 * Remove the task from the member list.
519 if (!FreeTaskMember())
523 * Of course we do not expunge when we still have accessors.
525 if (lib
->lib_OpenCnt
&& --lib
->lib_OpenCnt
)
529 * Delayed expunge pending?
531 if (lib
->lib_Flags
& LIBF_DELEXP
)
533 return AROS_UFC2(BPTR
, BGUI_LibExpunge
,
534 AROS_UFCA(struct Library
*, lib
, D0
),
535 AROS_UFCA(struct ExecBase
*, SysBase
, A6
));
537 return LibExpunge(lib
);
540 * Otherwise we remain in memory.
551 AROS_LH1(BPTR
, LibExpunge
,
552 AROS_LHA(struct Library
*, lib
, D0
),
553 struct ExecBase
*, sysBase
, 3, BGUI
)
555 makeproto SAVEDS ASM BPTR
LibExpunge(REG(a6
) struct Library
*lib
)
561 * No expunge when we still
562 * have accessors or when the classes
565 if (lib
->lib_OpenCnt
|| (!FreeClasses()))
568 * Set delayed expunge flag.
570 lib
->lib_Flags
|= LIBF_DELEXP
;
575 * Cleanup locale stuff.
578 CloseCatalog(Catalog
);
581 #warning Commented FreeInputStack
587 * Close system libraries.
594 * Remove us from the system and deallocate
595 * the memory we took up.
597 Remove(&lib
->lib_Node
);
598 FreeMem((char *)lib
- lib
->lib_NegSize
, lib
->lib_NegSize
+ lib
->lib_PosSize
);
601 * Return the seglist so that the
602 * system can unload us.
613 AROS_LH0(LONG
, LibVoid
,
614 struct Library
*, lib
, 4, BGUI
)
616 makeproto SAVEDS LONG
LibVoid(void)