Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / asl / propclass.c
blob89f57be8af75723509496290a96edec61179765f
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <proto/utility.h>
9 #include <proto/intuition.h>
10 #include <proto/graphics.h>
11 #include <proto/cybergraphics.h>
12 #include <exec/memory.h>
13 #include <intuition/screens.h>
14 #include <intuition/icclass.h>
15 #include <intuition/cghooks.h>
16 #include <intuition/imageclass.h>
17 #include <intuition/gadgetclass.h>
18 #include <graphics/gfx.h>
19 #include <cybergraphx/cybergraphics.h>
21 #include <string.h>
23 #include "asl_intern.h"
24 #include "layout.h"
26 #define SDEBUG 0
27 #define DEBUG 0
29 #include <aros/debug.h>
31 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
32 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
34 #define AslBase CLASS_ASLBASE
36 /********************** ASL PROP CLASS **************************************************/
38 IPTR AslProp__OM_NEW(Class * cl, Object * o, struct opSet * msg)
40 struct AslPropData *data;
41 struct TagItem fitags[] =
43 {IA_FrameType, FRAME_BUTTON},
44 {IA_EdgesOnly, TRUE },
45 {TAG_DONE, 0UL}
48 struct ExtGadget *eg = (struct ExtGadget *)DoSuperMethodA(cl, o, (Msg)msg);
49 if (eg)
51 data = INST_DATA(cl, eg);
53 eg->BoundsLeftEdge = eg->LeftEdge;
54 eg->BoundsTopEdge = eg->TopEdge;
55 eg->BoundsWidth = eg->Width;
56 eg->BoundsHeight = eg->Height;
57 eg->MoreFlags |= GMORE_BOUNDS;
59 eg->LeftEdge += BORDERPROPSPACINGX;
60 eg->TopEdge += BORDERPROPSPACINGY;
61 eg->Width -= BORDERPROPSPACINGX * 2;
62 eg->Height -= BORDERPROPSPACINGY * 2;
64 data->deltafactor = 1;
65 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
66 if (!data->frame)
68 CoerceMethod(cl, (Object *)eg, OM_DISPOSE);
69 eg = NULL;
73 return (IPTR)eg;
76 /***********************************************************************************/
78 IPTR AslProp__OM_DISPOSE(Class * cl, Object * o, Msg msg)
80 struct AslPropData *data;
81 IPTR retval;
83 data = INST_DATA(cl, o);
84 if (data->frame) DisposeObject(data->frame);
86 retval = DoSuperMethodA(cl, o, msg);
88 return retval;
91 /***********************************************************************************/
93 IPTR AslProp__OM_SET(Class * cl, Object * o, struct opSet * msg)
95 struct AslPropData *data;
96 const struct TagItem *tstate = msg->ops_AttrList;
97 struct TagItem *ti;
98 IPTR retval;
99 BOOL rerender = FALSE;
101 data = INST_DATA(cl, o);
103 while((ti = NextTagItem(&tstate)))
105 switch(ti->ti_Tag)
107 case ASLSC_DeltaFactor:
108 data->deltafactor = (LONG)ti->ti_Data;
109 break;
111 case ASLSC_Inc:
112 case ASLSC_Dec:
113 if (((LONG)ti->ti_Data > 0) &&
114 (((struct opUpdate *)msg)->opu_Flags & OPUF_INTERIM))
116 IPTR top, total, visible, newtop;
118 GetAttr(PGA_Top, o, &top);
119 GetAttr(PGA_Total, o, &total);
120 GetAttr(PGA_Visible, o, &visible);
122 newtop = top;
123 if (ti->ti_Data == ID_ARROWDEC)
125 if (newtop < data->deltafactor)
127 newtop = 0;
129 else
131 newtop -= data->deltafactor;
135 else
137 if (top <= total - visible - data->deltafactor)
139 newtop += data->deltafactor;
141 else
143 newtop = total - visible;
147 if (newtop != top)
149 struct TagItem set_tags [] =
151 {PGA_Top, newtop },
152 {TAG_DONE }
154 struct opSet ops;
156 ops.MethodID = OM_SET;
157 ops.ops_AttrList = set_tags;
158 ops.ops_GInfo = msg->ops_GInfo;
160 DoMethodA(o, (Msg)&ops);
162 /* rerender = TRUE; */
165 } /* if ((ti->ti_Data > 0) && (((struct opUpdate *)msg)->opu_Flags & OPUF_INTERIM)) */
167 } /* switch(ti->ti_Tag) */
169 } /* while((ti = NextTagItem(&tstate))) */
171 retval = DoSuperMethodA(cl, o, (Msg) msg);
173 if (rerender)
175 struct RastPort *rp;
177 rp = ObtainGIRPort(msg->ops_GInfo);
178 if (NULL != rp)
180 DoMethod(o, GM_RENDER, (IPTR) msg->ops_GInfo, (IPTR) rp, GREDRAW_UPDATE);
181 ReleaseGIRPort(rp);
185 return retval;
188 /***********************************************************************************/
190 IPTR AslProp__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
192 struct AslPropData *data;
193 IPTR retval;
195 data = INST_DATA(cl, g);
197 if (msg->gpr_Redraw == GREDRAW_REDRAW)
199 struct TagItem im_tags[] =
201 {IA_Width , 0 },
202 {IA_Height , 0 },
203 {TAG_DONE }
205 WORD x, y, w, h;
207 getgadgetcoords(g, msg->gpr_GInfo, &x, &y, &w, &h);
209 x -= BORDERPROPSPACINGX;
210 y -= BORDERPROPSPACINGY;
211 w += BORDERPROPSPACINGX * 2;
212 h += BORDERPROPSPACINGY * 2;
214 im_tags[0].ti_Data = w;
215 im_tags[1].ti_Data = h;
217 SetAttrsA(data->frame, im_tags);
219 DrawImageState(msg->gpr_RPort,
220 (struct Image *)data->frame,
223 IDS_NORMAL,
224 msg->gpr_GInfo->gi_DrInfo);
226 #if AVOID_FLICKER
228 struct IBox ibox, fbox;
230 fbox.Left = x;
231 fbox.Top = y;
232 fbox.Width = w;
233 fbox.Height = h;
235 ibox.Left = x + BORDERPROPSPACINGX;
236 ibox.Top = y + BORDERPROPSPACINGY;
237 ibox.Width = w - BORDERPROPSPACINGX * 2;
238 ibox.Height = h - BORDERPROPSPACINGY * 2;
240 PaintInnerFrame(msg->gpr_RPort,
241 msg->gpr_GInfo->gi_DrInfo,
242 data->frame,
243 &fbox,
244 &ibox,
245 msg->gpr_GInfo->gi_DrInfo->dri_Pens[BACKGROUNDPEN],
246 AslBase);
249 #endif
251 } /* if (msg->gpr_Redraw == GREDRAW_REDRAW) */
253 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
255 return retval;
258 /***********************************************************************************/