Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / support.c
blob5108ce128a79a6a856377ffa78737445be1df032
1 /*
2 Copyright © 2002, The AROS Development Team.
3 All rights reserved.
5 $Id$
6 */
8 #include <string.h>
10 #include <intuition/classes.h>
11 #include <clib/alib_protos.h>
12 #include <proto/exec.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
15 #include <proto/keymap.h>
16 #include <proto/utility.h>
18 #include "mui.h"
19 #include "support.h"
20 #include "muimaster_intern.h"
22 extern struct Library *MUIMasterBase;
24 /**************************************************************************
25 check if region is entirely within given bounds
26 **************************************************************************/
27 int isRegionWithinBounds(struct Region *r, int left, int top, int width, int height)
29 if ((left <= r->bounds.MinX) && (left + width - 1 >= r->bounds.MaxX)
30 && (top <= r->bounds.MinY) && (top + height - 1 >= r->bounds.MaxY))
31 return 1;
33 return 0;
37 /**************************************************************************
38 Converts a Rawkey to a vanillakey
39 **************************************************************************/
40 ULONG ConvertKey(struct IntuiMessage *imsg)
42 struct InputEvent event;
43 UBYTE code = 0;
44 event.ie_NextEvent = NULL;
45 event.ie_Class = IECLASS_RAWKEY;
46 event.ie_SubClass = 0;
47 event.ie_Code = imsg->Code;
48 event.ie_Qualifier = imsg->Qualifier;
49 event.ie_EventAddress = (APTR *) *((ULONG *)imsg->IAddress);
50 MapRawKey(&event, &code, 1, NULL);
51 return code;
54 /**************************************************************************
55 Convient way to get an attribute of an object easily. If the object
56 doesn't support the attribute this call returns an undefined value. So use
57 this call only if the attribute is known to be known by the object.
58 Implemented as a macro when compiling with GCC.
59 **************************************************************************/
60 #ifndef __GNUC__
61 IPTR XGET(Object *obj, Tag attr)
63 IPTR storage = 0;
64 GetAttr(attr, obj, &storage);
65 return storage;
67 #endif /* __GNUC__ */
69 /**************************************************************************
70 Call the Setup Method of an given object, but before set the renderinfo
71 **************************************************************************/
72 IPTR DoSetupMethod(Object *obj, struct MUI_RenderInfo *info)
74 /* MUI set the correct render info *before* it calls MUIM_Setup so please only use this function instead of DoMethodA() */
75 muiRenderInfo(obj) = info;
76 return DoMethod(obj, MUIM_Setup, (IPTR)info);
79 IPTR DoShowMethod(Object *obj)
81 IPTR ret;
83 ret = DoMethod(obj, MUIM_Show);
84 if (ret)
85 _flags(obj) |= MADF_CANDRAW;
86 return ret;
89 IPTR DoHideMethod(Object *obj)
91 _flags(obj) &= ~MADF_CANDRAW;
92 return DoMethod(obj, MUIM_Hide);
96 void *Node_Next(APTR node)
98 if(node == NULL) return NULL;
99 if(((struct MinNode*)node)->mln_Succ == NULL) return NULL;
100 if(((struct MinNode*)node)->mln_Succ->mln_Succ == NULL)
101 return NULL;
102 return ((struct MinNode*)node)->mln_Succ;
105 void *List_First(APTR list)
107 if( !((struct MinList*)list)->mlh_Head) return NULL;
108 if(((struct MinList*)list)->mlh_Head->mln_Succ == NULL) return NULL;
109 return ((struct MinList*)list)->mlh_Head;
112 /* subtract rectangle b from rectangle b. resulting rectangles will be put into
113 destrectarray which must have place for at least 4 rectangles. Returns number
114 of resulting rectangles */
116 WORD SubtractRectFromRect(struct Rectangle *a, struct Rectangle *b, struct Rectangle *destrectarray)
118 struct Rectangle intersect;
119 BOOL intersecting = FALSE;
120 WORD numrects = 0;
122 /* calc. intersection between a and b */
124 if (a->MinX <= b->MaxX)
126 if (a->MinY <= b->MaxY)
128 if (a->MaxX >= b->MinX)
130 if (a->MaxY >= b->MinY)
132 intersect.MinX = MAX(a->MinX, b->MinX);
133 intersect.MinY = MAX(a->MinY, b->MinY);
134 intersect.MaxX = MIN(a->MaxX, b->MaxX);
135 intersect.MaxY = MIN(a->MaxY, b->MaxY);
137 intersecting = TRUE;
143 if (!intersecting)
145 destrectarray[numrects++] = *a;
147 } /* not intersecting */
148 else
150 if (intersect.MinY > a->MinY) /* upper */
152 destrectarray->MinX = a->MinX;
153 destrectarray->MinY = a->MinY;
154 destrectarray->MaxX = a->MaxX;
155 destrectarray->MaxY = intersect.MinY - 1;
157 numrects++;
158 destrectarray++;
161 if (intersect.MaxY < a->MaxY) /* lower */
163 destrectarray->MinX = a->MinX;
164 destrectarray->MinY = intersect.MaxY + 1;
165 destrectarray->MaxX = a->MaxX;
166 destrectarray->MaxY = a->MaxY;
168 numrects++;
169 destrectarray++;
172 if (intersect.MinX > a->MinX) /* left */
174 destrectarray->MinX = a->MinX;
175 destrectarray->MinY = intersect.MinY;
176 destrectarray->MaxX = intersect.MinX - 1;
177 destrectarray->MaxY = intersect.MaxY;
179 numrects++;
180 destrectarray++;
183 if (intersect.MaxX < a->MaxX) /* right */
185 destrectarray->MinX = intersect.MaxX + 1;
186 destrectarray->MinY = intersect.MinY;
187 destrectarray->MaxX = a->MaxX;
188 destrectarray->MaxY = intersect.MaxY;
190 numrects++;
191 destrectarray++;
194 } /* intersecting */
196 return numrects;
200 ULONG IsObjectVisible(Object *child, struct Library *MUIMasterBase)
202 Object *wnd;
203 Object *obj;
205 wnd = _win(child);
206 obj = child;
208 while (get(obj,MUIA_Parent, &obj))
210 if (!obj) break;
211 if (obj == wnd) break;
213 if (_right(child) < _mleft(obj) || _left(child) > _mright(obj)
214 || _bottom(child) < _mtop(obj) || _top(child) > _mbottom(obj))
215 return FALSE;
217 return TRUE;