Icons for Radium and Shellplayer.
[AROS-Contrib.git] / bgui / lib.c
blobe4740dc5cf82d47241e5017753f6d7bcd8ff12c0
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * lib.c
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.
13 * $Log$
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
17 * on stack.
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
77 * Bumping to 41.10
79 * Revision 1.1 1998/02/25 17:08:46 mlemos
80 * Ian sources
85 #define NO_MEMORY_ALLOCATION_DEBUG_ALIASING
87 #include "include/classdefs.h"
89 #ifdef __AROS__
90 #include <aros/debug.h>
91 #endif
94 * Global data (written to once at initalization time).
96 BPTR SegList = 0;
97 #ifndef ENHANCED
98 makeproto BOOL OS30 = FALSE;
99 #endif
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. */
107 #ifdef __AROS__
108 struct UtilityBase *UtilityBase = NULL;
109 #else
110 struct Library *UtilityBase = NULL;
111 #endif
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;
126 #ifdef __AROS__
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 VOID BGUI_5_BGUI_GetClassPtr();
142 extern VOID BGUI_6_BGUI_NewObjectA();
143 extern VOID BGUI_7_BGUI_RequestA();
144 extern VOID BGUI_8_BGUI_Help();
145 extern VOID BGUI_9_BGUI_LockWindow();
146 extern VOID BGUI_10_BGUI_UnlockWindow();
147 extern VOID BGUI_11_BGUI_DoGadgetMethodA();
149 * Private routines.
151 extern VOID BGUI_12_BGUI_AllocPoolMem();
152 extern VOID BGUI_13_BGUI_FreePoolMem();
154 * Public routines.
156 extern VOID BGUI_14_BGUI_AllocBitMap();
157 extern VOID BGUI_15_BGUI_FreeBitMap();
158 extern VOID BGUI_16_BGUI_CreateRPortBitMap();
159 extern VOID BGUI_17_BGUI_FreeRPortBitMap();
160 extern VOID BGUI_18_BGUI_InfoTextSize();
161 extern VOID BGUI_19_BGUI_InfoText();
162 extern VOID BGUI_20_BGUI_GetLocaleStr();
163 extern VOID BGUI_21_BGUI_GetCatalogStr();
164 extern VOID BGUI_22_BGUI_FillRectPattern();
165 extern VOID BGUI_23_BGUI_PostRender();
166 extern VOID BGUI_24_BGUI_MakeClassA();
167 extern VOID BGUI_25_BGUI_FreeClass();
168 extern VOID BGUI_26_BGUI_PackStructureTags();
169 extern VOID BGUI_27_BGUI_UnpackStructureTags();
171 * Private routines.
173 extern VOID BGUI_28_BGUI_GetDefaultTags();
174 extern VOID BGUI_29_BGUI_DefaultPrefs();
175 extern VOID BGUI_30_BGUI_LoadPrefs();
176 extern VOID BGUI_31_BGUI_AllocPoolMemDebug();
177 extern VOID BGUI_32_BGUI_FreePoolMemDebug();
178 #endif
181 * Library function table.
183 STATIC const IPTR Vectors[] = {
184 #ifdef __AROS__
186 * System interface.
188 (IPTR)BGUI_1_LibOpen,
189 (IPTR)BGUI_2_LibClose,
190 (IPTR)BGUI_3_LibExpunge,
191 (IPTR)BGUI_4_LibVoid,
193 * Public routines.
195 (IPTR)BGUI_5_BGUI_GetClassPtr,
196 (IPTR)BGUI_6_BGUI_NewObjectA,
197 (IPTR)BGUI_7_BGUI_RequestA,
198 (IPTR)BGUI_8_BGUI_Help,
199 (IPTR)BGUI_9_BGUI_LockWindow,
200 (IPTR)BGUI_10_BGUI_UnlockWindow,
201 (IPTR)BGUI_11_BGUI_DoGadgetMethodA,
203 * Private routines.
205 (IPTR)BGUI_12_BGUI_AllocPoolMem,
206 (IPTR)BGUI_13_BGUI_FreePoolMem,
208 * Public routines.
210 (IPTR)BGUI_14_BGUI_AllocBitMap,
211 (IPTR)BGUI_15_BGUI_FreeBitMap,
212 (IPTR)BGUI_16_BGUI_CreateRPortBitMap,
213 (IPTR)BGUI_17_BGUI_FreeRPortBitMap,
214 (IPTR)BGUI_18_BGUI_InfoTextSize,
215 (IPTR)BGUI_19_BGUI_InfoText,
216 (IPTR)BGUI_20_BGUI_GetLocaleStr,
217 (IPTR)BGUI_21_BGUI_GetCatalogStr,
218 (IPTR)BGUI_22_BGUI_FillRectPattern,
219 (IPTR)BGUI_23_BGUI_PostRender,
220 (IPTR)BGUI_24_BGUI_MakeClassA,
221 (IPTR)BGUI_25_BGUI_FreeClass,
222 (IPTR)BGUI_26_BGUI_PackStructureTags,
223 (IPTR)BGUI_27_BGUI_UnpackStructureTags,
225 * Private routines.
227 (IPTR)BGUI_28_BGUI_GetDefaultTags,
228 (IPTR)BGUI_29_BGUI_DefaultPrefs,
229 (IPTR)BGUI_30_BGUI_LoadPrefs,
230 (IPTR)BGUI_31_BGUI_AllocPoolMemDebug,
231 (IPTR)BGUI_32_BGUI_FreePoolMemDebug,
232 #else
234 * System interface.
236 (IPTR)LibOpen,
237 (IPTR)LibClose,
238 (IPTR)LibExpunge,
239 (IPTR)LibVoid,
241 * Public routines.
244 (IPTR)BGUI_GetClassPtr,
245 (IPTR)BGUI_NewObjectA,
246 (IPTR)BGUI_RequestA,
247 (IPTR)BGUI_Help,
248 (IPTR)BGUI_LockWindow,
249 (IPTR)BGUI_UnlockWindow,
250 (IPTR)BGUI_DoGadgetMethodA,
252 * Private routines.
254 (IPTR)BGUI_AllocPoolMem,
255 (IPTR)BGUI_FreePoolMem,
257 * Public routines.
259 (IPTR)BGUI_AllocBitMap,
260 (IPTR)BGUI_FreeBitMap,
261 (IPTR)BGUI_CreateRPortBitMap,
262 (IPTR)BGUI_FreeRPortBitMap,
263 (IPTR)BGUI_InfoTextSize,
264 (IPTR)BGUI_InfoText,
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,
274 * Private routines.
276 (IPTR)BGUI_GetDefaultTags,
277 (IPTR)BGUI_DefaultPrefs,
278 (IPTR)BGUI_LoadPrefs,
279 (IPTR)BGUI_AllocPoolMemDebug,
280 (IPTR)BGUI_FreePoolMemDebug,
281 #endif
283 * Table end marker.
285 (IPTR)~0L
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)
313 UWORD num;
316 * locale.library opened?
318 if ( LocaleBase
319 && Catalog==NULL) {
321 * Obtain lock.
323 ObtainSemaphore( &TaskLock );
326 * Open up the catalog.
328 if ( (Catalog = OpenCatalog( NULL, "BGUI.catalog", OC_BuiltInLanguage, "english", OC_Version, 2, TAG_END ))) {
330 * Get strings.
332 for ( num = 0; num < NumCatCompStrings; num++ )
333 CatCompArray[ num ].cca_Str = GetCatalogStr( Catalog, num, CatCompArray[ num ].cca_Str );
337 * Free access.
339 ReleaseSemaphore( &TaskLock );
344 * Library initialization.
346 //makeproto SAVEDS ASM struct Library *LibInit(REG(a0) BPTR segment, REG(a6) struct ExecBase *syslib)
347 #ifndef __AROS__
348 makeproto SAVEDS
349 #else
350 makeproto
351 #endif
352 ASM REGFUNC3(struct Library *, LibInit,
353 REGPARAM(D0, ULONG, dummy),
354 REGPARAM(A0, BPTR, segment),
355 REGPARAM(A6, struct ExecBase *, syslib)
358 struct Library *lib;
361 * Assign SysBase.
364 SysBase = syslib;
367 * Open up system libraries.
369 #ifdef ENHANCED
370 DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 39);
371 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39);
372 GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
373 #else
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);
379 #endif
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);
393 InitInputStack();
395 #ifdef OUTDATE_BUILD
396 if(DOSBase)
398 static struct DateStamp expiry_date=
400 OUTDATE_BUILD,0,0
402 struct DateStamp today;
404 DateStamp(&today);
405 if(CompareDates(&today,&expiry_date)<0)
407 CloseLibs();
408 return(NULL);
411 #endif
413 * All libraries open?
415 if (DOSBase && IntuitionBase && GfxBase && GadToolsBase && UtilityBase && LayersBase && IFFParseBase && WorkbenchBase
416 && AslBase && CxBase && KeymapBase)
419 * Create the library.
421 if ((BGUIBase = lib = MakeLibrary((APTR)Vectors, NULL, NULL, sizeof(struct Library), BNULL)))
424 * Initialize library structure.
426 lib->lib_Node.ln_Type = NT_LIBRARY;
427 lib->lib_Node.ln_Name = (UBYTE *)LibName;
428 lib->lib_Flags = LIBF_CHANGED | LIBF_SUMUSED;
429 lib->lib_Version = LIBVER;
430 lib->lib_Revision = LIBREV;
431 lib->lib_IdString = (APTR)LibID;
434 * Globally assign the seglist.
436 SegList = segment;
439 * Add us to the system.
441 AddLibrary(lib);
444 * Initialize the task-list.
446 InitTaskList();
448 return(lib);
451 CloseLibs();
452 return NULL;
454 REGFUNC_END
457 * Open library.
459 #ifdef __AROS__
460 makeproto
461 AROS_LH1(struct Library *, LibOpen,
462 AROS_LHA(ULONG, version, D0),
463 struct Library *, lib, 1, BGUI)
464 #else
465 makeproto SAVEDS ASM struct Library *LibOpen(REG(a6) struct Library *lib, REG(d0) ULONG libver)
466 #endif
468 AROS_LIBFUNC_INIT
470 UWORD tc;
473 * Add this task to the list.
476 if ((tc = AddTaskMember()) != TASK_FAILED)
479 * Increase open counter when necessary.
481 if (tc == TASK_ADDED)
482 lib->lib_OpenCnt++;
485 * Clear delayed expunge flag.
487 lib->lib_Flags &= ~LIBF_DELEXP;
490 * Return library base or NULL upon failure.
492 return lib;
495 return NULL;
497 AROS_LIBFUNC_EXIT
501 * Close library.
503 #ifdef __AROS__
504 AROS_LH0(BPTR, LibClose,
505 struct Library *, lib, 2, BGUI)
506 #else
507 makeproto SAVEDS ASM BPTR LibClose(REG(a6) struct Library *lib)
508 #endif
510 AROS_LIBFUNC_INIT
513 * Remove the task from the member list.
515 if (!FreeTaskMember())
516 return BNULL;
519 * Of course we do not expunge when we still have accessors.
521 if (lib->lib_OpenCnt && --lib->lib_OpenCnt)
522 return BNULL;
525 * Delayed expunge pending?
527 if (lib->lib_Flags & LIBF_DELEXP) {
528 #ifdef __AROS__
529 return AROS_CALL1(BPTR, BGUI_3_LibExpunge,
530 AROS_LCA(struct Library *, lib, D0),
531 struct ExecBase *, SysBase);
532 #else
533 return LibExpunge(lib);
534 #endif
537 * Otherwise we remain in memory.
539 return BNULL;
541 AROS_LIBFUNC_EXIT
545 * Expunge library.
547 #ifdef __AROS__
548 AROS_LH1(BPTR, LibExpunge,
549 AROS_LHA(struct Library *, lib, D0),
550 struct ExecBase *, sysBase, 3, BGUI)
551 #else
552 makeproto SAVEDS ASM BPTR LibExpunge(REG(a6) struct Library *lib)
553 #endif
555 AROS_LIBFUNC_INIT
558 * No expunge when we still
559 * have accessors or when the classes
560 * fail to free.
562 if (lib->lib_OpenCnt || (!FreeClasses()))
565 * Set delayed expunge flag.
567 lib->lib_Flags |= LIBF_DELEXP;
568 return BNULL;
572 * Cleanup locale stuff.
574 if (Catalog)
575 CloseCatalog(Catalog);
577 FreeInputStack();
580 * Close system libraries.
582 CloseLibs();
584 FreeTaskList();
587 * Remove us from the system and deallocate
588 * the memory we took up.
590 Remove(&lib->lib_Node);
591 FreeMem((char *)lib - lib->lib_NegSize, lib->lib_NegSize + lib->lib_PosSize);
594 * Return the seglist so that the
595 * system can unload us.
597 return SegList;
599 AROS_LIBFUNC_EXIT
603 * Reserved routine.
605 #ifdef __AROS__
606 AROS_LH0(LONG, LibVoid,
607 struct Library *, lib, 4, BGUI)
608 #else
609 makeproto SAVEDS LONG LibVoid(void)
610 #endif
612 AROS_LIBFUNC_INIT
614 return 0;
616 AROS_LIBFUNC_EXIT