Metatarget for copying of testfile fixed.
[AROS.git] / workbench / libs / muimaster / support.c
blob3a1e208423f991e1723edfb20f6ae97b4b35d0b1
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,
28 int height)
30 if ((left <= r->bounds.MinX) && (left + width - 1 >= r->bounds.MaxX)
31 && (top <= r->bounds.MinY) && (top + height - 1 >= r->bounds.MaxY))
32 return 1;
34 return 0;
38 /**************************************************************************
39 Converts a Rawkey to a vanillakey
40 **************************************************************************/
41 ULONG ConvertKey(struct IntuiMessage * imsg)
43 struct InputEvent event;
44 UBYTE code = 0;
45 event.ie_NextEvent = NULL;
46 event.ie_Class = IECLASS_RAWKEY;
47 event.ie_SubClass = 0;
48 event.ie_Code = imsg->Code;
49 event.ie_Qualifier = imsg->Qualifier;
50 event.ie_EventAddress = (APTR *) * ((IPTR *) imsg->IAddress);
51 MapRawKey(&event, &code, 1, NULL);
52 return code;
55 /**************************************************************************
56 Convenient way to get an attribute of an object easily. If the object
57 doesn't support the attribute this call returns an undefined value. So use
58 this call only if the attribute is known to be known by the object.
59 Implemented as a macro when compiling with GCC.
60 **************************************************************************/
61 #ifndef __GNUC__
62 IPTR XGET(Object * obj, Tag attr)
64 IPTR storage = 0;
65 GetAttr(attr, obj, &storage);
66 return storage;
68 #endif /* __GNUC__ */
70 /**************************************************************************
71 Call the Setup Method of an given object, but before set the renderinfo
72 **************************************************************************/
73 IPTR DoSetupMethod(Object * obj, struct MUI_RenderInfo * info)
75 /* MUI set the correct render info *before* it calls MUIM_Setup so please
76 * only use this function instead of DoMethodA() */
77 muiRenderInfo(obj) = info;
78 return DoMethod(obj, MUIM_Setup, (IPTR) info);
81 IPTR DoShowMethod(Object * obj)
83 IPTR ret;
85 ret = DoMethod(obj, MUIM_Show);
86 if (ret)
87 _flags(obj) |= MADF_CANDRAW;
88 return ret;
91 IPTR DoHideMethod(Object * obj)
93 _flags(obj) &= ~MADF_CANDRAW;
94 return DoMethod(obj, MUIM_Hide);
98 void *Node_Next(APTR node)
100 if (node == NULL)
101 return NULL;
102 if (((struct MinNode *)node)->mln_Succ == NULL)
103 return NULL;
104 if (((struct MinNode *)node)->mln_Succ->mln_Succ == NULL)
105 return NULL;
106 return ((struct MinNode *)node)->mln_Succ;
109 void *List_First(APTR list)
111 if (!((struct MinList *)list)->mlh_Head)
112 return NULL;
113 if (((struct MinList *)list)->mlh_Head->mln_Succ == NULL)
114 return NULL;
115 return ((struct MinList *)list)->mlh_Head;
118 /* subtract rectangle b from rectangle b. resulting rectangles will be put into
119 destrectarray which must have place for at least 4 rectangles. Returns number
120 of resulting rectangles */
122 WORD SubtractRectFromRect(struct Rectangle *a, struct Rectangle *b,
123 struct Rectangle *destrectarray)
125 struct Rectangle intersect;
126 BOOL intersecting = FALSE;
127 WORD numrects = 0;
129 /* calc. intersection between a and b */
131 if (a->MinX <= b->MaxX)
133 if (a->MinY <= b->MaxY)
135 if (a->MaxX >= b->MinX)
137 if (a->MaxY >= b->MinY)
139 intersect.MinX = MAX(a->MinX, b->MinX);
140 intersect.MinY = MAX(a->MinY, b->MinY);
141 intersect.MaxX = MIN(a->MaxX, b->MaxX);
142 intersect.MaxY = MIN(a->MaxY, b->MaxY);
144 intersecting = TRUE;
150 if (!intersecting)
152 destrectarray[numrects++] = *a;
154 } /* not intersecting */
155 else
157 if (intersect.MinY > a->MinY) /* upper */
159 destrectarray->MinX = a->MinX;
160 destrectarray->MinY = a->MinY;
161 destrectarray->MaxX = a->MaxX;
162 destrectarray->MaxY = intersect.MinY - 1;
164 numrects++;
165 destrectarray++;
168 if (intersect.MaxY < a->MaxY) /* lower */
170 destrectarray->MinX = a->MinX;
171 destrectarray->MinY = intersect.MaxY + 1;
172 destrectarray->MaxX = a->MaxX;
173 destrectarray->MaxY = a->MaxY;
175 numrects++;
176 destrectarray++;
179 if (intersect.MinX > a->MinX) /* left */
181 destrectarray->MinX = a->MinX;
182 destrectarray->MinY = intersect.MinY;
183 destrectarray->MaxX = intersect.MinX - 1;
184 destrectarray->MaxY = intersect.MaxY;
186 numrects++;
187 destrectarray++;
190 if (intersect.MaxX < a->MaxX) /* right */
192 destrectarray->MinX = intersect.MaxX + 1;
193 destrectarray->MinY = intersect.MinY;
194 destrectarray->MaxX = a->MaxX;
195 destrectarray->MaxY = intersect.MaxY;
197 numrects++;
198 destrectarray++;
201 } /* intersecting */
203 return numrects;
207 ULONG IsObjectVisible(Object * child, struct Library * MUIMasterBase)
209 Object *wnd;
210 Object *obj;
212 wnd = _win(child);
213 obj = child;
215 while (get(obj, MUIA_Parent, &obj))
217 if (!obj)
218 break;
219 if (obj == wnd)
220 break;
222 if (_right(child) < _mleft(obj) || _left(child) > _mright(obj)
223 || _bottom(child) < _mtop(obj) || _top(child) > _mbottom(obj))
224 return FALSE;
226 return TRUE;