2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 /****************************************************************************/
9 #include <exec/types.h>
12 #include <dos/dosextens.h>
14 #include <intuition/intuition.h>
15 #include <intuition/intuitionbase.h>
16 #include <intuition/classes.h>
17 #include <intuition/classusr.h>
18 #include <intuition/gadgetclass.h>
19 #include <intuition/cghooks.h>
20 #include <intuition/icclass.h>
21 #include <intuition/imageclass.h>
23 #include <graphics/gfxbase.h>
24 #include <graphics/gfxmacros.h>
26 #include <utility/tagitem.h>
27 #include <utility/hooks.h>
29 #include <clib/macros.h>
31 #include <proto/exec.h>
32 #include <proto/intuition.h>
33 #include <proto/graphics.h>
34 #include <proto/utility.h>
39 #include "intuition_intern.h"
40 #include <aros/asmcall.h>
41 #include <proto/alib.h>
43 #endif /* !__MORPHOS__ */
45 #define DEBUG_FRBUTTON(x) ;
47 /****************************************************************************/
50 #define IntuitionBase ((struct IntuitionBase *)(cl->cl_UserData))
52 /****************************************************************************/
54 IPTR
FrButtonClass__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
56 /* We will let the AROS gadgetclass test if it is safe to render */
58 /* FIXME: if ( DoSuperMethodA(cl, o, (Msg *)msg) != 0)
60 UWORD
*pens
= msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
;
61 struct RastPort
*rp
= msg
->gpr_RPort
;
62 struct IBox container
;
64 DEBUG_FRBUTTON(dprintf("frbutton_render: rp %p[%p] win %p[%p] req %p[%p] gi->rp %p[%p]\n",
66 msg
->gpr_GInfo
->gi_Window
, msg
->gpr_GInfo
->gi_Window
->WLayer
,
67 msg
->gpr_GInfo
->gi_Requester
, msg
->gpr_GInfo
->gi_Requester
->ReqLayer
,
68 msg
->gpr_GInfo
->gi_RastPort
, msg
->gpr_GInfo
->gi_RastPort
->Layer
));
71 GetGadgetIBox(g
, msg
->gpr_GInfo
, &container
);
73 if (container
.Width
<= 1 || container
.Height
<= 1)
76 if ((g
->Flags
& GFLG_GADGIMAGE
) == 0) /* not an image-button */
79 if ((g
->SelectRender
!= NULL
) && (g
->Flags
& GFLG_SELECTED
))
81 ((struct Border
*)g
->SelectRender
),
84 else if (g
->GadgetRender
!= NULL
)
86 ((struct Border
*)g
->GadgetRender
),
90 else /* GFLG_GADGIMAGE set */
92 struct TagItem image_tags
[] =
94 {IA_Width
, g
->Width
},
95 {IA_Height
, g
->Height
},
99 if ((g
->SelectRender
!= NULL
) &&
100 (g
->Flags
& GFLG_SELECTED
)) /* render selected image */
103 struct Image
*sr
= g
->SelectRender
;
105 if(sr
->Depth
== CUSTOMIMAGEDEPTH
)
107 // ONLY DO THIS FOR REAL IMAGE OBJECTS (cyfm 31/12/02)
108 /* center image position, we assume image top and left is 0 */
109 SetAttrsA(g
->SelectRender
, image_tags
);
112 x
= container
.Left
+ (container
.Width
/ 2) - (sr
->Width
/ 2);
113 y
= container
.Top
+ (container
.Height
/ 2) - (sr
->Height
/ 2);
119 msg
->gpr_GInfo
->gi_DrInfo
);
121 else if ( g
->GadgetRender
!= NULL
) /* render normal image */
124 struct Image
*gr
= g
->GadgetRender
;
126 if(gr
->Depth
== CUSTOMIMAGEDEPTH
)
128 // ONLY DO THIS FOR REAL IMAGE OBJECTS (cyfm 31/12/02)
129 /* center image position, we assume image top and left is 0 */
130 SetAttrsA(gr
, image_tags
);
133 x
= container
.Left
+ (container
.Width
/ 2) - (gr
->Width
/ 2);
134 y
= container
.Top
+ (container
.Height
/ 2) - (gr
->Height
/ 2);
139 ((g
->Flags
& GFLG_SELECTED
) ? IDS_SELECTED
: IDS_NORMAL
),
140 msg
->gpr_GInfo
->gi_DrInfo
);
145 SetABPenDrMd(rp
, pens
[TEXTPEN
], 0, JAM1
);
147 printgadgetlabel(cl
, (Object
*)g
, msg
, IntuitionBase
);
149 if ( g
->Flags
& GFLG_DISABLED
)
151 UWORD pattern
[] = { 0x8888, 0x2222 };
154 SetAPen( rp
, pens
[SHADOWPEN
] );
155 SetAfPt( rp
, pattern
, 1);
157 /* render disable pattern */
161 container
.Left
+ container
.Width
- 1,
162 container
.Top
+ container
.Height
- 1 );
169 /***********************************************************************************/
171 void frbutton_setsize(Class
*cl
, struct Gadget
*g
, struct opSet
*msg
)
173 struct Image
*image
= (struct Image
*)g
->GadgetRender
;
175 DEBUG_FRBUTTON(dprintf("frbutton_setsize: o %p\n", o
));
177 if ((FindTagItem(GA_Width
, msg
->ops_AttrList
) == NULL
||
178 FindTagItem(GA_Height
, msg
->ops_AttrList
) == NULL
) &&
179 image
&& g
->Flags
& GFLG_GADGIMAGE
)
181 struct IBox contents
, frame
;
182 struct DrawInfo
*dri
= msg
->ops_GInfo
? msg
->ops_GInfo
->gi_DrInfo
: NULL
;
183 BOOL do_framebox
= TRUE
;
185 DEBUG_FRBUTTON(dprintf("frbutton_setsize: image %p flags 0x%lx\n", image
,g
->Flags
));
187 dri
= (APTR
)GetTagData(GA_DrawInfo
, (IPTR
)dri
, msg
->ops_AttrList
);
191 switch (g
->Flags
& GFLG_LABELMASK
)
193 //case GFLG_LABELITEXT:
196 case GFLG_LABELSTRING
:
200 STRPTR text
= (STRPTR
)g
->GadgetText
;
203 SetFont(&rp
, dri
->dri_Font
);
205 contents
.Height
= dri
->dri_Font
->tf_YSize
;
206 contents
.Width
= LabelWidth(&rp
, text
, strlen(text
), IntuitionBase
);
214 case GFLG_LABELIMAGE
:
215 contents
.Width
= ((struct Image
*)g
->GadgetText
)->Width
;
216 contents
.Height
= ((struct Image
*)g
->GadgetText
)->Height
;
224 DEBUG_FRBUTTON(dprintf("frbutton_setsize: do_framebox %d contents %d %d %d %d\n", do_framebox
,
225 contents
.Left
,contents
.Top
, contents
.Width
,contents
.Height
));
228 struct impFrameBox method
;
231 method
.MethodID
= IM_FRAMEBOX
;
232 method
.imp_ContentsBox
= &contents
;
233 method
.imp_FrameBox
= &frame
;
234 method
.imp_DrInfo
= dri
;
235 method
.imp_FrameFlags
= 0;
237 if (DoMethodA((Object
*)image
, (Msg
)&method
))
240 height
= frame
.Height
;
241 DEBUG_FRBUTTON(dprintf("frbutton_setsize: ok, w=%d h=%d l=%d t=%d\n", width
, height
, frame
.Left
, frame
.Top
));
245 width
= image
->Width
;
246 height
= image
->Height
;
247 DEBUG_FRBUTTON(dprintf("frbutton_setsize: bad, w=%d h=%d\n", width
, height
));
256 /***********************************************************************************/
258 IPTR
FrButtonClass__GM_HITTEST(Class
*cl
, struct Gadget
* g
, struct gpHitTest
* msg
)
260 struct Image
*image
= (struct Image
*)g
->GadgetRender
;
262 IPTR retval
= GMR_GADGETHIT
;
266 if (image
->Depth
== CUSTOMIMAGEDEPTH
)
268 struct impHitTest imph
;
270 imph
.MethodID
= IM_HITFRAME
;
271 imph
.imp_Point
.X
= msg
->gpht_Mouse
.X
;
272 imph
.imp_Point
.Y
= msg
->gpht_Mouse
.Y
;
274 retval
= DoMethodA((Object
*)image
, (Msg
)&imph
) ? GMR_GADGETHIT
: 0;
281 /****************************************************************************/
283 IPTR
FrButtonClass__OM_NEW(Class
*cl
, Object
*o
, struct opSet
*msg
)
285 struct Gadget
*g
= (struct Gadget
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
288 frbutton_setsize(cl
, g
, msg
);
293 /***********************************************************************************/
295 IPTR
FrButtonClass__OM_SET(Class
*cl
, Object
*o
, struct opSet
*msg
)
297 IPTR retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
299 /* If we have been subclassed, OM_UPDATE should not cause a GM_RENDER
300 * because it would circumvent the subclass from fully overriding it.
301 * The check of cl == OCLASS(o) should fail if we have been
302 * subclassed, and we have gotten here via DoSuperMethodA().
304 if ( retval
&& ( (msg
->MethodID
!= OM_UPDATE
) || (cl
== OCLASS(o
)) ) )
306 struct GadgetInfo
*gi
= msg
->ops_GInfo
;
310 struct RastPort
*rp
= ObtainGIRPort(gi
);
314 struct gpRender method
;
316 method
.MethodID
= GM_RENDER
;
317 method
.gpr_GInfo
= gi
;
318 method
.gpr_RPort
= rp
;
319 method
.gpr_Redraw
= GREDRAW_REDRAW
;
321 DoMethodA(o
, (Msg
)&method
);
331 /****************************************************************************/