revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / asl / gadgets.c
blob46f45b36475b4ad8c02a0fa8edfe418b0105b7eb
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/utility.h>
13 #include <proto/intuition.h>
14 #include <exec/memory.h>
15 #include <intuition/screens.h>
16 #include <intuition/icclass.h>
17 #include <intuition/cghooks.h>
18 #include <intuition/imageclass.h>
19 #include <intuition/gadgetclass.h>
20 #include <string.h>
22 #include "asl_intern.h"
23 #include "layout.h"
25 #define SDEBUG 0
26 #define DEBUG 0
28 #include <aros/debug.h>
30 /*******************************************************************************************/
32 #ifdef __MORPHOS__
34 * temporarily..until included in our includes
37 /********************************************************************************/
38 /* imageclass.h AROS extensions */
40 #ifndef SYSIA_WithBorder
41 #define SYSIA_WithBorder IA_FGPen /* default: TRUE */
42 #endif
44 #ifndef SYSIA_Style
45 #define SYSIA_Style IA_BGPen /* default: SYSISTYLE_NORMAL */
47 #define SYSISTYLE_NORMAL 0
48 #define SYSISTYLE_GADTOOLS 1 /* to get arrow images in gadtools look */
49 #endif
51 #endif
53 /*******************************************************************************************/
55 #define G(x) ((struct Gadget *)(x))
56 #define EG(x) ((struct ExtGadget *)(x))
58 /*******************************************************************************************/
60 static const struct TagItem arrowinc_to_prop [] =
62 {GA_ID , ASLSC_Inc },
63 {TAG_DONE }
66 static const struct TagItem arrowdec_to_prop [] =
68 {GA_ID , ASLSC_Dec },
69 {TAG_DONE }
72 static const struct TagItem prop_to_lv [] =
74 {PGA_Top , ASLLV_TopPixel},
75 {TAG_DONE }
78 static const struct TagItem lv_to_prop [] =
80 {ASLLV_TopPixel , PGA_Top },
81 {ASLLV_TotalPixels , PGA_Total },
82 {ASLLV_VisiblePixels, PGA_Visible },
83 {ASLLV_DeltaFactor , ASLSC_DeltaFactor },
84 {TAG_DONE }
88 /*******************************************************************************************/
90 BOOL makescrollergadget(struct ScrollerGadget *scrollergad, struct LayoutData *ld,
91 struct TagItem *tags, struct AslBase_intern *AslBase)
93 struct TagItem extraproptags[] =
95 {PGA_NotifyBehaviour, PG_BEHAVIOUR_NICE},
96 {PGA_RenderBehaviour, PG_BEHAVIOUR_NICE},
97 {TAG_MORE , 0 }
100 struct TagItem *ti, *h_ti, *w_ti;
101 WORD x = 0, y = 0, w = 0, h = 0, aw, ah;
102 UWORD flags = 0;
103 BOOL freehoriz = (GetTagData(PGA_Freedom, FREEVERT, tags) == FREEHORIZ);
104 BOOL result = FALSE;
106 if ((ti = FindTagItem(GA_Left, tags)))
108 x = ti->ti_Data;
109 } else if ((ti = FindTagItem(GA_RelRight, tags)))
111 x = ti->ti_Data; flags |= GFLG_RELRIGHT;
114 if ((ti = FindTagItem(GA_Top, tags)))
116 y = ti->ti_Data;
117 } else if ((ti = FindTagItem(GA_RelBottom, tags)))
119 y = ti->ti_Data; flags |= GFLG_RELBOTTOM;
122 if ((w_ti = FindTagItem(GA_Width, tags)))
124 w = w_ti->ti_Data;
125 } else if ((w_ti = FindTagItem(GA_RelWidth, tags)))
127 w = w_ti->ti_Data; flags |= GFLG_RELWIDTH;
130 if ((h_ti = FindTagItem(GA_Height, tags)))
132 h = h_ti->ti_Data;
133 } else if ((h_ti = FindTagItem(GA_RelHeight, tags)))
135 h = h_ti->ti_Data; flags |= GFLG_RELHEIGHT;
138 if (freehoriz)
140 aw = h; ah = h;
141 w -= aw * 2;
142 if (w_ti) w_ti->ti_Data = w;
143 } else {
144 aw = w; ah = w;
145 h -= ah * 2;
146 if (h_ti) h_ti->ti_Data = h;
149 extraproptags[2].ti_Data = (IPTR)tags;
150 if ((scrollergad->prop = NewObjectA(AslBase->aslpropclass, NULL, extraproptags)))
152 struct TagItem arrow_tags[] =
154 {GA_Left , freehoriz ? x + w - 1 : x },
155 {GA_Top , freehoriz ? y : y + h - 1 },
156 {GA_Width , aw },
157 {GA_Height , ah },
158 {GA_RelVerify , TRUE },
159 {GA_Immediate , TRUE },
160 {GA_Previous , (IPTR)scrollergad->prop },
161 {GA_ID , ID_ARROWDEC },
162 {TAG_DONE }
165 if (flags & GFLG_RELRIGHT) arrow_tags[0].ti_Tag = GA_RelRight;
166 if (flags & GFLG_RELWIDTH)
168 arrow_tags[0].ti_Tag = GA_RelRight;
169 if (freehoriz) arrow_tags[0].ti_Data += 2;
172 if (flags & GFLG_RELBOTTOM) arrow_tags[1].ti_Tag = GA_RelBottom;
173 if (flags & GFLG_RELHEIGHT)
175 arrow_tags[1].ti_Tag = GA_RelBottom;
176 if (!freehoriz) arrow_tags[1].ti_Data += 2;
179 if ((scrollergad->arrow1 = NewObjectA(AslBase->aslarrowclass, NULL, arrow_tags)))
181 if (freehoriz)
183 arrow_tags[0].ti_Data += aw;
184 } else {
185 arrow_tags[1].ti_Data += ah;
187 arrow_tags[6].ti_Data = (IPTR)scrollergad->arrow1;
188 arrow_tags[7].ti_Data = ID_ARROWINC;
190 if ((scrollergad->arrow2 = NewObjectA(AslBase->aslarrowclass, NULL, arrow_tags)))
192 struct TagItem image_tags[] =
194 {SYSIA_Which , freehoriz ? LEFTIMAGE : UPIMAGE },
195 {SYSIA_DrawInfo , (IPTR)ld->ld_Dri },
196 {SYSIA_Style , SYSISTYLE_GADTOOLS },
197 {IA_Width , aw },
198 {IA_Height , ah },
199 {TAG_DONE }
201 struct Image *im;
203 if ((im = NewObjectA(NULL, SYSICLASS, image_tags)))
205 SetAttrs(scrollergad->arrow1, GA_Image, (IPTR)im,
206 TAG_DONE);
208 image_tags[0].ti_Data = (freehoriz ? RIGHTIMAGE : DOWNIMAGE);
210 if ((im = NewObjectA(NULL, SYSICLASS, image_tags)))
212 #if USE_SAFE_NOTIFYING
213 struct TagItem ic_tags [] =
215 {ICA_MAP , (IPTR) prop_to_lv },
216 {TAG_DONE }
219 if ((scrollergad->prop_ic = NewObjectA(NULL, ICCLASS, ic_tags)))
221 ic_tags[0].ti_Data = (IPTR)lv_to_prop;
223 if ((scrollergad->listview_ic = NewObjectA(NULL, ICCLASS, ic_tags)))
225 #endif
226 struct TagItem set_tags [] =
228 {ICA_TARGET , (IPTR) scrollergad->prop },
229 {ICA_MAP , (IPTR) arrowdec_to_prop },
230 {TAG_DONE }
233 SetAttrs(scrollergad->arrow2, GA_Image, (IPTR)im,
234 TAG_DONE);
236 SetAttrsA(scrollergad->arrow1, set_tags);
237 set_tags[1].ti_Data = (IPTR)arrowinc_to_prop;
238 SetAttrsA(scrollergad->arrow2, set_tags);
240 result = TRUE;
242 #if USE_SAFE_NOTIFYING
244 } /* if ((scrollergad->listview_ic = NewObjectA(NULL, ICCLASS, ic_tags))) */
246 } /* if ((scrollergad->prop_ic = NewObjectA(NULL, ICCLASS, ic_tags))) */
248 #endif
250 } /* if ((im = NewObjectA(NULL, SYSICLASS, image_tags))) */
252 } /* if ((im = NewObject(NULL, SYSICLASS, image_tags))) */
254 } /* if ((scrollergad->arrow2 = NewObjectA(NULL, BUTTONGCLASS, arrow_tags))) */
256 } /* if (scrollergad->arrow1 = NewObjectA(NULL, BUTTONGCLASS, arrow_tags)) */
258 } /* if ((scrollergad->prop = NewObjectA(AslBase->aslpropclass, NULL, tags))) */
260 if (!result) killscrollergadget(scrollergad, AslBase);
262 return result;
265 /*******************************************************************************************/
267 void killscrollergadget(struct ScrollerGadget *scrollergad, struct AslBase_intern *AslBase)
269 if (scrollergad->prop) DisposeObject(scrollergad->prop);
270 scrollergad->prop = NULL;
272 if (scrollergad->arrow1)
274 if (G(scrollergad->arrow1)->GadgetRender) DisposeObject(G(scrollergad->arrow1)->GadgetRender);
275 DisposeObject(scrollergad->arrow1);
277 scrollergad->arrow1 = NULL;
279 if (scrollergad->arrow2)
281 if (G(scrollergad->arrow2)->GadgetRender) DisposeObject(G(scrollergad->arrow2)->GadgetRender);
282 DisposeObject(scrollergad->arrow2);
284 scrollergad->arrow2 = NULL;
286 #if USE_SAFE_NOTIFYING
287 if (scrollergad->prop_ic) DisposeObject(scrollergad->prop_ic);
288 scrollergad->prop_ic = NULL;
290 if (scrollergad->listview_ic) DisposeObject(scrollergad->listview_ic);
291 scrollergad->listview_ic = NULL;
292 #endif
295 /*******************************************************************************************/
297 void getgadgetcoords(struct Gadget *gad, struct GadgetInfo *gi, WORD *x, WORD *y, WORD *w, WORD *h)
299 *x = gad->LeftEdge + ((gad->Flags & GFLG_RELRIGHT) ? gi->gi_Domain.Width - 1 : 0);
300 *y = gad->TopEdge + ((gad->Flags & GFLG_RELBOTTOM) ? gi->gi_Domain.Height - 1 : 0);
301 *w = gad->Width + ((gad->Flags & GFLG_RELWIDTH) ? gi->gi_Domain.Width : 0);
302 *h = gad->Height + ((gad->Flags & GFLG_RELHEIGHT) ? gi->gi_Domain.Height : 0);
305 /*******************************************************************************************/
307 void getgadgetbounds(struct Gadget *gad, struct GadgetInfo *gi, WORD *x, WORD *y, WORD *w, WORD *h)
309 if (!(gad->Flags & GFLG_EXTENDED) ||
310 !(EG(gad)->MoreFlags & GMORE_BOUNDS))
312 return getgadgetcoords(gad, gi, x, y, w, h);
315 *x = EG(gad)->BoundsLeftEdge + ((gad->Flags & GFLG_RELRIGHT) ? gi->gi_Domain.Width - 1 : 0);
316 *y = EG(gad)->BoundsTopEdge + ((gad->Flags & GFLG_RELBOTTOM) ? gi->gi_Domain.Height - 1 : 0);
317 *w = EG(gad)->BoundsWidth + ((gad->Flags & GFLG_RELWIDTH) ? gi->gi_Domain.Width : 0);
318 *h = EG(gad)->BoundsHeight + ((gad->Flags & GFLG_RELHEIGHT) ? gi->gi_Domain.Height : 0);
321 /*******************************************************************************************/
323 void connectscrollerandlistview(struct ScrollerGadget *scrollergad, Object *listview,
324 struct AslBase_intern *AslBase)
326 #if USE_SAFE_NOTIFYING
328 struct TagItem ic_tags[] =
330 {ICA_TARGET , (IPTR)listview },
331 {TAG_DONE }
334 /* ICA_TARGET of prop ic is listview gadget */
335 SetAttrsA(scrollergad->prop_ic, ic_tags);
337 /* ICA_TARGET of listview ic is prop gadget */
338 ic_tags[0].ti_Data = (IPTR)scrollergad->prop;
339 SetAttrsA(scrollergad->listview_ic, ic_tags);
341 /* ICA_TARGET of listview gadget is listview ic */
342 ic_tags[0].ti_Data = (IPTR)scrollergad->listview_ic;
343 SetAttrsA(listview, ic_tags);
345 /* ICA_TARGET of prop gadget is prop ic */
346 ic_tags[0].ti_Data = (IPTR)scrollergad->prop_ic;
347 SetAttrsA(scrollergad->prop, ic_tags);
349 #else
351 struct TagItem ic_tags[] =
353 {ICA_TARGET , (IPTR)listview },
354 {ICA_MAP , (IPTR)prop_to_lv },
355 {TAG_DONE }
358 #warning This would not work in AmigaOS, because there gadgetclass is really lame and does not check for notifying loops
360 SetAttrsA(scrollergad->prop, ic_tags);
362 ic_tags[0].ti_Data = (IPTR)scrollergad->prop;
363 ic_tags[1].ti_Data = (IPTR)lv_to_prop;
365 SetAttrsA(listview, ic_tags);
367 #endif
370 /*******************************************************************************************/
372 void FreeObjects(Object **first, Object **last, struct AslBase_intern *AslBase)
374 Object **objptr;
376 for(objptr = first; objptr != last + 1; objptr++)
378 if (*objptr)
380 DisposeObject(*objptr);
381 *objptr = NULL;
386 /*******************************************************************************************/