2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Internal GadTools slider class.
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() */
30 #include <aros/debug.h>
32 #include "gadtools_intern.h"
34 /**********************************************************************************************/
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
},
48 ntags
[0].ti_Data
= (IPTR
)level
;
49 DoSuperMethod(cl
, o
, OM_NOTIFY
, (IPTR
) ntags
, (IPTR
) ginfo
, 0);
54 #define GadToolsBase ((struct GadToolsBase_intern *)(cl->cl_UserData))
56 /**********************************************************************************************/
58 IPTR
GTSlider__OM_SET(Class
* cl
, Object
* o
, struct opSet
* msg
)
60 struct TagItem
*tag
, *tstate
, *dosuper_tags
, tags
[] =
66 struct SliderData
*data
= INST_DATA(cl
, o
);
70 EnterFunc(bug("Slider::Set(attrlist=%p)\n", msg
->ops_AttrList
));
71 dosuper_tags
= msg
->ops_AttrList
;
73 tstate
= msg
->ops_AttrList
;
74 while ((tag
= NextTagItem(&tstate
)))
76 WORD tidata
= tag
->ti_Data
;
90 case GTSL_Level
: /* [ISN] */
91 /* Ensure that the value is within limits */
92 if (tidata
< data
->min
)
94 if (tidata
> data
->max
)
97 if (tidata
!= data
->level
)
99 data
->level
= data
->freedom
== FREEHORIZ
? tidata
: data
->max
- tidata
+ data
->min
;
100 notifylevel(cl
, o
, data
->level
, msg
->ops_GInfo
, GadToolsBase
);
108 } /* while (iterate taglist) */
112 tags
[0].ti_Data
= data
->max
- data
->min
+ 1;
113 tags
[1].ti_Data
= data
->level
- data
->min
;
114 tags
[2].ti_Data
= (IPTR
)msg
->ops_AttrList
;
119 ReturnInt ("Slider::Set", IPTR
, DoSuperMethod(cl
, o
, OM_SET
, (IPTR
) dosuper_tags
, (IPTR
) msg
->ops_GInfo
));
122 /**********************************************************************************************/
124 IPTR
GTSlider__OM_NEW(Class
* cl
, Object
* o
, struct opSet
*msg
)
126 struct DrawInfo
*dri
;
128 struct TagItem fitags
[] =
132 {IA_Resolution
, 0UL },
133 {IA_FrameType
, FRAME_BUTTON
},
134 {IA_EdgesOnly
, TRUE
},
138 EnterFunc(bug("Slider::New()\n"));
140 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
143 struct SliderData
*data
= INST_DATA(cl
, o
);
145 dri
= (struct DrawInfo
*)GetTagData(GA_DrawInfo
, (IPTR
) NULL
, msg
->ops_AttrList
);
147 fitags
[0].ti_Data
= GetTagData(GA_Width
, 0, msg
->ops_AttrList
) + BORDERPROPSPACINGX
* 2;
148 fitags
[1].ti_Data
= GetTagData(GA_Height
, 0, msg
->ops_AttrList
) + BORDERPROPSPACINGY
* 2;
149 fitags
[2].ti_Data
= (dri
->dri_Resolution
.X
<< 16) + dri
->dri_Resolution
.Y
;
151 data
->frame
= NewObjectA(NULL
, FRAMEICLASS
, fitags
);
154 data
->freedom
=GetTagData(PGA_Freedom
,FREEHORIZ
,msg
->ops_AttrList
);
158 data
->level
= data
->freedom
==FREEHORIZ
?data
->min
:data
->max
;
159 notifylevel(cl
, o
, data
->level
, msg
->ops_GInfo
, GadToolsBase
);
161 GTSlider__OM_SET(cl
, o
, msg
);
163 data
->labelplace
= GetTagData(GA_LabelPlace
, GV_LabelPlace_Left
, msg
->ops_AttrList
);
165 CoerceMethod(cl
, o
, OM_DISPOSE
);
169 ReturnPtr("Slider::New", IPTR
, (IPTR
)o
);
173 /**********************************************************************************************/
175 IPTR
GTSlider__GM_GOACTIVE(Class
*cl
, Object
*o
, struct gpInput
*msg
)
178 struct SliderData
*data
= INST_DATA(cl
, o
);
180 EnterFunc(bug("Slider::GoActive()\n"));
181 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
183 if (retval
!= GMR_MEACTIVE
)
185 data
->level
= data
->min
+ (WORD
)*(msg
->gpi_Termination
);
186 notifylevel(cl
, o
, data
->level
, msg
->gpi_GInfo
, GadToolsBase
);
188 ReturnInt("Slider::Goactive", IPTR
, retval
);
191 /**********************************************************************************************/
193 IPTR
GTSlider__OM_GET(Class
*cl
, Object
*o
, struct opGet
*msg
)
195 struct SliderData
*data
= INST_DATA(cl
, o
);
198 switch (msg
->opg_AttrID
)
201 case GTA_ChildGadgetKind
:
202 *msg
->opg_Storage
= SLIDER_KIND
;
206 *msg
->opg_Storage
= data
->freedom
==FREEHORIZ
?data
->level
:data
->max
-data
->level
+data
->min
;
210 *msg
->opg_Storage
= data
->max
;
214 *msg
->opg_Storage
= data
->min
;
218 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
225 /**********************************************************************************************/
227 IPTR
GTSlider__GM_HANDLEINPUT(Class
*cl
, Object
*o
, struct gpInput
*msg
)
229 struct InputEvent
*ie
= msg
->gpi_IEvent
;
231 struct SliderData
*data
= INST_DATA(cl
,o
);
233 EnterFunc(bug("Slider::HandleInput()\n"));
234 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
236 if ((ie
->ie_Class
== IECLASS_RAWMOUSE
) && (ie
->ie_Code
== IECODE_NOBUTTON
))
240 /* Get the PGA_Top attribute */
241 DoSuperMethod(cl
, o
, OM_GET
, PGA_Top
, (IPTR
) &top
);
243 /* Level changed ? */
244 if (data
->level
- data
->min
!= top
)
246 data
->level
= data
->min
+ top
;
247 notifylevel(cl
, o
, data
->level
, msg
->gpi_GInfo
, GadToolsBase
);
252 if (retval
!= GMR_MEACTIVE
)
255 data
->level
= data
->min
+ (WORD
)*(msg
->gpi_Termination
);
256 notifylevel(cl
, o
, data
->level
, msg
->gpi_GInfo
, GadToolsBase
);
260 ReturnInt("Slider::HandleInput", IPTR
, retval
);
263 /**********************************************************************************************/
265 IPTR
GTSlider__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
267 struct SliderData
*data
= INST_DATA(cl
, g
);
270 if (msg
->gpr_Redraw
== GREDRAW_REDRAW
)
272 DrawImageState(msg
->gpr_RPort
,
273 (struct Image
*)data
->frame
,
274 g
->LeftEdge
- BORDERPROPSPACINGX
,
275 g
->TopEdge
- BORDERPROPSPACINGY
,
277 msg
->gpr_GInfo
->gi_DrInfo
);
281 retval
= DoSuperMethodA(cl
, (Object
*)g
, (Msg
)msg
);
283 renderlabel(GadToolsBase
, g
, msg
->gpr_RPort
, data
->labelplace
);
285 ReturnInt("Slider::Render", IPTR
, retval
);
288 /**********************************************************************************************/
290 IPTR
GTSlider__OM_DISPOSE(Class
*cl
, Object
*o
, Msg msg
)
292 struct SliderData
*data
= INST_DATA(cl
, o
);
294 if (data
->frame
) DisposeObject(data
->frame
);
296 return DoSuperMethodA(cl
, o
, msg
);
299 /**********************************************************************************************/