2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: Internal GadTools cycle class.
10 #include <proto/exec.h>
11 #include <exec/libraries.h>
12 #include <exec/memory.h>
13 #include <proto/dos.h>
14 #include <intuition/classes.h>
15 #include <intuition/classusr.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/imageclass.h>
18 #include <intuition/intuition.h>
19 #include <intuition/cghooks.h>
20 #include <graphics/rastport.h>
21 #include <graphics/text.h>
22 #include <utility/tagitem.h>
23 #include <devices/inputevent.h>
24 #include <proto/alib.h>
25 #include <proto/utility.h>
27 #include <string.h> /* memset() */
31 #include <aros/debug.h>
33 #include "gadtools_intern.h"
35 /**********************************************************************************************/
37 #define CYCLEIMAGEWIDTH 19
39 #define GadToolsBase ((struct GadToolsBase_intern *)cl->cl_UserData)
41 /**********************************************************************************************/
43 STATIC VOID
rendercyclelabel(Class
*cl
, struct Gadget
*gad
, STRPTR string
,
44 struct RastPort
*rp
, struct GadgetInfo
*ginfo
)
46 UWORD
*pens
= ginfo
->gi_DrInfo
->dri_Pens
;
48 int len
= strlen(string
);
50 SetABPenDrMd(rp
, pens
[TEXTPEN
], pens
[BACKGROUNDPEN
], JAM1
);
52 gad
->LeftEdge
+ (gad
->Width
- CYCLEIMAGEWIDTH
- TextLength(rp
, string
, len
)) / 2,
53 gad
->TopEdge
+ (gad
->Height
- rp
->Font
->tf_YSize
) / 2 + rp
->Font
->tf_Baseline
);
54 Text(rp
, string
, len
);
56 x
= gad
->LeftEdge
+ gad
->Width
- CYCLEIMAGEWIDTH
;
60 SetAPen(rp
, pens
[SHINEPEN
]);
61 RectFill(rp
, x
+ 1, gad
->TopEdge
+ 2, x
+ 1, gad
->TopEdge
+ gad
->Height
- 1 - 2);
62 SetAPen(rp
, pens
[SHADOWPEN
]);
63 RectFill(rp
, x
, gad
->TopEdge
+ 2, x
, gad
->TopEdge
+ gad
->Height
- 1 - 2);
71 for(y
= 0; y
< 4; y
++)
74 gad
->TopEdge
+ gad
->Height
- 1 - h
- y
- 1,
76 gad
->TopEdge
+ gad
->Height
- 1 - h
- y
- 1);
79 gad
->TopEdge
+ h
+ y
+ 1,
81 gad
->TopEdge
+ h
+ y
+ 1);
85 /**********************************************************************************************/
87 BOOL
pointingadget(struct Gadget
*gad
, struct GadgetInfo
*gi
, WORD x
, WORD y
)
92 if (gad
->Flags
& GFLG_RELWIDTH
) gadw
+= gi
->gi_Domain
.Width
;
95 if (gad
->Flags
& GFLG_RELHEIGHT
) gadh
+= gi
->gi_Domain
.Height
;
97 return ((x
>= 0) && (y
>= 0) && (x
< gadw
) && (y
< gadh
)) ? TRUE
: FALSE
;
100 /**********************************************************************************************/
102 IPTR
GTCycle__OM_NEW(Class
*cl
, Object
*objcl
, struct opSet
*msg
)
104 struct CycleData
*data
;
105 struct TextAttr
*tattr
;
106 struct TagItem imgtags
[] =
110 { IA_EdgesOnly
, FALSE
},
111 { IA_FrameType
, FRAME_BUTTON
},
117 g
= (struct Gadget
*)DoSuperMethodA(cl
, objcl
, (Msg
)msg
);
121 data
= INST_DATA(cl
, g
);
123 data
->active
= GetTagData(GTCY_Active
, 0, msg
->ops_AttrList
);
124 data
->labels
= (STRPTR
*)GetTagData(GTCY_Labels
, (IPTR
)NULL
, msg
->ops_AttrList
);
125 data
->labelplace
= GetTagData(GA_LabelPlace
, GV_LabelPlace_Left
, msg
->ops_AttrList
);
129 labels
= data
->labels
;
139 tattr
= (struct TextAttr
*)GetTagData(GA_TextAttr
, (IPTR
)NULL
, msg
->ops_AttrList
);
140 if (tattr
) data
->font
= OpenFont(tattr
);
142 imgtags
[0].ti_Data
= (IPTR
)g
->Width
;
143 imgtags
[1].ti_Data
= (IPTR
)g
->Height
;
145 g
->GadgetRender
= NewObjectA(NULL
, FRAMEICLASS
, imgtags
);
146 if (!(g
->GadgetRender
))
148 CoerceMethod(cl
, (Object
*)g
, OM_DISPOSE
);
155 /**********************************************************************************************/
157 IPTR
GTCycle__OM_DISPOSE(Class
*cl
, struct Gadget
* g
, Msg msg
)
159 struct CycleData
*data
= INST_DATA(cl
, g
);
162 DisposeObject(g
->GadgetRender
);
164 if (data
->font
) CloseFont(data
->font
);
166 return DoSuperMethodA(cl
,(Object
*)g
,msg
);
169 /**********************************************************************************************/
171 IPTR
GTCycle__OM_SET(Class
*cl
, Object
*o
, struct opSet
*msg
)
173 struct CycleData
*data
= INST_DATA(cl
, o
);
175 struct TagItem
*taglist
= msg
->ops_AttrList
;
177 BOOL rerender
= FALSE
;
180 result
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
182 while((tag
= NextTagItem(&taglist
)))
187 data
->labels
= (STRPTR
*)tag
->ti_Data
;
190 mylabels
= data
->labels
;
203 data
->active
= tag
->ti_Data
;
213 /* SDuvan: Removed test (cl == OCLASS(o)) */
219 if(data
->active
> data
->numlabels
-1)
222 //kprintf("Rerendering\n");
224 rp
= ObtainGIRPort(msg
->ops_GInfo
);
227 DoMethod(o
, GM_RENDER
, (IPTR
)msg
->ops_GInfo
, (IPTR
)rp
, GREDRAW_UPDATE
);
236 /**********************************************************************************************/
238 IPTR
GTCycle__OM_GET(Class
*cl
, Object
*o
, struct opGet
*msg
)
240 struct CycleData
*data
= INST_DATA(cl
, o
);
243 switch (msg
->opg_AttrID
)
246 case GTA_ChildGadgetKind
:
247 *(msg
->opg_Storage
) = CYCLE_KIND
;
252 *(msg
->opg_Storage
) = (IPTR
)data
->active
;
256 *(msg
->opg_Storage
) = (IPTR
)data
->labels
;
260 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
267 /**********************************************************************************************/
269 IPTR
GTCycle__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
271 struct CycleData
*data
= INST_DATA(cl
, g
);
273 /* Full redraw: clear and draw border */
274 DrawImageState(msg
->gpr_RPort
,(struct Image
*)g
->GadgetRender
,
275 g
->LeftEdge
, g
->TopEdge
,
276 (g
->Flags
& GFLG_SELECTED
)? IDS_SELECTED
: IDS_NORMAL
,
277 msg
->gpr_GInfo
->gi_DrInfo
);
280 SetFont(msg
->gpr_RPort
, data
->font
);
282 SetFont(msg
->gpr_RPort
, msg
->gpr_GInfo
->gi_DrInfo
->dri_Font
);
286 rendercyclelabel(cl
, g
, data
->labels
[data
->active
], msg
->gpr_RPort
, msg
->gpr_GInfo
);
289 /* Draw disabled pattern */
290 if (g
->Flags
& GFLG_DISABLED
)
292 DoDisabledPattern(msg
->gpr_RPort
,
295 g
->LeftEdge
+ g
->Width
- 1,
296 g
->TopEdge
+ g
->Height
- 1,
297 msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
[SHADOWPEN
],
301 if (msg
->gpr_Redraw
== GREDRAW_REDRAW
)
303 renderlabel(GadToolsBase
, g
, msg
->gpr_RPort
, data
->labelplace
);
309 /**********************************************************************************************/
311 IPTR
GTCycle__GM_HITTEST(Class
*cl
, struct Gadget
*g
, struct gpHitTest
*msg
)
313 return pointingadget(g
,
316 msg
->gpht_Mouse
.Y
) ? GMR_GADGETHIT
: 0;
319 /**********************************************************************************************/
321 IPTR
GTCycle__GM_GOACTIVE(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
326 g
->Flags
|= GFLG_SELECTED
;
328 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
331 struct gpRender rmsg
=
338 DoMethodA((Object
*)g
, (Msg
)&rmsg
);
340 retval
= GMR_MEACTIVE
;
344 retval
= GMR_NOREUSE
;
350 /**********************************************************************************************/
352 IPTR
GTCycle__GM_HANDLEINPUT(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
355 struct CycleData
*data
;
356 IPTR retval
= GMR_MEACTIVE
;
358 data
= INST_DATA(cl
, g
);
360 if (msg
->gpi_IEvent
->ie_Class
== IECLASS_RAWMOUSE
)
362 if (msg
->gpi_IEvent
->ie_Code
== SELECTUP
)
364 if (g
->Flags
& GFLG_SELECTED
)
366 /* mouse is over gadget */
369 if (data
->active
== data
->numlabels
)
373 *msg
->gpi_Termination
= data
->active
;
374 retval
= GMR_NOREUSE
| GMR_VERIFY
;
378 /* mouse is not over gadget */
379 retval
= GMR_NOREUSE
;
383 else if (msg
->gpi_IEvent
->ie_Code
== IECODE_NOBUTTON
)
385 struct gpHitTest htmsg
=
389 { msg
->gpi_Mouse
.X
, msg
->gpi_Mouse
.Y
},
392 if (DoMethodA((Object
*)g
, (Msg
)&htmsg
) != GMR_GADGETHIT
)
394 if (g
->Flags
& GFLG_SELECTED
)
396 g
->Flags
&= ~GFLG_SELECTED
;
397 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
400 struct gpRender rmsg
=
408 DoMethodA((Object
*)g
, (Msg
)&rmsg
);
415 if (!(g
->Flags
& GFLG_SELECTED
))
417 g
->Flags
|= GFLG_SELECTED
;
418 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
421 struct gpRender rmsg
=
429 DoMethodA((Object
*)g
, (Msg
)&rmsg
);
435 else if (msg
->gpi_IEvent
->ie_Code
== MENUDOWN
)
444 /**********************************************************************************************/
446 IPTR
GTCycle__GM_GOINACTIVE(Class
*cl
, struct Gadget
*g
, struct gpGoInactive
*msg
)
450 g
->Flags
&= ~GFLG_SELECTED
;
452 rp
= ObtainGIRPort(msg
->gpgi_GInfo
);
455 struct gpRender rmsg
=
463 DoMethodA((Object
*)g
, (Msg
)&rmsg
);
470 /**********************************************************************************************/