Icons for Radium and Shellplayer.
[AROS-Contrib.git] / bgui / libfunc.c
blobb9569b9c56d8be5e0efb5cb6763ee36f8d5bb4cc
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * libfunc.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.9 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.8 2003/01/18 19:09:58 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.7 2000/08/09 11:45:57 chodorowski
21 * Removed a lot of #ifdefs that disabled the AROS_LIB* macros when not building on AROS. This is now handled in contrib/bgui/include/bgui_compilerspecific.h.
23 * Revision 42.6 2000/08/08 14:08:00 chodorowski
24 * Minor fixes to make BGUI compile on Amiga.
26 * Revision 42.5 2000/07/09 03:05:07 bergers
27 * Makes the gadgets compilable.
29 * Revision 42.4 2000/06/01 01:41:37 bergers
30 * Only 2 linker problems left: stch_l & stcu_d. Somebody might want to replace them (embraced by #ifdef __AROS__), please.
32 * Revision 42.3 2000/05/29 00:40:24 bergers
33 * 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.
35 * Revision 42.2 2000/05/15 19:27:01 stegerg
36 * another hundreds of REG() macro replacements in func headers/protos.
38 * Revision 42.1 2000/05/14 23:32:47 stegerg
39 * changed over 200 function headers which all use register
40 * parameters (oh boy ...), because the simple REG() macro
41 * doesn't work with AROS. And there are still hundreds
42 * of headers left to be fixed :(
44 * Many of these functions would also work with stack
45 * params, but since i have fixed every single one
46 * I encountered up to now, I guess will have to do
47 * the same for the rest.
49 * Revision 42.0 2000/05/09 22:09:23 mlemos
50 * Bumped to revision 42.0 before handing BGUI to AROS team
52 * Revision 41.11 2000/05/09 19:54:33 mlemos
53 * Merged with the branch Manuel_Lemos_fixes.
55 * Revision 41.10.2.11 2000/05/04 04:39:06 mlemos
56 * Added the entries to the now built-in supported bar and layout group gadget
57 * classes.
59 * Revision 41.10.2.10 1999/08/17 19:11:24 mlemos
60 * Prevented base class from being replaced by an external library.
62 * Revision 41.10.2.9 1999/07/31 01:56:02 mlemos
63 * Added code to keep track of created objects.
65 * Revision 41.10.2.8 1999/07/29 00:43:47 mlemos
66 * Ensured that external library classes can only be freed if they get marked
67 * as such.
69 * Revision 41.10.2.7 1999/07/28 23:17:11 mlemos
70 * Allowed the library to be expunged if there no remainining classes with
71 * open subclasses but without any objects to be disposed.
73 * Revision 41.10.2.6 1999/07/28 16:38:05 mlemos
74 * Added code to detect class object leaks in FreeClasses.
75 * Made FreeClasses iterate until the number of classes subclasses that remain
76 * to be freed does not change.
78 * Revision 41.10.2.5 1999/07/18 02:58:03 mlemos
79 * Fixed problem of BGUI_CallHookPkt using the stack frame to store local
80 * variables that were pointing to the wrong address after EnsureStack was
81 * called.
83 * Revision 41.10.2.4 1999/07/03 15:16:54 mlemos
84 * Added the function BGUI_CallHookPkt.
85 * Replaced the calls to CallHookPkt to BGUI_CallHookPkt.
87 * Revision 41.10.2.3 1999/05/31 00:45:03 mlemos
88 * Added the TreeView gadget to the list of internally supported gadgets.
90 * Revision 41.10.2.2 1998/10/12 01:26:56 mlemos
91 * Made the ARexx be initialized internally whenever is needed.
93 * Revision 41.10.2.1 1998/03/02 23:51:17 mlemos
94 * Switched vector allocation functions calls to BGUI allocation functions.
96 * Revision 41.10 1998/02/25 21:12:26 mlemos
97 * Bumping to 41.10
99 * Revision 1.1 1998/02/25 17:08:50 mlemos
100 * Ian sources
105 #include "include/classdefs.h"
108 * Internal lock housekeeping.
110 typedef struct {
111 struct Requester wl_IDCMPLock; /* Requester lock. */
112 struct Window *wl_Locked; /* Locked window. */
113 UWORD wl_MinWidth, wl_MinHeight; /* Current sizes. */
114 UWORD wl_MaxWidth, wl_MaxHeight; /* " " */
115 } WINDOWLOCK;
118 #ifdef DEBUG_BGUI
120 static ULONG object_serial_number=1;
122 struct ObjectTracking
124 struct ObjectTracking *Next;
125 Object *Object;
126 ULONG SerialNumber;
127 STRPTR File;
128 ULONG Line;
131 static struct ObjectTracking *tracked_objects=NULL;
133 makeproto ULONG TrackNewObject(Object *object,struct TagItem *tags)
135 struct ObjectTracking *track;
137 if((track=BGUI_AllocPoolMem(sizeof(*track)))==NULL)
138 return(0);
139 track->Object=object;
140 Forbid();
141 track->SerialNumber=object_serial_number++;
142 track->Next=tracked_objects;
143 tracked_objects=track;
144 Permit();
145 return(track->SerialNumber);
148 makeproto BOOL TrackDisposedObject(Object *object)
150 struct ObjectTracking **track,*found;
152 Forbid();
153 for(track= &tracked_objects;(found= *track) && (*track)->Object!=object;track= &(*track)->Next);
154 if(found)
156 *track= found->Next;
157 BGUI_FreePoolMem(found);
159 else
160 bug("*** Could not track disposed object %lX\n",object);
161 Permit();
162 return((BOOL)(found!=NULL));
166 static void DumpTrackedObjects(void)
168 Forbid();
169 while(tracked_objects)
171 struct ObjectTracking *track;
173 track= tracked_objects;
174 tracked_objects=track->Next;
175 bug("*** Object %lX leaked! Serial number %lu\n",track->Object,track->SerialNumber);
176 BGUI_FreePoolMem(track);
178 Permit();
181 #endif
184 * Table for class init stuff.
186 typedef struct {
187 Class *cd_Storage;
188 Class *(*cd_InitFunc)(void);
189 UWORD cd_ClassID;
190 UBYTE *cd_ClassFile;
191 struct BGUIClassBase *cd_ClassBase;
192 struct TagItem *cd_DefTags;
193 BOOL cd_Leaking;
194 BOOL cd_LibraryClass;
195 } CLASSDEF;
197 STATIC CLASSDEF Classes[] =
199 { NULL, InitGroupNodeClass, BGUI_GROUP_NODE, NULL, NULL, FALSE, FALSE },
201 { NULL, InitDGMClass, BGUI_DGM_OBJECT, NULL, NULL, FALSE, FALSE },
202 { NULL, InitRootClass, BGUI_ROOT_OBJECT, NULL, NULL, FALSE, FALSE },
205 * Graphic classes.
207 { NULL, InitTextClass, BGUI_TEXT_GRAPHIC, NULL, NULL, FALSE, FALSE },
210 * Image classes.
212 { NULL, InitImageClass, BGUI_IMAGE_OBJECT, NULL, NULL, FALSE, FALSE },
213 { NULL, InitFrameClass, BGUI_FRAME_IMAGE, "images/bgui_frame.image", NULL, FALSE, FALSE },
214 { NULL, InitLabelClass, BGUI_LABEL_IMAGE, "images/bgui_label.image", NULL, FALSE, FALSE },
215 { NULL, InitVectorClass, BGUI_VECTOR_IMAGE, "images/bgui_vector.image", NULL, FALSE, FALSE },
216 { NULL, InitSystemClass, BGUI_SYSTEM_IMAGE, "images/bgui_system.image", NULL, FALSE, FALSE },
219 * Gadget classes.
221 { NULL, InitGadgetClass, BGUI_GADGET_OBJECT, NULL, NULL, FALSE, FALSE },
222 { NULL, InitBaseClass, BGUI_BASE_GADGET, NULL, NULL, FALSE, FALSE },
223 { NULL, InitButtonClass, BGUI_BUTTON_GADGET, "gadgets/bgui_button.gadget", NULL, FALSE, FALSE },
224 { NULL, InitGroupClass, BGUI_GROUP_GADGET, "gadgets/bgui_group.gadget", NULL, FALSE, FALSE },
225 { NULL, InitCycleClass, BGUI_CYCLE_GADGET, "gadgets/bgui_cycle.gadget", NULL, FALSE, FALSE },
226 { NULL, InitCheckBoxClass, BGUI_CHECKBOX_GADGET, "gadgets/bgui_checkbox.gadget", NULL, FALSE, FALSE },
227 { NULL, InitInfoClass, BGUI_INFO_GADGET, "gadgets/bgui_info.gadget", NULL, FALSE, FALSE },
228 { NULL, InitStringClass, BGUI_STRING_GADGET, "gadgets/bgui_string.gadget", NULL, FALSE, FALSE },
229 { NULL, InitPropClass, BGUI_PROP_GADGET, "gadgets/bgui_prop.gadget", NULL, FALSE, FALSE },
230 { NULL, InitIndicatorClass, BGUI_INDICATOR_GADGET, "gadgets/bgui_indicator.gadget", NULL, FALSE, FALSE },
231 { NULL, InitProgressClass, BGUI_PROGRESS_GADGET, "gadgets/bgui_progress.gadget", NULL, FALSE, FALSE },
232 { NULL, InitSliderClass, BGUI_SLIDER_GADGET, "gadgets/bgui_slider.gadget", NULL, FALSE, FALSE },
233 { NULL, InitPageClass, BGUI_PAGE_GADGET, "gadgets/bgui_page.gadget", NULL, FALSE, FALSE },
234 { NULL, InitMxClass, BGUI_MX_GADGET, "gadgets/bgui_mx.gadget", NULL, FALSE, FALSE },
235 { NULL, InitListClass, BGUI_LISTVIEW_GADGET, "gadgets/bgui_listview.gadget", NULL, FALSE, FALSE },
236 { NULL, InitExtClass, BGUI_EXTERNAL_GADGET, "gadgets/bgui_external.gadget", NULL, FALSE, FALSE },
237 { NULL, InitSepClass, BGUI_SEPARATOR_GADGET, "gadgets/bgui_separator.gadget", NULL, FALSE, FALSE },
238 { NULL, InitRadioButtonClass, BGUI_RADIOBUTTON_GADGET, "gadgets/bgui_radiobutton.gadget", NULL, FALSE, FALSE },
239 { NULL, InitAreaClass, BGUI_AREA_GADGET, "gadgets/bgui_area.gadget", NULL, FALSE, FALSE },
240 { NULL, InitViewClass, BGUI_VIEW_GADGET, "gadgets/bgui_view.gadget", NULL, FALSE, FALSE },
241 { NULL, NULL, BGUI_PALETTE_GADGET, "gadgets/bgui_palette.gadget", NULL, FALSE, FALSE },
242 { NULL, NULL, BGUI_POPBUTTON_GADGET, "gadgets/bgui_popbutton.gadget", NULL, FALSE, FALSE },
243 { NULL, NULL, BGUI_TREEVIEW_GADGET, "gadgets/bgui_treeview.gadget", NULL, FALSE, FALSE },
244 { NULL, NULL, BGUI_BAR_GADGET, "gadgets/bgui_bar.gadget", NULL, FALSE, FALSE },
245 { NULL, NULL, BGUI_LAYOUTGROUP_GADGET, "gadgets/bgui_layoutgroup.gadget", NULL, FALSE, FALSE },
248 * Misc. classes.
250 { NULL, InitWindowClass, BGUI_WINDOW_OBJECT, "bgui_window.class", NULL, FALSE, FALSE },
251 { NULL, InitCxClass, BGUI_COMMODITY_OBJECT, "bgui_commodity.class", NULL, FALSE, FALSE },
252 { NULL, InitAslReqClass, BGUI_ASLREQ_OBJECT, "bgui_aslreq.class", NULL, FALSE, FALSE },
253 { NULL, InitFileReqClass, BGUI_FILEREQ_OBJECT, "bgui_filereq.class", NULL, FALSE, FALSE },
254 { NULL, InitFontReqClass, BGUI_FONTREQ_OBJECT, "bgui_fontreq.class", NULL, FALSE, FALSE },
255 { NULL, InitScreenReqClass, BGUI_SCREENREQ_OBJECT, "bgui_screenreq.class", NULL, FALSE, FALSE },
257 #ifdef __AROS__
258 /* AREXX is not yet supported on AROS */
259 #else
260 { NULL, InitArexxClass, BGUI_AREXX_OBJECT, "bgui_arexx.class", NULL, FALSE, FALSE },
261 #endif
262 { NULL, InitSpacingClass, BGUI_SPACING_OBJECT, NULL, NULL, FALSE, FALSE },
264 { NULL, NULL, (UWORD)~0, NULL }
268 * Free the classes. Returns FALSE if one of the classes
269 * fail to free.
271 makeproto BOOL FreeClasses(void)
273 CLASSDEF *cd;
274 BOOL rc = TRUE;
275 ULONG subclasses,last_subclasses=0,opened_classes;
277 Forbid();
280 opened_classes=subclasses=0;
281 for (cd = Classes; cd->cd_ClassID != (UWORD)~0; cd++)
283 if(last_subclasses==0)
284 cd->cd_Leaking=FALSE;
285 if (cd->cd_Storage)
287 if (cd->cd_LibraryClass)
289 if(cd->cd_ClassBase)
291 CloseLibrary((struct Library *)cd->cd_ClassBase);
292 cd->cd_ClassBase = NULL;
294 opened_classes++;
295 rc=FALSE;
297 else
300 * Return FALSE if one or more fail to free.
302 if (!BGUI_FreeClass(cd->cd_Storage))
304 rc = FALSE;
305 if(cd->cd_Storage->cl_SubclassCount)
307 subclasses+=cd->cd_Storage->cl_SubclassCount;
308 if(cd->cd_Storage->cl_ObjectCount)
309 opened_classes++;
311 else
313 if(!cd->cd_Leaking)
315 cd->cd_Leaking=TRUE;
316 D(bug("*** Object leak of class %lu: Class %lX, Object count %lu\n",cd->cd_ClassID,cd->cd_Storage,cd->cd_Storage->cl_ObjectCount));
320 else
321 cd->cd_Storage = NULL;
324 else
325 cd->cd_LibraryClass=FALSE;
327 if(last_subclasses==subclasses)
328 break;
329 last_subclasses=subclasses;
331 while(subclasses);
332 if(!rc)
334 if(opened_classes==0)
336 for (cd = Classes; cd->cd_ClassID != (UWORD)~0; cd++)
337 cd->cd_Storage = NULL;
338 #ifdef DEBUG_BGUI
339 DumpTrackedObjects();
340 #endif
341 rc=TRUE;
343 else
345 D(bug("Opened classes %lu\n",opened_classes));
348 Permit();
349 return rc;
352 makeproto void MarkFreedClass(Class *cl)
354 CLASSDEF *cd;
356 Forbid();
357 for (cd = Classes; cd->cd_ClassID != (UWORD)~0; cd++)
359 if(cl==cd->cd_Storage)
361 cd->cd_Storage = NULL;
362 break;
365 Permit();
370 * Obtain a class pointer. This routine will only fail if you pass it
371 * a non-existing class ID, or the class fails to initialize.
373 #ifdef __AROS__
374 makearosproto
375 AROS_LH1(Class *, BGUI_GetClassPtr,
376 AROS_LHA(ULONG, classID, D0),
377 struct Library *, BGUIBase, 5, BGUI)
378 #else
379 makeproto SAVEDS ASM Class *BGUI_GetClassPtr( REG(d0) ULONG classID )
380 #endif
382 AROS_LIBFUNC_INIT
384 CLASSDEF *cd;
385 Class *cl = NULL;
388 for (cd = Classes; cd->cd_ClassID != (UWORD)~0; cd++)
390 if (classID == (UWORD)cd->cd_ClassID)
392 if (!(cl = cd->cd_Storage))
394 if (cd->cd_ClassFile)
396 if ((cd->cd_ClassBase = (struct BGUIClassBase *)OpenLibrary(cd->cd_ClassFile, 0)))
399 * Get the class pointer.
401 cl = cd->cd_ClassBase->bcb_Class;
402 cd->cd_LibraryClass=TRUE;
405 if (!cl && cd->cd_InitFunc)
408 * Call the initialization routine.
410 cl = (cd->cd_InitFunc)();
412 cd->cd_Storage = cl;
414 break;
417 return cl;
419 AROS_LIBFUNC_EXIT
422 #if defined(__AROS__) && defined(NO_LINEAR_VARARGS)
424 * Var-args stub for BGUI_NewObjectA().
426 * This is a little complicated on NO_LINEAR_VARARGS architectures,
427 * since BGUI puts ((GROUP_Member,obj) ... (TAG_END,0)) sequences
428 * in its arguments to BGUI_NewObject, so we can't use the
429 * standard AROS_SLOWSTACKTAGS_* family.
431 makeproto Object *BGUI_NewObject(ULONG classID, Tag tag1, ...)
433 va_list va, vc;
434 int gm_depth = 0, len = 0;
435 Tag tag;
436 IPTR data;
437 Object *rc = NULL;
438 struct TagItem *tags;
440 va_start(va, tag1);
441 va_copy(vc, va);
443 /* Determine the va list length, skipping GROUP_Member tagsets */
444 for (tag = tag1; gm_depth >= 0; tag = va_arg(va, IPTR) ) {
445 data = va_arg(va, IPTR);
446 (void)data;
447 len++;
449 switch (tag) {
450 case TAG_END:
451 gm_depth--;
452 break;
453 case TAG_MORE:
454 if (gm_depth == 0)
455 gm_depth = -1;
456 break;
457 case GROUP_Member:
458 gm_depth++;
459 break;
463 tags = AllocMem(sizeof(tags[0])*len, MEMF_ANY);
464 if (tags != NULL) {
465 int i;
466 tag = tag1;
467 for (i = 0; i < len; i++) {
468 tags[i].ti_Tag = tag;
469 tags[i].ti_Data = va_arg(vc, IPTR);
470 if (i != (len-1))
471 tag = va_arg(vc, IPTR);
474 rc = BGUI_NewObjectA(classID, tags);
475 FreeMem(tags, sizeof(tags[0])*len);
477 va_end(vc);
478 va_end(va);
479 return rc;
481 #else
483 * Var-args stub for BGUI_NewObjectA().
485 makeproto Object *BGUI_NewObject(ULONG classID, Tag tag1, ...)
487 return BGUI_NewObjectA(classID, (struct TagItem *)&tag1);
489 #endif
492 * Create an object from a class.
494 #ifdef __AROS__
495 makearosproto
496 AROS_LH2(Object *, BGUI_NewObjectA,
497 AROS_LHA(ULONG, classID, D0),
498 AROS_LHA(struct TagItem *, attr, A0),
499 struct Library *, BGUIBase, 6, BGUI)
500 #else
501 makeproto SAVEDS ASM Object *BGUI_NewObjectA( REG(d0) ULONG classID, REG(a0) struct TagItem *attr )
502 #endif
504 AROS_LIBFUNC_INIT
506 Class *cl;
507 Object *obj = NULL;
509 if ((cl = BGUI_GetClassPtr(classID)))
510 obj = NewObjectA(cl, NULL, attr);
512 return obj;
514 AROS_LIBFUNC_EXIT
518 * Allocate a bitmap.
520 #ifdef __AROS__
521 makearosproto
522 AROS_LH5(struct BitMap *, BGUI_AllocBitMap,
523 AROS_LHA(ULONG, width, D0),
524 AROS_LHA(ULONG, height, D1),
525 AROS_LHA(ULONG, depth, D2),
526 AROS_LHA(ULONG, flags, D3),
527 AROS_LHA(struct BitMap *, fr, A0),
528 struct Library *, BGUIBase, 14, BGUI)
529 #else
530 makeproto SAVEDS ASM struct BitMap *BGUI_AllocBitMap( REG(d0) ULONG width, REG(d1) ULONG height, REG(d2) ULONG depth,
531 REG(d3) ULONG flags, REG(a0) struct BitMap *fr )
532 #endif
534 AROS_LIBFUNC_INIT
536 #ifdef ENHANCED
537 return AllocBitMap(width, height, depth, flags | BMF_MINPLANES, fr);
538 #else
539 struct BitMap *bm = NULL;
540 ULONG *b;
541 int i, rassize;
544 * Use the system routine if
545 * we are running OS 3.0 or better.
547 if (OS30)
548 return AllocBitMap(width, height, depth, flags | BMF_MINPLANES, fr);
551 * Not OS 3.0 or better?
552 * Make the bitmap ourselves.
554 if ((b = (ULONG *)BGUI_AllocPoolMem(sizeof(struct BitMap) + sizeof(ULONG))))
556 *b = ID_BGUI;
557 bm = (struct BitMap *)(b + 1);
558 InitBitMap(bm, depth, width, height);
560 flags = flags & BMF_CLEAR ? MEMF_CHIP : MEMF_CHIP | MEMF_CLEAR;
561 rassize = RASSIZE(width, height);
564 * Allocate planes.
566 for (i = 0; i < depth; i++)
568 if (!(bm->Planes[i] = AllocVec(rassize, flags)))
570 BGUI_FreeBitMap(bm);
571 return NULL;
575 return bm;
576 #endif
578 AROS_LIBFUNC_EXIT
582 * Free a bitmap.
584 #ifdef __AROS__
585 makearosproto
586 AROS_LH1(VOID, BGUI_FreeBitMap,
587 AROS_LHA(struct BitMap *, bm, A0),
588 struct Library *, BGUIBase, 15, BGUI)
589 #else
590 makeproto SAVEDS ASM VOID BGUI_FreeBitMap( REG(a0) struct BitMap *bm )
591 #endif
593 AROS_LIBFUNC_INIT
595 #ifdef ENHANCED
596 WaitBlit();
597 FreeBitMap(bm);
598 #else
600 ULONG *b = ((ULONG *)bm) - 1;
601 int i;
602 UBYTE *p;
604 if (bm)
607 * Wait for the blitter.
609 WaitBlit();
612 * Under OS 3.0 we call the system routine.
614 if (*b == ID_BGUI)
616 for (i = bm->Depth - 1; i >= 0; --i)
619 * Free planes.
621 if ((p = bm->Planes[i])) FreeVec(p);
624 * Free the structure.
626 BGUI_FreePoolMem(b);
628 else
630 FreeBitMap(bm);
633 #endif
635 AROS_LIBFUNC_EXIT
639 * Allocate a rastport with bitmap.
641 #ifdef __AROS__
642 makearosproto
643 AROS_LH4(struct RastPort *, BGUI_CreateRPortBitMap,
644 AROS_LHA(struct RastPort *, source, A0),
645 AROS_LHA(ULONG, width, D0),
646 AROS_LHA(ULONG, height, D1),
647 AROS_LHA(ULONG, depth, D2),
648 struct Library *, BGUIBase, 16, BGUI)
649 #else
650 makeproto SAVEDS ASM struct RastPort *BGUI_CreateRPortBitMap( REG(a0) struct RastPort *source,
651 REG(d0) ULONG width, REG(d1) ULONG height, REG(d2) ULONG depth )
652 #endif
654 AROS_LIBFUNC_INIT
656 struct RastPort *rp;
657 struct Layer_Info *li;
660 * Allocate a rastport structure.
662 if ((rp = (struct RastPort *)BGUI_AllocPoolMem(sizeof(struct RastPort))))
665 * If we have a source rastport we
666 * copy it. Otherwise we initialize
667 * the rastport.
669 if (source) *rp = *source;
670 else InitRastPort(rp);
672 if (!depth && source) depth = FGetDepth(source);
675 * Add a bitmap.
677 if ((rp->BitMap = BGUI_AllocBitMap(width, height, depth, BMF_CLEAR, source ? source->BitMap : NULL)))
680 * NO LAYER!.
682 // rp->Layer = NULL;
684 if ((li = NewLayerInfo()))
686 if ((rp->Layer = CreateUpfrontLayer(li, rp->BitMap, 0, 0, width - 1, height - 1, 0, NULL)))
689 * Mark it as a buffered rastport.
691 // rp->RP_User = ID_BFRP;
693 return rp;
696 * No layer.
698 DisposeLayerInfo(li);
701 * No layerinfo.
703 BGUI_FreeBitMap(rp->BitMap);
706 * No bitmap.
708 BGUI_FreePoolMem(rp);
710 return NULL;
712 AROS_LIBFUNC_EXIT
716 * Free a buffer rastport and bitmap.
718 #ifdef __AROS__
719 makearosproto
720 AROS_LH1(VOID, BGUI_FreeRPortBitMap,
721 AROS_LHA(struct RastPort *, rp, A0),
722 struct Library *, BGUIBase, 17, BGUI)
723 #else
724 makeproto SAVEDS ASM VOID BGUI_FreeRPortBitMap( REG(a0) struct RastPort *rp )
725 #endif
727 AROS_LIBFUNC_INIT
729 struct Layer *l = rp->Layer;
730 struct Layer_Info *li = l->LayerInfo;
733 * Free the layer.
735 InstallClipRegion(l, NULL);
736 DeleteLayer(0, l);
739 * Free the layerinfo.
741 DisposeLayerInfo(li);
744 * Free the bitmap.
746 BGUI_FreeBitMap(rp->BitMap);
749 * Free the rastport.
751 BGUI_FreePoolMem(rp);
753 AROS_LIBFUNC_EXIT
757 * Show AmigaGuide file.
759 #ifdef __AROS__
760 makearosproto
761 AROS_LH4(BOOL, BGUI_Help,
762 AROS_LHA(struct Window *, win, A0),
763 AROS_LHA(UBYTE *, file, A1),
764 AROS_LHA(UBYTE *, node, A2),
765 AROS_LHA(ULONG, line, D0),
766 struct Library *, BGUIBase, 8, BGUI)
767 #else
768 makeproto SAVEDS ASM BOOL BGUI_Help( REG(a0) struct Window *win, REG(a1) UBYTE *file, REG(a2) UBYTE *node, REG(d0) ULONG line )
769 #endif
771 AROS_LIBFUNC_INIT
773 struct NewAmigaGuide nag = { };
776 * Initialize structure.
778 nag.nag_Name = ( STRPTR )file;
779 nag.nag_Node = ( STRPTR )node;
780 nag.nag_Line = line;
781 nag.nag_Screen = win ? win->WScreen : NULL;
784 * Show file.
786 return( DisplayAGuideInfo( &nag, TAG_END ));
788 AROS_LIBFUNC_EXIT
793 * Set or clear the busy pointer.
795 STATIC ASM VOID Busy(REG(a0) struct Window *win, REG(d0) BOOL set)
797 #ifdef ENHANCED
799 if (set) SetWindowPointer(win, WA_BusyPointer, TRUE, WA_PointerDelay, TRUE, TAG_END);
800 else SetWindowPointer(win, TAG_END);
802 #else
805 * Must be in chip memory (busy pointer on OS 2.04 machines).
807 static __chip UWORD BusyPointer[] =
809 0x0000, 0x0000, 0x0400, 0x07c0, 0x0000, 0x07c0, 0x0100, 0x0380,
810 0x0000, 0x07e0, 0x07c0, 0x1ff8, 0x1FF0, 0x3FEC, 0x3FF8, 0x7FDE,
811 0x3FF8, 0x7FBE, 0x7FFC, 0xFF7F, 0x7EFC, 0xFFFF, 0x7FFC, 0xFFFF,
812 0x3FF8, 0x7FFE, 0x3FF8, 0x7FFE, 0x1FF0, 0x3FFC, 0x07C0, 0x1FF8,
813 0x0000, 0x07E0, 0x0000, 0x0000
816 if (OS30)
818 if (set) SetWindowPointer(win, WA_BusyPointer, TRUE, WA_PointerDelay, TRUE, TAG_END);
819 else SetWindowPointer(win, TAG_END);
821 else
823 if (set) SetPointer(win, BusyPointer, 16, 16, -6, 0 );
824 else ClearPointer(win );
827 #endif
831 * Lock a window.
833 #ifdef __AROS__
834 makearosproto
835 AROS_LH1(APTR, BGUI_LockWindow,
836 AROS_LHA(struct Window *, win, A0),
837 struct Library *, BGUIBase, 9, BGUI)
838 #else
839 makeproto SAVEDS ASM APTR BGUI_LockWindow( REG(a0) struct Window *win )
840 #endif
842 AROS_LIBFUNC_INIT
844 WINDOWLOCK *wl;
847 * Allocate lock structure.
849 if (( wl = ( WINDOWLOCK * )BGUI_AllocPoolMem( sizeof( WINDOWLOCK )))) {
851 * Initialize structure.
853 wl->wl_Locked = win;
856 * Copy current min/max sizes.
858 *IBOX( &wl->wl_MinWidth ) = *IBOX( &win->MinWidth );
861 * Setup and open requester.
863 InitRequester( &wl->wl_IDCMPLock );
864 Request( &wl->wl_IDCMPLock, win );
867 * Set busy pointer.
869 Busy( win, TRUE );
872 * Disable sizing.
874 WindowLimits( win, win->Width, win->Height, win->Width, win->Height );
877 return( wl );
879 AROS_LIBFUNC_EXIT
883 * Unlock a window.
885 #ifdef __AROS__
886 makearosproto
887 AROS_LH1(VOID, BGUI_UnlockWindow,
888 AROS_LHA(APTR, lock, A0),
889 struct Library *, BGUIBase, 10, BGUI)
890 #else
891 makeproto SAVEDS ASM VOID BGUI_UnlockWindow( REG(a0) APTR lock )
892 #endif
894 AROS_LIBFUNC_INIT
896 WINDOWLOCK *wl = ( WINDOWLOCK * )lock;
899 * A NULL lock is safe.
901 if ( wl ) {
903 * Setup limits.
905 WindowLimits( wl->wl_Locked, wl->wl_MinWidth, wl->wl_MinHeight, wl->wl_MaxWidth, wl->wl_MaxHeight );
908 * End request.
910 EndRequest( &wl->wl_IDCMPLock, wl->wl_Locked );
913 * Clear busy pointer.
915 Busy( wl->wl_Locked, FALSE );
918 * Free lock.
920 BGUI_FreePoolMem( wl );
923 AROS_LIBFUNC_EXIT
926 #ifdef __AROS__
927 makearosproto
928 AROS_LH2(CONST_STRPTR, BGUI_GetLocaleStr,
929 AROS_LHA(struct bguiLocale *, bl, A0),
930 AROS_LHA(ULONG, id, D0),
931 struct Library *, BGUIBase, 20, BGUI)
932 #else
933 makeproto SAVEDS ASM STRPTR BGUI_GetLocaleStr( REG(a0) struct bguiLocale *bl, REG(d0) ULONG id )
934 #endif
936 AROS_LIBFUNC_INIT
938 CONST_STRPTR str = NULL;
940 struct bguiLocaleStr bls;
942 if (bl)
944 if (bl->bl_LocaleStrHook)
946 bls.bls_ID = id;
947 str = (STRPTR)BGUI_CallHookPkt(bl->bl_LocaleStrHook, (void *)bl, (void *)&bls);
949 else
951 if (LocaleBase) str = GetLocaleStr(bl->bl_Locale, id);
954 return str;
956 AROS_LIBFUNC_EXIT
959 #ifdef __AROS__
960 makearosproto
961 AROS_LH3(CONST_STRPTR, BGUI_GetCatalogStr,
962 AROS_LHA(struct bguiLocale *, bl, A0),
963 AROS_LHA(ULONG, id, D0),
964 AROS_LHA(CONST_STRPTR, str, A1),
965 struct Library *, BGUIBase, 21, BGUI)
966 #else
967 makeproto SAVEDS ASM CONST_STRPTR BGUI_GetCatalogStr( REG(a0) struct bguiLocale *bl, REG(d0) ULONG id, REG(a1) CONST_STRPTR str )
968 #endif
970 AROS_LIBFUNC_INIT
972 struct bguiCatalogStr bcs;
974 if (bl)
976 if (bl->bl_CatalogStrHook)
978 bcs.bcs_ID = id;
979 bcs.bcs_DefaultString = str;
980 str = (STRPTR)BGUI_CallHookPkt(bl->bl_CatalogStrHook, (void *)bl, (void *)&bcs);
982 else
984 if (LocaleBase) str = GetCatalogStr(bl->bl_Catalog, id, str);
987 return str;
989 AROS_LIBFUNC_EXIT
992 struct CallHookData
994 struct Hook *Hook;
995 APTR Object;
996 APTR Message;
999 static IPTR CallHookWithStack(struct CallHookData *call_hook_data)
1001 register APTR stack;
1002 register IPTR result;
1004 stack=EnsureStack();
1005 result=CallHookPkt(call_hook_data->Hook,call_hook_data->Object,call_hook_data->Message);
1006 RevertStack(stack);
1008 return(result);
1011 makeproto SAVEDS ASM IPTR BGUI_CallHookPkt(REG(a0) struct Hook *hook,REG(a2) APTR object,REG(a1) APTR message)
1013 struct CallHookData call_hook_data;
1015 call_hook_data.Hook=hook;
1016 call_hook_data.Object=object;
1017 call_hook_data.Message=message;
1018 return(CallHookWithStack(&call_hook_data));