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
)
61 struct TagItem
*tag
, *tstate
, *dosuper_tags
, tags
[] =
67 struct SliderData
*data
= INST_DATA(cl
, o
);
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
;
82 data
->min
= (WORD
)tidata
;
87 data
->max
= (WORD
)tidata
;
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
);
103 } /* while (iterate taglist) */
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
;
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
[] =
129 {IA_Resolution
, 0UL },
130 {IA_FrameType
, FRAME_BUTTON
},
131 {IA_EdgesOnly
, TRUE
},
135 EnterFunc(bug("Slider::New()\n"));
137 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
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
);
151 data
->freedom
=GetTagData(PGA_Freedom
,FREEHORIZ
,msg
->ops_AttrList
);
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
);
161 CoerceMethod(cl
, o
, OM_DISPOSE
);
165 ReturnPtr("Slider::New", IPTR
, (IPTR
)o
);
169 /**********************************************************************************************/
171 IPTR
GTSlider__GM_GOACTIVE(Class
*cl
, Object
*o
, struct gpInput
*msg
)
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
);
194 switch (msg
->opg_AttrID
)
197 case GTA_ChildGadgetKind
:
198 *msg
->opg_Storage
= SLIDER_KIND
;
202 *msg
->opg_Storage
= data
->freedom
==FREEHORIZ
?data
->level
:data
->max
-data
->level
+data
->min
;
206 *msg
->opg_Storage
= data
->max
;
210 *msg
->opg_Storage
= data
->min
;
214 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
221 /**********************************************************************************************/
223 IPTR
GTSlider__GM_HANDLEINPUT(Class
*cl
, Object
*o
, struct gpInput
*msg
)
225 struct InputEvent
*ie
= msg
->gpi_IEvent
;
227 struct SliderData
*data
= INST_DATA(cl
,o
);
229 EnterFunc(bug("Slider::HandleInput()\n"));
230 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
232 if ((ie
->ie_Class
== IECLASS_RAWMOUSE
) && (ie
->ie_Code
== IECODE_NOBUTTON
))
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
);
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
);
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
,
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 /**********************************************************************************************/