added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / gadtools / sliderclass.c
blob41aff173ceb13f6b665ec6107323c1a9b564d0cc
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 struct TagItem *tag, *tstate, *dosuper_tags, tags[] =
63 {PGA_Total , 0 },
64 {PGA_Top , 0 },
65 {TAG_MORE , 0 }
67 struct SliderData *data = INST_DATA(cl, o);
69 BOOL val_set = FALSE;
71 EnterFunc(bug("Slider::Set(attrlist=%p)\n", msg->ops_AttrList));
72 dosuper_tags = msg->ops_AttrList;
74 tstate = msg->ops_AttrList;
75 while ((tag = NextTagItem(&tstate)))
77 IPTR tidata = tag->ti_Data;
79 switch (tag->ti_Tag)
81 case GTSL_Min:
82 data->min = (WORD)tidata;
83 val_set = TRUE;
84 break;
86 case GTSL_Max:
87 data->max = (WORD)tidata;
88 val_set = TRUE;
89 break;
91 case GTSL_Level: /* [ISN] */
92 if (tidata != data->level)
94 data->level = data->freedom==FREEHORIZ?(WORD)tidata:data->max-(WORD)tidata+data->min;
95 notifylevel(cl, o, data->level, msg->ops_GInfo, GadToolsBase);
96 val_set = TRUE;
99 break;
101 } /* switch () */
103 } /* while (iterate taglist) */
105 if (val_set)
107 tags[0].ti_Data = data->max - data->min + 1;
108 tags[1].ti_Data = data->level - data->min;
109 tags[2].ti_Data = (IPTR)msg->ops_AttrList;
111 dosuper_tags = tags;
113 retval = 1UL;
116 ReturnInt ("Slider::Set", IPTR, DoSuperMethod(cl, o, OM_SET, (IPTR) dosuper_tags, (IPTR) msg->ops_GInfo));
119 /**********************************************************************************************/
121 IPTR GTSlider__OM_NEW(Class * cl, Object * o, struct opSet *msg)
123 struct DrawInfo *dri;
125 struct TagItem fitags[] =
127 {IA_Width , 0UL },
128 {IA_Height , 0UL },
129 {IA_Resolution , 0UL },
130 {IA_FrameType , FRAME_BUTTON },
131 {IA_EdgesOnly , TRUE },
132 {TAG_DONE }
135 EnterFunc(bug("Slider::New()\n"));
137 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
138 if (o)
140 struct SliderData *data = INST_DATA(cl, o);
142 dri = (struct DrawInfo *)GetTagData(GA_DrawInfo, (IPTR) NULL, msg->ops_AttrList);
144 fitags[0].ti_Data = GetTagData(GA_Width, 0, msg->ops_AttrList) + BORDERPROPSPACINGX * 2;
145 fitags[1].ti_Data = GetTagData(GA_Height, 0, msg->ops_AttrList) + BORDERPROPSPACINGY * 2;
146 fitags[2].ti_Data = (dri->dri_Resolution.X << 16) + dri->dri_Resolution.Y;
148 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
149 if (data->frame)
151 data->freedom=GetTagData(PGA_Freedom,FREEHORIZ,msg->ops_AttrList);
153 data->min = 0;
154 data->max = 15;
155 data->level = data->freedom==FREEHORIZ?data->min:data->max;
157 GTSlider__OM_SET(cl, o, msg);
159 data->labelplace = GetTagData(GA_LabelPlace, GV_LabelPlace_Left, msg->ops_AttrList);
160 } else {
161 CoerceMethod(cl, o, OM_DISPOSE);
162 o = NULL;
165 ReturnPtr("Slider::New", IPTR, (IPTR)o);
169 /**********************************************************************************************/
171 IPTR GTSlider__GM_GOACTIVE(Class *cl, Object *o, struct gpInput *msg)
173 IPTR retval;
174 struct SliderData *data = INST_DATA(cl, o);
176 EnterFunc(bug("Slider::GoActive()\n"));
177 retval = DoSuperMethodA(cl, o, (Msg)msg);
179 if (retval != GMR_MEACTIVE)
181 data->level = data->min + (WORD)*(msg->gpi_Termination);
182 notifylevel(cl, o, data->level, msg->gpi_GInfo, GadToolsBase);
184 ReturnInt("Slider::Goactive", IPTR, retval);
187 /**********************************************************************************************/
189 IPTR GTSlider__OM_GET(Class *cl, Object *o, struct opGet *msg)
191 struct SliderData *data = INST_DATA(cl, o);
192 IPTR retval = 1UL;
194 switch (msg->opg_AttrID)
196 case GTA_GadgetKind:
197 case GTA_ChildGadgetKind:
198 *msg->opg_Storage = SLIDER_KIND;
199 break;
201 case GTSL_Level:
202 *msg->opg_Storage = data->freedom==FREEHORIZ?data->level:data->max-data->level+data->min;
203 break;
205 case GTSL_Max:
206 *msg->opg_Storage = data->max;
207 break;
209 case GTSL_Min:
210 *msg->opg_Storage = data->min;
211 break;
213 default:
214 retval = DoSuperMethodA(cl, o, (Msg)msg);
215 break;
218 return retval;
221 /**********************************************************************************************/
223 IPTR GTSlider__GM_HANDLEINPUT(Class *cl, Object *o, struct gpInput *msg)
225 struct InputEvent *ie = msg->gpi_IEvent;
226 IPTR retval;
227 struct SliderData *data = INST_DATA(cl ,o);
229 EnterFunc(bug("Slider::HandleInput()\n"));
230 retval = DoSuperMethodA(cl, o, (Msg)msg);
231 /* Mousemove ? */
232 if ((ie->ie_Class == IECLASS_RAWMOUSE) && (ie->ie_Code == IECODE_NOBUTTON))
234 LONG top;
236 /* Get the PGA_Top attribute */
237 DoSuperMethod(cl, o, OM_GET, PGA_Top, (IPTR) &top);
239 /* Level changed ? */
240 if (data->level - data->min != top)
242 data->level = data->min + top;
243 notifylevel(cl, o, data->level, msg->gpi_GInfo, GadToolsBase);
246 else
248 if (retval != GMR_MEACTIVE)
251 data->level = data->min + (WORD)*(msg->gpi_Termination);
252 notifylevel(cl, o, data->level, msg->gpi_GInfo, GadToolsBase);
256 ReturnInt("Slider::HandleInput", IPTR, retval);
259 /**********************************************************************************************/
261 IPTR GTSlider__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
263 struct SliderData *data = INST_DATA(cl, g);
264 IPTR retval;
266 if (msg->gpr_Redraw == GREDRAW_REDRAW)
268 DrawImageState(msg->gpr_RPort,
269 (struct Image *)data->frame,
270 g->LeftEdge - BORDERPROPSPACINGX,
271 g->TopEdge - BORDERPROPSPACINGY,
272 IDS_NORMAL,
273 msg->gpr_GInfo->gi_DrInfo);
277 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
279 renderlabel(GadToolsBase, g, msg->gpr_RPort, data->labelplace);
281 ReturnInt("Slider::Render", IPTR, retval);
284 /**********************************************************************************************/
286 IPTR GTSlider__OM_DISPOSE(Class *cl, Object *o, Msg msg)
288 struct SliderData *data = INST_DATA(cl, o);
290 if (data->frame) DisposeObject(data->frame);
292 return DoSuperMethodA(cl, o, msg);
295 /**********************************************************************************************/