4 ** Copyright (C) 1999 Bernardo Innocenti
5 ** All rights reserved.
7 ** Use 4 chars wide TABs to read this file
9 ** GetGadgetBox() computes the actual IBox where a gadget exists in a window.
10 ** The special cases it handles are all the REL#? (relative positioning flags).
12 ** This function returns the gadget size in the provided
13 ** IBox structure, computing the values from the coordinates
14 ** in the gadget structure and the container (window or requester)
18 #include <intuition/intuition.h>
20 #include <CompilerSpecific.h>
21 #include <DebugMacros.h>
22 #include <BoopsiLib.h>
25 void GetGadgetBox(struct GadgetInfo *ginfo, struct ExtGadget *g, struct IBox *box)
28 ASSERT_VALID_PTR(ginfo)
31 DB2(if (g->Flags & GFLG_EXTENDED)
32 DBPRINTF("GetGadgetBox(): GFLG_EXTENDED is set\n");)
33 DB2(if ((g->Flags & GFLG_EXTENDED) && (g->MoreFlags & GMORE_BOUNDS))
34 DBPRINTF("GetGadgetBox(): Gadget has valid bounds\n");)
37 box->Left = g->LeftEdge;
38 if (g->Flags & GFLG_RELRIGHT)
39 box->Left += ginfo->gi_Domain.Width - 1;
41 box->Top = g->TopEdge;
42 if (g->Flags & GFLG_RELBOTTOM)
43 box->Top += ginfo->gi_Domain.Height - 1;
45 box->Width = g->Width;
46 if (g->Flags & GFLG_RELWIDTH)
47 box->Width += ginfo->gi_Domain.Width;
49 box->Height = g->Height;
50 if (g->Flags & GFLG_RELHEIGHT)
51 box->Height += ginfo->gi_Domain.Height;
53 DB2(DBPRINTF("GetGadgetBox(): Left = %ld, Top = %ld, Width = %ld, Height = %ld\n",
54 box->Left, box->Top, box->Width, box->Height);)
59 /* Useful macro missing in <intuition/imageclass.h> */
60 #define GADGET_BOUNDS(g) ((struct IBox *)&((struct ExtGadget *)(g))->BoundsLeftEdge)
63 void GetGadgetBounds(struct GadgetInfo *ginfo, struct ExtGadget *g, struct IBox *bounds)
68 ASSERT_VALID_PTR(ginfo)
69 ASSERT_VALID_PTR(bounds)
72 box = ((g->Flags & GFLG_EXTENDED) && (g->MoreFlags & GMORE_BOUNDS)) ?
73 GADGET_BOUNDS(g) : GADGET_BOX(g);
75 memcpy(bounds, box, sizeof(struct IBox));
77 if (g->Flags & GFLG_RELRIGHT)
78 bounds->Left += ginfo->gi_Domain.Width - 1;
80 if (g->Flags & GFLG_RELBOTTOM)
81 bounds->Top += ginfo->gi_Domain.Height - 1;
83 if (g->Flags & GFLG_RELWIDTH)
84 bounds->Width += ginfo->gi_Domain.Width;
86 if (g->Flags & GFLG_RELHEIGHT)
87 bounds->Height += ginfo->gi_Domain.Height;