Check for SYS/GL during library init. Reason is that
[AROS.git] / rom / intuition / frbuttonclass.c
blob2512d8a35135566dbbbecdded10396cde4d36489
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 /****************************************************************************/
9 #include <exec/types.h>
11 #include <dos/dos.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>
36 #include <string.h>
38 #ifndef __MORPHOS__
39 #include "intuition_intern.h"
40 #include <aros/asmcall.h>
41 #include <proto/alib.h>
42 #include "gadgets.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)
53 { */
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;
60 DEBUG_FRBUTTON(
61 if (rp)
62 dprintf("frbutton_render: rp @ %p, rp->layer @ %p\n", rp, rp->Layer);
63 else
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);
68 else
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);
73 else
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);
78 else
79 dprintf("frbutton_render: msg->gpr_GInfo->gi_RastPort == NULL!\n");
82 SANITY_CHECKR(rp, 0)
84 GetGadgetIBox(g, msg->gpr_GInfo, &container);
86 if (container.Width <= 1 || container.Height <= 1)
87 return (IPTR)0;
89 if ((g->Flags & GFLG_GADGIMAGE) == 0) /* not an image-button */
91 /* draw border */
92 if ((g->SelectRender != NULL ) && (g->Flags & GFLG_SELECTED))
93 DrawBorder(rp,
94 ((struct Border *)g->SelectRender),
95 container.Left,
96 container.Top);
97 else if (g->GadgetRender != NULL)
98 DrawBorder(rp,
99 ((struct Border *)g->GadgetRender),
100 container.Left,
101 container.Top);
103 else /* GFLG_GADGIMAGE set */
105 struct TagItem image_tags[] =
107 {IA_Width , g->Width },
108 {IA_Height, g->Height},
109 {TAG_DONE }
112 if ((g->SelectRender != NULL) &&
113 (g->Flags & GFLG_SELECTED)) /* render selected image */
115 ULONG x, y;
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);
128 DrawImageState(rp,
130 x, y,
131 IDS_SELECTED,
132 msg->gpr_GInfo->gi_DrInfo );
134 else if ( g->GadgetRender != NULL ) /* render normal image */
136 ULONG x, y;
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);
149 DrawImageState(rp,
151 x, y,
152 ((g->Flags & GFLG_SELECTED) ? IDS_SELECTED : IDS_NORMAL ),
153 msg->gpr_GInfo->gi_DrInfo);
157 /* print label */
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 };
166 SetDrMd( rp, JAM1 );
167 SetAPen( rp, pens[SHADOWPEN] );
168 SetAfPt( rp, pattern, 1);
170 /* render disable pattern */
171 RectFill(rp,
172 container.Left,
173 container.Top,
174 container.Left + container.Width - 1,
175 container.Top + container.Height - 1 );
177 /* } FIXME */
179 return (IPTR)0;
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);
204 contents.Left = 0;
205 contents.Top = 0;
207 switch (g->Flags & GFLG_LABELMASK)
209 //case GFLG_LABELITEXT:
210 //break;
212 case GFLG_LABELSTRING:
213 if (dri)
215 struct RastPort rp;
216 STRPTR text = (STRPTR)g->GadgetText;
218 InitRastPort(&rp);
219 SetFont(&rp, dri->dri_Font);
221 contents.Height = dri->dri_Font->tf_YSize;
222 contents.Width = LabelWidth(&rp, text, strlen(text), IntuitionBase);
224 else
225 do_framebox = FALSE;
226 break;
228 case GFLG_LABELIMAGE:
229 contents.Width = ((struct Image *)g->GadgetText)->Width;
230 contents.Height = ((struct Image *)g->GadgetText)->Height;
231 break;
233 default:
234 do_framebox = FALSE;
235 break;
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));
240 if (do_framebox)
242 struct impFrameBox method;
243 int width, height;
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))
253 width = frame.Width;
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));
257 else
259 width = image->Width;
260 height = image->Height;
261 DEBUG_FRBUTTON(dprintf("frbutton_setsize: bad, w=%d h=%d\n", width, height));
264 g->Width = width;
265 g->Height = 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;
280 if (image)
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;
294 return retval;
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"));
305 if (g)
307 frbutton_setsize(cl, g, msg);
309 return (IPTR)g;
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;
330 if (gi)
332 struct RastPort *rp = ObtainGIRPort(gi);
334 if (rp)
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);
345 ReleaseGIRPort(rp);
350 return retval;
353 /****************************************************************************/