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 const struct TagItem
*tstate
;
62 struct TagItem
*tag
, *dosuper_tags
, tags
[] =
68 struct SliderData
*data
= INST_DATA(cl
, o
);
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
;
83 data
->min
= (WORD
)tidata
;
88 data
->max
= (WORD
)tidata
;
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
);
104 } /* while (iterate taglist) */
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
;
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
[] =
130 {IA_Resolution
, 0UL },
131 {IA_FrameType
, FRAME_BUTTON
},
132 {IA_EdgesOnly
, TRUE
},
136 EnterFunc(bug("Slider::New()\n"));
138 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
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
);
152 data
->freedom
=GetTagData(PGA_Freedom
,FREEHORIZ
,msg
->ops_AttrList
);
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
);
162 CoerceMethod(cl
, o
, OM_DISPOSE
);
166 ReturnPtr("Slider::New", IPTR
, (IPTR
)o
);
170 /**********************************************************************************************/
172 IPTR
GTSlider__GM_GOACTIVE(Class
*cl
, Object
*o
, struct gpInput
*msg
)
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
);
195 switch (msg
->opg_AttrID
)
198 case GTA_ChildGadgetKind
:
199 *msg
->opg_Storage
= SLIDER_KIND
;
203 *msg
->opg_Storage
= data
->freedom
==FREEHORIZ
?data
->level
:data
->max
-data
->level
+data
->min
;
207 *msg
->opg_Storage
= data
->max
;
211 *msg
->opg_Storage
= data
->min
;
215 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
222 /**********************************************************************************************/
224 IPTR
GTSlider__GM_HANDLEINPUT(Class
*cl
, Object
*o
, struct gpInput
*msg
)
226 struct InputEvent
*ie
= msg
->gpi_IEvent
;
228 struct SliderData
*data
= INST_DATA(cl
,o
);
230 EnterFunc(bug("Slider::HandleInput()\n"));
231 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
233 if ((ie
->ie_Class
== IECLASS_RAWMOUSE
) && (ie
->ie_Code
== IECODE_NOBUTTON
))
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
);
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
);
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
,
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 /**********************************************************************************************/