include/muimaster/macros.h: get() compiler delint
[AROS.git] / workbench / libs / gadtools / scrollerclass.c
blobeb8aa03337b7e3c789c39f7f819fc351055c590a
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Internal GadTools scroller class.
6 Lang: English
7 */
10 #include <proto/exec.h>
11 #include <exec/libraries.h>
12 #include <exec/memory.h>
13 #include <proto/dos.h>
14 #include <intuition/classes.h>
15 #include <intuition/classusr.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/imageclass.h>
18 #include <intuition/intuition.h>
19 #include <intuition/cghooks.h>
20 #include <graphics/rastport.h>
21 #include <graphics/text.h>
22 #include <utility/tagitem.h>
23 #include <devices/inputevent.h>
24 #include <proto/alib.h>
25 #include <proto/utility.h>
27 #include <string.h> /* memset() */
29 #define SDEBUG 0
30 #define DEBUG 0
31 #include <aros/debug.h>
33 #include "gadtools_intern.h"
35 /**********************************************************************************************/
37 #define GadToolsBase ((struct GadToolsBase_intern *)cl->cl_UserData)
39 /**********************************************************************************************/
41 STATIC IPTR scroller_set(Class * cl, Object * o, struct opSet * msg)
43 IPTR retval = 0UL;
44 struct TagItem *tag, tags[] =
46 {PGA_Total , 0 },
47 {PGA_Top , 0 },
48 {PGA_Visible , 0 },
49 {TAG_MORE }
51 struct TagItem *tstate = msg->ops_AttrList;
53 struct ScrollerData *data = INST_DATA(cl, o);
55 D(bug("scroller_set(cl 0x%lx o 0x%lx msg 0x%lx)\n",cl,o,msg));
57 tags[3].ti_Data = (IPTR)msg->ops_AttrList;
59 /* Get old values */
60 DoSuperMethod(cl, o, OM_GET, PGA_Total, (IPTR) &(tags[0].ti_Data));
61 DoSuperMethod(cl, o, OM_GET, PGA_Top, (IPTR) &(tags[1].ti_Data));
62 DoSuperMethod(cl, o, OM_GET, PGA_Visible, (IPTR) &(tags[2].ti_Data));
64 D(bug("scroller_set: Old Total %ld Top %ld Visible %ld\n",
65 tags[0].ti_Data,
66 tags[1].ti_Data,
67 tags[2].ti_Data));
70 while ((tag = NextTagItem(&tstate)))
73 switch (tag->ti_Tag)
75 case GTA_GadgetKind:
76 data->gadgetkind = tag->ti_Data;
77 break;
79 case GTSC_Total:
80 D(bug("scroller_set: GTSC_Total %ld\n",tag->ti_Data));
81 tags[0].ti_Data = tag->ti_Data;
82 break;
84 case GTSC_Top:
85 D(bug("scroller_set: GTSC_Top %ld\n",tag->ti_Data));
86 tags[1].ti_Data = tag->ti_Data;
87 break;
89 case GTSC_Visible:
90 D(bug("scroller_set: GTSC_Visible %ld\n",tag->ti_Data));
91 tags[2].ti_Data = tag->ti_Data;
92 break;
94 case GTA_Scroller_Dec:
95 if (tags[1].ti_Data > 0)
97 tags[1].ti_Data --;
98 retval = 1UL;
100 break;
102 case GTA_Scroller_Inc:
103 /* Top < (Total - Visible) ? */
104 if (tags[1].ti_Data < (tags[0].ti_Data - tags[2].ti_Data))
106 tags[1].ti_Data ++;
107 retval = 1UL;
109 break;
111 case GTA_Scroller_Arrow1:
112 data->arrow1 = (struct Gadget *)tag->ti_Data;
113 break;
115 case GTA_Scroller_Arrow2:
116 data->arrow2 = (struct Gadget *)tag->ti_Data;
117 break;
119 case GA_Disabled:
121 struct TagItem set_tags[] =
123 {GA_Disabled , tag->ti_Data },
124 {TAG_DONE }
127 if (data->arrow1)
129 if (msg->ops_GInfo)
131 SetGadgetAttrsA(data->arrow1, msg->ops_GInfo->gi_Window, 0, set_tags);
132 } else {
133 SetAttrsA((Object *)data->arrow1, set_tags);
137 if (data->arrow2)
139 if (msg->ops_GInfo)
141 SetGadgetAttrsA(data->arrow2, msg->ops_GInfo->gi_Window, 0, set_tags);
142 } else {
143 SetAttrsA((Object *)data->arrow2, set_tags);
147 break;
149 } /* switch (tag->ti_Tag) */
151 } /* while ((tag = NextTagItem(&tstate))) */
153 DoSuperMethod(cl, o, OM_SET, (IPTR) tags, (IPTR) msg->ops_GInfo);
155 return (retval);
158 /**********************************************************************************************/
160 IPTR GTScroller__OM_GET(Class * cl, Object * o, struct opGet *msg)
162 struct ScrollerData *data = INST_DATA(cl, o);
163 struct opGet cloned_msg = *msg;
164 IPTR retval = 1UL;
166 switch (msg->opg_AttrID)
168 case GTA_GadgetKind:
169 *msg->opg_Storage = data->gadgetkind;
170 break;
172 case GTA_ChildGadgetKind:
173 *msg->opg_Storage = SCROLLER_KIND;
174 break;
176 case GTSC_Top:
177 cloned_msg.opg_AttrID = PGA_Top;
178 retval = DoSuperMethodA(cl, o, (Msg)&cloned_msg);
179 break;
181 case GTSC_Total:
182 cloned_msg.opg_AttrID = PGA_Total;
183 retval = DoSuperMethodA(cl, o, (Msg)&cloned_msg);
184 break;
186 case GTSC_Visible:
187 cloned_msg.opg_AttrID = PGA_Visible;
188 retval = DoSuperMethodA(cl, o, (Msg)&cloned_msg);
189 break;
191 default:
192 retval = DoSuperMethodA(cl, o, (Msg)msg);
193 break;
196 return retval;
199 /**********************************************************************************************/
201 IPTR GTScroller__OM_NEW(Class * cl, Object * o, struct opSet *msg)
203 struct ScrollerData *data;
204 struct DrawInfo *dri;
205 struct TagItem fitags[] =
207 {IA_Width , 0UL },
208 {IA_Height , 0UL },
209 {IA_Resolution , 0UL },
210 {IA_FrameType , FRAME_BUTTON },
211 {IA_EdgesOnly , TRUE },
212 {TAG_DONE }
215 EnterFunc(bug("Scroller::New()\n"));
217 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
218 if (o)
220 data = INST_DATA(cl, o);
222 dri = (struct DrawInfo *)GetTagData(GA_DrawInfo, 0, msg->ops_AttrList);
224 fitags[0].ti_Data = GetTagData(GA_Width, 0, msg->ops_AttrList) + BORDERPROPSPACINGX * 2;
225 fitags[1].ti_Data = GetTagData(GA_Height, 0, msg->ops_AttrList) + BORDERPROPSPACINGY * 2;
226 fitags[2].ti_Data = (dri->dri_Resolution.X << 16) + dri->dri_Resolution.Y;
228 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
229 if (data->frame)
231 scroller_set(cl, o, msg);
232 data->labelplace = GetTagData(GA_LabelPlace, GV_LabelPlace_Left, ((struct opSet *)msg)->ops_AttrList);
233 } else {
234 CoerceMethod(cl, o, OM_DISPOSE);
235 o = NULL;
238 ReturnPtr("Scroller::New", IPTR, (IPTR)o);
242 /**********************************************************************************************/
244 IPTR GTScroller__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
246 struct ScrollerData *data;
247 IPTR retval;
249 data = INST_DATA(cl, g);
251 if (msg->gpr_Redraw == GREDRAW_REDRAW)
253 DrawImageState(msg->gpr_RPort,
254 (struct Image *)data->frame,
255 g->LeftEdge - BORDERPROPSPACINGX,
256 g->TopEdge - BORDERPROPSPACINGY,
257 IDS_NORMAL,
258 msg->gpr_GInfo->gi_DrInfo);
260 renderlabel(GadToolsBase, g, msg->gpr_RPort, data->labelplace);
263 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
265 ReturnInt("Scroller::Render", IPTR, retval);
268 /**********************************************************************************************/
270 IPTR GTScroller__OM_DISPOSE(Class *cl, Object *o, Msg msg)
272 struct ScrollerData *data = INST_DATA(cl, o);
274 if (data->frame) DisposeObject(data->frame);
276 return DoSuperMethodA(cl, o, msg);
279 /**********************************************************************************************/
281 IPTR GTScroller__OM_SET(Class *cl, Object *o, struct opSet *msg)
283 IPTR retval = scroller_set(cl, o, msg);
285 /* If we have been subclassed, OM_UPDATE should not cause a GM_RENDER
286 * because it would circumvent the subclass from fully overriding it.
287 * The check of cl == OCLASS(o) should fail if we have been
288 * subclassed, and we have gotten here via DoSuperMethodA().
290 if ( retval && ( (msg->MethodID != OM_UPDATE) || (cl == OCLASS(o)) ) )
292 struct GadgetInfo *gi = msg->ops_GInfo;
293 if (gi)
295 struct RastPort *rp = ObtainGIRPort(gi);
296 if (rp)
298 DoMethod(o, GM_RENDER, (IPTR) gi, (IPTR) rp, GREDRAW_REDRAW);
299 ReleaseGIRPort(rp);
300 } /* if */
301 } /* if */
302 } /* if */
304 return retval;
307 /**********************************************************************************************/