Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / gadtools / sliderclass.c
bloba2a6c9cfd5a766363b76325cbdeb18e415aaaf83
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Internal GadTools slider class.
6 */
9 #include <proto/exec.h>
10 #include <exec/libraries.h>
11 #include <exec/memory.h>
12 #include <proto/dos.h>
13 #include <intuition/classes.h>
14 #include <intuition/classusr.h>
15 #include <intuition/gadgetclass.h>
16 #include <intuition/imageclass.h>
17 #include <intuition/intuition.h>
18 #include <intuition/cghooks.h>
19 #include <graphics/rastport.h>
20 #include <graphics/text.h>
21 #include <utility/tagitem.h>
22 #include <devices/inputevent.h>
23 #include <proto/alib.h>
24 #include <proto/utility.h>
26 #include <string.h> /* memset() */
28 #define SDEBUG 0
29 #define DEBUG 0
30 #include <aros/debug.h>
32 #include "gadtools_intern.h"
34 /**********************************************************************************************/
36 #undef GadToolsBase
38 STATIC VOID notifylevel(Class *cl, Object *o, WORD level, struct GadgetInfo *ginfo,
39 struct GadToolsBase_intern *GadToolsBase)
42 struct TagItem ntags[] =
44 {GTSL_Level , (IPTR)NULL },
45 {TAG_DONE }
48 ntags[0].ti_Data = (IPTR)level;
49 DoSuperMethod(cl, o, OM_NOTIFY, (IPTR) ntags, (IPTR) ginfo, 0);
51 return;
54 #define GadToolsBase ((struct GadToolsBase_intern *)(cl->cl_UserData))
56 /**********************************************************************************************/
58 IPTR GTSlider__OM_SET(Class * cl, Object * o, struct opSet * msg)
60 IPTR retval = 0UL;
61 const struct TagItem *tstate;
62 struct TagItem *tag, *dosuper_tags, tags[] =
64 {PGA_Total , 0 },
65 {PGA_Top , 0 },
66 {TAG_MORE , 0 }
68 struct SliderData *data = INST_DATA(cl, o);
70 BOOL val_set = FALSE;
72 EnterFunc(bug("Slider::Set(attrlist=%p)\n", msg->ops_AttrList));
73 dosuper_tags = msg->ops_AttrList;
75 tstate = msg->ops_AttrList;
76 while ((tag = NextTagItem(&tstate)))
78 IPTR tidata = tag->ti_Data;
80 switch (tag->ti_Tag)
82 case GTSL_Min:
83 data->min = (WORD)tidata;
84 val_set = TRUE;
85 break;
87 case GTSL_Max:
88 data->max = (WORD)tidata;
89 val_set = TRUE;
90 break;
92 case GTSL_Level: /* [ISN] */
93 if (tidata != data->level)
95 data->level = data->freedom==FREEHORIZ?(WORD)tidata:data->max-(WORD)tidata+data->min;
96 notifylevel(cl, o, data->level, msg->ops_GInfo, GadToolsBase);
97 val_set = TRUE;
100 break;
102 } /* switch () */
104 } /* while (iterate taglist) */
106 if (val_set)
108 tags[0].ti_Data = data->max - data->min + 1;
109 tags[1].ti_Data = data->level - data->min;
110 tags[2].ti_Data = (IPTR)msg->ops_AttrList;
112 dosuper_tags = tags;
114 retval = 1UL;
117 ReturnInt ("Slider::Set", IPTR, DoSuperMethod(cl, o, OM_SET, (IPTR) dosuper_tags, (IPTR) msg->ops_GInfo));
120 /**********************************************************************************************/
122 IPTR GTSlider__OM_NEW(Class * cl, Object * o, struct opSet *msg)
124 struct DrawInfo *dri;
126 struct TagItem fitags[] =
128 {IA_Width , 0UL },
129 {IA_Height , 0UL },
130 {IA_Resolution , 0UL },
131 {IA_FrameType , FRAME_BUTTON },
132 {IA_EdgesOnly , TRUE },
133 {TAG_DONE }
136 EnterFunc(bug("Slider::New()\n"));
138 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
139 if (o)
141 struct SliderData *data = INST_DATA(cl, o);
143 dri = (struct DrawInfo *)GetTagData(GA_DrawInfo, (IPTR) NULL, msg->ops_AttrList);
145 fitags[0].ti_Data = GetTagData(GA_Width, 0, msg->ops_AttrList) + BORDERPROPSPACINGX * 2;
146 fitags[1].ti_Data = GetTagData(GA_Height, 0, msg->ops_AttrList) + BORDERPROPSPACINGY * 2;
147 fitags[2].ti_Data = (dri->dri_Resolution.X << 16) + dri->dri_Resolution.Y;
149 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
150 if (data->frame)
152 data->freedom=GetTagData(PGA_Freedom,FREEHORIZ,msg->ops_AttrList);
154 data->min = 0;
155 data->max = 15;
156 data->level = data->freedom==FREEHORIZ?data->min:data->max;
158 GTSlider__OM_SET(cl, o, msg);
160 data->labelplace = GetTagData(GA_LabelPlace, GV_LabelPlace_Left, msg->ops_AttrList);
161 } else {
162 CoerceMethod(cl, o, OM_DISPOSE);
163 o = NULL;
166 ReturnPtr("Slider::New", IPTR, (IPTR)o);
170 /**********************************************************************************************/
172 IPTR GTSlider__GM_GOACTIVE(Class *cl, Object *o, struct gpInput *msg)
174 IPTR retval;
175 struct SliderData *data = INST_DATA(cl, o);
177 EnterFunc(bug("Slider::GoActive()\n"));
178 retval = DoSuperMethodA(cl, o, (Msg)msg);
180 if (retval != GMR_MEACTIVE)
182 data->level = data->min + (WORD)*(msg->gpi_Termination);
183 notifylevel(cl, o, data->level, msg->gpi_GInfo, GadToolsBase);
185 ReturnInt("Slider::Goactive", IPTR, retval);
188 /**********************************************************************************************/
190 IPTR GTSlider__OM_GET(Class *cl, Object *o, struct opGet *msg)
192 struct SliderData *data = INST_DATA(cl, o);
193 IPTR retval = 1UL;
195 switch (msg->opg_AttrID)
197 case GTA_GadgetKind:
198 case GTA_ChildGadgetKind:
199 *msg->opg_Storage = SLIDER_KIND;
200 break;
202 case GTSL_Level:
203 *msg->opg_Storage = data->freedom==FREEHORIZ?data->level:data->max-data->level+data->min;
204 break;
206 case GTSL_Max:
207 *msg->opg_Storage = data->max;
208 break;
210 case GTSL_Min:
211 *msg->opg_Storage = data->min;
212 break;
214 default:
215 retval = DoSuperMethodA(cl, o, (Msg)msg);
216 break;
219 return retval;
222 /**********************************************************************************************/
224 IPTR GTSlider__GM_HANDLEINPUT(Class *cl, Object *o, struct gpInput *msg)
226 struct InputEvent *ie = msg->gpi_IEvent;
227 IPTR retval;
228 struct SliderData *data = INST_DATA(cl ,o);
230 EnterFunc(bug("Slider::HandleInput()\n"));
231 retval = DoSuperMethodA(cl, o, (Msg)msg);
232 /* Mousemove ? */
233 if ((ie->ie_Class == IECLASS_RAWMOUSE) && (ie->ie_Code == IECODE_NOBUTTON))
235 LONG top;
237 /* Get the PGA_Top attribute */
238 DoSuperMethod(cl, o, OM_GET, PGA_Top, (IPTR) &top);
240 /* Level changed ? */
241 if (data->level - data->min != top)
243 data->level = data->min + top;
244 notifylevel(cl, o, data->level, msg->gpi_GInfo, GadToolsBase);
247 else
249 if (retval != GMR_MEACTIVE)
252 data->level = data->min + (WORD)*(msg->gpi_Termination);
253 notifylevel(cl, o, data->level, msg->gpi_GInfo, GadToolsBase);
257 ReturnInt("Slider::HandleInput", IPTR, retval);
260 /**********************************************************************************************/
262 IPTR GTSlider__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
264 struct SliderData *data = INST_DATA(cl, g);
265 IPTR retval;
267 if (msg->gpr_Redraw == GREDRAW_REDRAW)
269 DrawImageState(msg->gpr_RPort,
270 (struct Image *)data->frame,
271 g->LeftEdge - BORDERPROPSPACINGX,
272 g->TopEdge - BORDERPROPSPACINGY,
273 IDS_NORMAL,
274 msg->gpr_GInfo->gi_DrInfo);
278 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
280 renderlabel(GadToolsBase, g, msg->gpr_RPort, data->labelplace);
282 ReturnInt("Slider::Render", IPTR, retval);
285 /**********************************************************************************************/
287 IPTR GTSlider__OM_DISPOSE(Class *cl, Object *o, Msg msg)
289 struct SliderData *data = INST_DATA(cl, o);
291 if (data->frame) DisposeObject(data->frame);
293 return DoSuperMethodA(cl, o, msg);
296 /**********************************************************************************************/