2 Copyright © 1995-2011, 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 /****************************************************************************/
49 IPTR
FrButtonClass__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
51 /* We will let the AROS gadgetclass test if it is safe to render */
52 /* FIXME: if ( DoSuperMethodA(cl, o, (Msg *)msg) != 0)
54 struct IntuitionBase
*IntuitionBase
= (struct IntuitionBase
*)cl
->cl_UserData
;
55 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
56 UWORD
*pens
= msg
->gpr_GInfo
->gi_DrInfo
->dri_Pens
;
57 struct RastPort
*rp
= msg
->gpr_RPort
;
58 struct IBox container
;
62 dprintf("frbutton_render: rp @ %p, rp->layer @ %p\n", rp
, rp
->Layer
);
64 dprintf("frbutton_render: rp == NULL!\n");
66 if (msg
->gpr_GInfo
->gi_Window
)
67 dprintf("frbutton_render: msg->gpr_GInfo->gi_Window @ %p, msg->gpr_GInfo->gi_Window->WLayer @ %p\n", msg
->gpr_GInfo
->gi_Window
, msg
->gpr_GInfo
->gi_Window
->WLayer
);
69 dprintf("frbutton_render: msg->gpr_GInfo->gi_Window == NULL!\n");
71 if (msg
->gpr_GInfo
->gi_Requester
)
72 dprintf("frbutton_render: msg->gpr_GInfo->gi_Requester @ %p, msg->gpr_GInfo->gi_Requester->ReqLayer @ %p\n", msg
->gpr_GInfo
->gi_Requester
, msg
->gpr_GInfo
->gi_Requester
->ReqLayer
);
74 dprintf("frbutton_render: msg->gpr_GInfo->gi_Requester == NULL!\n");
76 if (msg
->gpr_GInfo
->gi_RastPort
)
77 dprintf("frbutton_render: msg->gpr_GInfo->gi_RastPort @ %p, msg->gpr_GInfo->gi_RastPort->Layer @ %p\n", msg
->gpr_GInfo
->gi_RastPort
, msg
->gpr_GInfo
->gi_RastPort
->Layer
);
79 dprintf("frbutton_render: msg->gpr_GInfo->gi_RastPort == NULL!\n");
84 GetGadgetIBox(g
, msg
->gpr_GInfo
, &container
);
86 if (container
.Width
<= 1 || container
.Height
<= 1)
89 if ((g
->Flags
& GFLG_GADGIMAGE
) == 0) /* not an image-button */
92 if ((g
->SelectRender
!= NULL
) && (g
->Flags
& GFLG_SELECTED
))
94 ((struct Border
*)g
->SelectRender
),
97 else if (g
->GadgetRender
!= NULL
)
99 ((struct Border
*)g
->GadgetRender
),
103 else /* GFLG_GADGIMAGE set */
105 struct TagItem image_tags
[] =
107 {IA_Width
, g
->Width
},
108 {IA_Height
, g
->Height
},
112 if ((g
->SelectRender
!= NULL
) &&
113 (g
->Flags
& GFLG_SELECTED
)) /* render selected image */
116 struct Image
*sr
= g
->SelectRender
;
118 if(sr
->Depth
== CUSTOMIMAGEDEPTH
)
120 // ONLY DO THIS FOR REAL IMAGE OBJECTS (cyfm 31/12/02)
121 /* center image position, we assume image top and left is 0 */
122 SetAttrsA(g
->SelectRender
, image_tags
);
125 x
= container
.Left
+ (container
.Width
/ 2) - (sr
->Width
/ 2);
126 y
= container
.Top
+ (container
.Height
/ 2) - (sr
->Height
/ 2);
132 msg
->gpr_GInfo
->gi_DrInfo
);
134 else if ( g
->GadgetRender
!= NULL
) /* render normal image */
137 struct Image
*gr
= g
->GadgetRender
;
139 if(gr
->Depth
== CUSTOMIMAGEDEPTH
)
141 // ONLY DO THIS FOR REAL IMAGE OBJECTS (cyfm 31/12/02)
142 /* center image position, we assume image top and left is 0 */
143 SetAttrsA(gr
, image_tags
);
146 x
= container
.Left
+ (container
.Width
/ 2) - (gr
->Width
/ 2);
147 y
= container
.Top
+ (container
.Height
/ 2) - (gr
->Height
/ 2);
152 ((g
->Flags
& GFLG_SELECTED
) ? IDS_SELECTED
: IDS_NORMAL
),
153 msg
->gpr_GInfo
->gi_DrInfo
);
158 SetABPenDrMd(rp
, pens
[TEXTPEN
], 0, JAM1
);
160 printgadgetlabel(cl
, (Object
*)g
, msg
, IntuitionBase
);
162 if ( g
->Flags
& GFLG_DISABLED
)
164 UWORD pattern
[] = { 0x8888, 0x2222 };
167 SetAPen( rp
, pens
[SHADOWPEN
] );
168 SetAfPt( rp
, pattern
, 1);
170 /* render disable pattern */
174 container
.Left
+ container
.Width
- 1,
175 container
.Top
+ container
.Height
- 1 );
182 /***********************************************************************************/
184 void frbutton_setsize(Class
*cl
, struct Gadget
*g
, struct opSet
*msg
)
186 struct IntuitionBase
*IntuitionBase
= (struct IntuitionBase
*)cl
->cl_UserData
;
187 struct GfxBase
*GfxBase
= GetPrivIBase(IntuitionBase
)->GfxBase
;
188 struct Library
*UtilityBase
= GetPrivIBase(IntuitionBase
)->UtilityBase
;
189 struct Image
*image
= (struct Image
*)g
->GadgetRender
;
191 DEBUG_FRBUTTON(dprintf("frbutton_setsize: g %p\n", g
));
193 if ((FindTagItem(GA_Width
, msg
->ops_AttrList
) == NULL
||
194 FindTagItem(GA_Height
, msg
->ops_AttrList
) == NULL
) &&
195 image
&& g
->Flags
& GFLG_GADGIMAGE
)
197 struct IBox contents
, frame
;
198 struct DrawInfo
*dri
= msg
->ops_GInfo
? msg
->ops_GInfo
->gi_DrInfo
: NULL
;
199 BOOL do_framebox
= TRUE
;
201 DEBUG_FRBUTTON(dprintf("frbutton_setsize: image %p flags 0x%lx\n", image
,g
->Flags
));
203 dri
= (APTR
)GetTagData(GA_DrawInfo
, (IPTR
)dri
, msg
->ops_AttrList
);
207 switch (g
->Flags
& GFLG_LABELMASK
)
209 //case GFLG_LABELITEXT:
212 case GFLG_LABELSTRING
:
216 STRPTR text
= (STRPTR
)g
->GadgetText
;
219 SetFont(&rp
, dri
->dri_Font
);
221 contents
.Height
= dri
->dri_Font
->tf_YSize
;
222 contents
.Width
= LabelWidth(&rp
, text
, strlen(text
), IntuitionBase
);
228 case GFLG_LABELIMAGE
:
229 contents
.Width
= ((struct Image
*)g
->GadgetText
)->Width
;
230 contents
.Height
= ((struct Image
*)g
->GadgetText
)->Height
;
238 DEBUG_FRBUTTON(dprintf("frbutton_setsize: do_framebox %d contents %d %d %d %d\n", do_framebox
,
239 contents
.Left
,contents
.Top
, contents
.Width
,contents
.Height
));
242 struct impFrameBox method
;
245 method
.MethodID
= IM_FRAMEBOX
;
246 method
.imp_ContentsBox
= &contents
;
247 method
.imp_FrameBox
= &frame
;
248 method
.imp_DrInfo
= dri
;
249 method
.imp_FrameFlags
= 0;
251 if (DoMethodA((Object
*)image
, (Msg
)&method
))
254 height
= frame
.Height
;
255 DEBUG_FRBUTTON(dprintf("frbutton_setsize: ok, w=%d h=%d l=%d t=%d\n", width
, height
, frame
.Left
, frame
.Top
));
259 width
= image
->Width
;
260 height
= image
->Height
;
261 DEBUG_FRBUTTON(dprintf("frbutton_setsize: bad, w=%d h=%d\n", width
, height
));
270 /***********************************************************************************/
272 IPTR
FrButtonClass__GM_HITTEST(Class
*cl
, struct Gadget
* g
, struct gpHitTest
* msg
)
274 struct Image
*image
= (struct Image
*)g
->GadgetRender
;
276 DEBUG_FRBUTTON(dprintf("FrButtonClass__GM_HITTEST()\n"));
278 IPTR retval
= GMR_GADGETHIT
;
282 if (image
->Depth
== CUSTOMIMAGEDEPTH
)
284 struct impHitTest imph
;
286 imph
.MethodID
= IM_HITFRAME
;
287 imph
.imp_Point
.X
= msg
->gpht_Mouse
.X
;
288 imph
.imp_Point
.Y
= msg
->gpht_Mouse
.Y
;
290 retval
= DoMethodA((Object
*)image
, (Msg
)&imph
) ? GMR_GADGETHIT
: 0;
297 /****************************************************************************/
299 IPTR
FrButtonClass__OM_NEW(Class
*cl
, Object
*o
, struct opSet
*msg
)
301 struct Gadget
*g
= (struct Gadget
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
303 DEBUG_FRBUTTON(dprintf("FrButtonClass__OM_NEW()\n"));
307 frbutton_setsize(cl
, g
, msg
);
312 /***********************************************************************************/
314 IPTR
FrButtonClass__OM_SET(Class
*cl
, Object
*o
, struct opSet
*msg
)
316 struct IntuitionBase
*IntuitionBase
= (struct IntuitionBase
*)cl
->cl_UserData
;
317 IPTR retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
319 DEBUG_FRBUTTON(dprintf("FrButtonClass__OM_SET()\n"));
321 /* If we have been subclassed, OM_UPDATE should not cause a GM_RENDER
322 * because it would circumvent the subclass from fully overriding it.
323 * The check of cl == OCLASS(o) should fail if we have been
324 * subclassed, and we have gotten here via DoSuperMethodA().
326 if ( retval
&& ( (msg
->MethodID
!= OM_UPDATE
) || (cl
== OCLASS(o
)) ) )
328 struct GadgetInfo
*gi
= msg
->ops_GInfo
;
332 struct RastPort
*rp
= ObtainGIRPort(gi
);
336 struct gpRender method
;
338 method
.MethodID
= GM_RENDER
;
339 method
.gpr_GInfo
= gi
;
340 method
.gpr_RPort
= rp
;
341 method
.gpr_Redraw
= GREDRAW_REDRAW
;
343 DoMethodA(o
, (Msg
)&method
);
353 /****************************************************************************/