2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: AROS specific cycle class implementation.
9 /***********************************************************************************/
11 #define USE_BOOPSI_STUBS
12 #include <exec/libraries.h>
13 #include <proto/dos.h>
14 #include <proto/intuition.h>
15 #include <intuition/classes.h>
16 #include <intuition/classusr.h>
17 #include <intuition/imageclass.h>
18 #include <intuition/intuition.h>
19 #include <intuition/screens.h>
20 #include <proto/graphics.h>
21 #include <graphics/rastport.h>
22 #include <graphics/text.h>
23 #include <proto/utility.h>
24 #include <utility/tagitem.h>
25 #include <devices/inputevent.h>
26 #include <gadgets/aroscycle.h>
27 #include <proto/alib.h>
32 #include <aros/debug.h>
34 #include "aroscycle_intern.h"
36 /***********************************************************************************/
38 #define IM(o) ((struct Image *)(o))
39 #define EG(o) ((struct Gadget *)(o))
41 #include <clib/boopsistubs.h>
43 /***********************************************************************************/
45 Object
*AROSCycle__OM_NEW(Class
*cl
, Class
*rootcl
, struct opSet
*msg
)
47 struct CycleData
*data
;
48 struct TextAttr
*tattr
;
49 struct TagItem imgtags
[] = {
52 { IA_EdgesOnly
, FALSE
},
53 { IA_FrameType
, FRAME_BUTTON
},
59 o
= (Object
*)DoSuperMethodA(cl
, (Object
*)rootcl
, (Msg
)msg
);
63 data
= INST_DATA(cl
, o
);
64 data
->active
= GetTagData(AROSCYCLE_Active
, 0, msg
->ops_AttrList
);
65 data
->labels
= (STRPTR
*)GetTagData(AROSCYCLE_Labels
, (IPTR
) NULL
, msg
->ops_AttrList
);
68 labels
= data
->labels
;
78 tattr
= (struct TextAttr
*)GetTagData(GA_TextAttr
, (IPTR
) NULL
, msg
->ops_AttrList
);
79 if (tattr
) data
->font
= OpenFont(tattr
);
81 imgtags
[0].ti_Data
= (IPTR
)EG(o
)->Width
;
82 imgtags
[1].ti_Data
= (IPTR
)EG(o
)->Height
;
84 EG(o
)->GadgetRender
= NewObjectA(NULL
, FRAMEICLASS
, imgtags
);
85 if (!EG(o
)->GadgetRender
)
87 IPTR methodid
= OM_DISPOSE
;
88 CoerceMethodA(cl
, o
, (Msg
)&methodid
);
95 /***********************************************************************************/
97 VOID
AROSCycle__OM_DISPOSE(Class
*cl
, Object
*o
, Msg msg
)
99 struct CycleData
*data
= INST_DATA(cl
, o
);
101 if (EG(o
)->GadgetRender
)
102 DisposeObject(EG(o
)->GadgetRender
);
104 if (data
->font
) CloseFont(data
->font
);
106 DoSuperMethodA(cl
,o
,msg
);
109 /***********************************************************************************/
111 IPTR
AROSCycle__OM_GET(Class
*cl
, Object
*o
, struct opGet
*msg
)
113 struct CycleData
*data
= INST_DATA(cl
, o
);
116 switch(msg
->opg_AttrID
)
118 case AROSCYCLE_Active
:
119 *(msg
->opg_Storage
) = (IPTR
)data
->active
;
122 case AROSCYCLE_Labels
:
123 *(msg
->opg_Storage
) = (IPTR
)data
->labels
;
127 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
134 /***********************************************************************************/
136 IPTR
AROSCycle__OM_SET(Class
*cl
, Object
*o
, struct opSet
*msg
)
138 struct CycleData
*data
= INST_DATA(cl
, o
);
139 struct TagItem
*tag
, *taglist
= msg
->ops_AttrList
;
141 BOOL rerender
= FALSE
;
144 result
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
146 while((tag
= NextTagItem(&taglist
)))
150 case AROSCYCLE_Labels
:
151 data
->labels
= (STRPTR
*)tag
->ti_Data
;
154 mylabels
= data
->labels
;
166 case AROSCYCLE_Active
:
167 data
->active
= tag
->ti_Data
;
177 /* SDuvan: Removed test (cl == OCLASS(o)) */
181 struct RastPort
*rport
;
183 if(data
->active
> data
->numlabels
-1)
186 //kprintf("Rerendering\n");
188 rport
= ObtainGIRPort(msg
->ops_GInfo
);
191 DoMethod(o
, GM_RENDER
, (IPTR
)msg
->ops_GInfo
, (IPTR
)rport
, GREDRAW_UPDATE
);
192 ReleaseGIRPort(rport
);
200 /***********************************************************************************/
202 IPTR
cycle_hittest(Class
*cl
, Object
*o
, struct gpHitTest
*msg
)
204 return pointingadget((struct Gadget
*)o
,
207 msg
->gpht_Mouse
.Y
) ? GMR_GADGETHIT
: 0;
210 /***********************************************************************************/
212 VOID
AROSCycle__GM_RENDER(Class
*cl
, Object
*o
, struct gpRender
*msg
)
214 struct CycleData
*data
= INST_DATA(cl
, o
);
216 /* Full redraw: clear and draw border */
217 DrawImageState(msg
->gpr_RPort
,IM(EG(o
)->GadgetRender
),
218 EG(o
)->LeftEdge
, EG(o
)->TopEdge
,
219 EG(o
)->Flags
&GFLG_SELECTED
?IDS_SELECTED
:IDS_NORMAL
,
220 msg
->gpr_GInfo
->gi_DrInfo
);
223 SetFont(msg
->gpr_RPort
, data
->font
);
225 SetFont(msg
->gpr_RPort
, msg
->gpr_GInfo
->gi_DrInfo
->dri_Font
);
228 renderlabel(EG(o
), data
->labels
[data
->active
],
229 msg
->gpr_RPort
, msg
->gpr_GInfo
);
231 /* Draw disabled pattern */
232 if (G(o
)->Flags
& GFLG_DISABLED
)
233 drawdisabledpattern(msg
->gpr_RPort
,
234 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[SHADOWPEN
],
235 G(o
)->LeftEdge
, G(o
)->TopEdge
,
236 G(o
)->Width
, G(o
)->Height
);
240 /***********************************************************************************/
242 IPTR
AROSCycle__GM_GOACTIVE(Class
*cl
, Object
*o
, struct gpInput
*msg
)
244 struct RastPort
*rport
;
247 EG(o
)->Flags
|= GFLG_SELECTED
;
249 rport
= ObtainGIRPort(msg
->gpi_GInfo
);
252 struct gpRender rmsg
=
253 { GM_RENDER
, msg
->gpi_GInfo
, rport
, GREDRAW_UPDATE
}, *p_rmsg
= &rmsg
;
254 DoMethodA(o
, (Msg
)p_rmsg
);
255 ReleaseGIRPort(rport
);
256 retval
= GMR_MEACTIVE
;
258 retval
= GMR_NOREUSE
;
263 /***********************************************************************************/
265 IPTR
AROSCycle__GM_HANDLEINPUT(Class
*cl
, Object
*o
, struct gpInput
*msg
)
267 struct RastPort
*rport
;
268 struct CycleData
*data
;
269 IPTR retval
= GMR_MEACTIVE
;
271 data
= INST_DATA(cl
, o
);
273 if (msg
->gpi_IEvent
->ie_Class
== IECLASS_RAWMOUSE
)
275 if (msg
->gpi_IEvent
->ie_Code
== SELECTUP
)
277 if (G(o
)->Flags
& GFLG_SELECTED
)
279 /* mouse is over gadget */
282 if (data
->active
== data
->numlabels
)
286 *msg
->gpi_Termination
= data
->active
;
287 retval
= GMR_NOREUSE
| GMR_VERIFY
;
289 /* mouse is not over gadget */
290 retval
= GMR_NOREUSE
;
293 G(o)->Flags &= ~GFLG_SELECTED;
295 rport = ObtainGIRPort(msg->gpi_GInfo);
298 struct gpRender rmsg =
299 { GM_RENDER, msg->gpi_GInfo, rport, GREDRAW_UPDATE };
300 DoMethodA(o, (Msg)&rmsg);
301 ReleaseGIRPort(rport);
304 } else if (msg
->gpi_IEvent
->ie_Code
== IECODE_NOBUTTON
)
306 struct gpHitTest htmsg
=
307 { GM_HITTEST
, msg
->gpi_GInfo
,
308 { msg
->gpi_Mouse
.X
, msg
->gpi_Mouse
.Y
},
309 }, *p_htmsg
= &htmsg
;
310 if (DoMethodA(o
, (Msg
)p_htmsg
) != GMR_GADGETHIT
)
312 if (EG(o
)->Flags
& GFLG_SELECTED
)
314 G(o
)->Flags
&= ~GFLG_SELECTED
;
315 rport
= ObtainGIRPort(msg
->gpi_GInfo
);
318 struct gpRender rmsg
=
319 { GM_RENDER
, msg
->gpi_GInfo
, rport
, GREDRAW_UPDATE
}, *p_rmsg
= &rmsg
;
320 DoMethodA(o
, (Msg
)p_rmsg
);
321 ReleaseGIRPort(rport
);
326 if (!(EG(o
)->Flags
& GFLG_SELECTED
))
328 EG(o
)->Flags
|= GFLG_SELECTED
;
329 rport
= ObtainGIRPort(msg
->gpi_GInfo
);
332 struct gpRender rmsg
=
333 { GM_RENDER
, msg
->gpi_GInfo
, rport
, GREDRAW_UPDATE
}, *p_rmsg
= &rmsg
;
334 DoMethodA(o
, (Msg
)p_rmsg
);
335 ReleaseGIRPort(rport
);
339 } else if (msg
->gpi_IEvent
->ie_Code
== MENUDOWN
)
345 /***********************************************************************************/
347 IPTR
AROSCycle__GM_GOINACTIVE(Class
*cl
, Object
*o
, struct gpGoInactive
*msg
)
349 struct RastPort
*rport
;
351 EG(o
)->Flags
&= ~GFLG_SELECTED
;
353 rport
= ObtainGIRPort(msg
->gpgi_GInfo
);
356 struct gpRender rmsg
= { GM_RENDER
, msg
->gpgi_GInfo
, rport
, GREDRAW_UPDATE
}, *p_rmsg
= &rmsg
;
358 DoMethodA(o
, (Msg
)p_rmsg
);
359 ReleaseGIRPort(rport
);