Replaced Popscren with a custom pop-up list for selecting public screen. Now it conta...
[tangerine.git] / rom / intuition / frbuttonclass.c
blob25ca772fb948dfe1d9fabca0ed0dabfe112f1f3a
1 /*
2 Copyright © 1995-2005, 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 #undef IntuitionBase
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 */
57 #warning FIXME:
58 /* FIXME: if ( DoSuperMethodA(cl, o, (Msg *)msg) != 0)
59 { */
60 UWORD *pens = msg->gpr_GInfo->gi_DrInfo->dri_Pens;
61 struct RastPort *rp = msg->gpr_RPort;
62 struct IBox container;
64 DEBUG_FRBUTTON(
65 if (rp)
66 dprintf("frbutton_render: rp @ %p, rp->layer @ %p\n", rp, rp->Layer);
67 else
68 dprintf("frbutton_render: rp == NULL!\n");
70 if (msg->gpr_GInfo->gi_Window)
71 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);
72 else
73 dprintf("frbutton_render: msg->gpr_GInfo->gi_Window == NULL!\n");
75 if (msg->gpr_GInfo->gi_Requester)
76 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);
77 else
78 dprintf("frbutton_render: msg->gpr_GInfo->gi_Requester == NULL!\n");
80 if (msg->gpr_GInfo->gi_RastPort)
81 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);
82 else
83 dprintf("frbutton_render: msg->gpr_GInfo->gi_RastPort == NULL!\n");
86 SANITY_CHECKR(rp, 0)
88 GetGadgetIBox(g, msg->gpr_GInfo, &container);
90 if (container.Width <= 1 || container.Height <= 1)
91 return (IPTR)0;
93 if ((g->Flags & GFLG_GADGIMAGE) == 0) /* not an image-button */
95 /* draw border */
96 if ((g->SelectRender != NULL ) && (g->Flags & GFLG_SELECTED))
97 DrawBorder(rp,
98 ((struct Border *)g->SelectRender),
99 container.Left,
100 container.Top);
101 else if (g->GadgetRender != NULL)
102 DrawBorder(rp,
103 ((struct Border *)g->GadgetRender),
104 container.Left,
105 container.Top);
107 else /* GFLG_GADGIMAGE set */
109 struct TagItem image_tags[] =
111 {IA_Width , g->Width },
112 {IA_Height, g->Height},
113 {TAG_DONE }
116 if ((g->SelectRender != NULL) &&
117 (g->Flags & GFLG_SELECTED)) /* render selected image */
119 ULONG x, y;
120 struct Image *sr = g->SelectRender;
122 if(sr->Depth == CUSTOMIMAGEDEPTH)
124 // ONLY DO THIS FOR REAL IMAGE OBJECTS (cyfm 31/12/02)
125 /* center image position, we assume image top and left is 0 */
126 SetAttrsA(g->SelectRender, image_tags);
129 x = container.Left + (container.Width / 2) - (sr->Width / 2);
130 y = container.Top + (container.Height / 2) - (sr->Height / 2);
132 DrawImageState(rp,
134 x, y,
135 IDS_SELECTED,
136 msg->gpr_GInfo->gi_DrInfo );
138 else if ( g->GadgetRender != NULL ) /* render normal image */
140 ULONG x, y;
141 struct Image *gr = g->GadgetRender;
143 if(gr->Depth == CUSTOMIMAGEDEPTH)
145 // ONLY DO THIS FOR REAL IMAGE OBJECTS (cyfm 31/12/02)
146 /* center image position, we assume image top and left is 0 */
147 SetAttrsA(gr, image_tags);
150 x = container.Left + (container.Width / 2) - (gr->Width / 2);
151 y = container.Top + (container.Height / 2) - (gr->Height / 2);
153 DrawImageState(rp,
155 x, y,
156 ((g->Flags & GFLG_SELECTED) ? IDS_SELECTED : IDS_NORMAL ),
157 msg->gpr_GInfo->gi_DrInfo);
161 /* print label */
162 SetABPenDrMd(rp, pens[TEXTPEN], 0, JAM1);
164 printgadgetlabel(cl, (Object *)g, msg, IntuitionBase);
166 if ( g->Flags & GFLG_DISABLED )
168 UWORD pattern[] = { 0x8888, 0x2222 };
170 SetDrMd( rp, JAM1 );
171 SetAPen( rp, pens[SHADOWPEN] );
172 SetAfPt( rp, pattern, 1);
174 /* render disable pattern */
175 RectFill(rp,
176 container.Left,
177 container.Top,
178 container.Left + container.Width - 1,
179 container.Top + container.Height - 1 );
181 /* } FIXME */
183 return (IPTR)0;
186 /***********************************************************************************/
188 void frbutton_setsize(Class *cl, struct Gadget *g, struct opSet *msg)
190 struct Image *image = (struct Image *)g->GadgetRender;
192 DEBUG_FRBUTTON(dprintf("frbutton_setsize: g %p\n", g));
194 if ((FindTagItem(GA_Width, msg->ops_AttrList) == NULL ||
195 FindTagItem(GA_Height, msg->ops_AttrList) == NULL) &&
196 image && g->Flags & GFLG_GADGIMAGE)
198 struct IBox contents, frame;
199 struct DrawInfo *dri = msg->ops_GInfo ? msg->ops_GInfo->gi_DrInfo : NULL;
200 BOOL do_framebox = TRUE;
202 DEBUG_FRBUTTON(dprintf("frbutton_setsize: image %p flags 0x%lx\n", image,g->Flags));
204 dri = (APTR)GetTagData(GA_DrawInfo, (IPTR)dri, msg->ops_AttrList);
205 contents.Left = 0;
206 contents.Top = 0;
208 switch (g->Flags & GFLG_LABELMASK)
210 //case GFLG_LABELITEXT:
211 //break;
213 case GFLG_LABELSTRING:
214 if (dri)
216 struct RastPort rp;
217 STRPTR text = (STRPTR)g->GadgetText;
219 InitRastPort(&rp);
220 SetFont(&rp, dri->dri_Font);
222 contents.Height = dri->dri_Font->tf_YSize;
223 contents.Width = LabelWidth(&rp, text, strlen(text), IntuitionBase);
225 DeinitRastPort(&rp);
227 else
228 do_framebox = FALSE;
229 break;
231 case GFLG_LABELIMAGE:
232 contents.Width = ((struct Image *)g->GadgetText)->Width;
233 contents.Height = ((struct Image *)g->GadgetText)->Height;
234 break;
236 default:
237 do_framebox = FALSE;
238 break;
241 DEBUG_FRBUTTON(dprintf("frbutton_setsize: do_framebox %d contents %d %d %d %d\n", do_framebox,
242 contents.Left,contents.Top, contents.Width,contents.Height));
243 if (do_framebox)
245 struct impFrameBox method;
246 int width, height;
248 method.MethodID = IM_FRAMEBOX;
249 method.imp_ContentsBox = &contents;
250 method.imp_FrameBox = &frame;
251 method.imp_DrInfo = dri;
252 method.imp_FrameFlags = 0;
254 if (DoMethodA((Object *)image, (Msg)&method))
256 width = frame.Width;
257 height = frame.Height;
258 DEBUG_FRBUTTON(dprintf("frbutton_setsize: ok, w=%d h=%d l=%d t=%d\n", width, height, frame.Left, frame.Top));
260 else
262 width = image->Width;
263 height = image->Height;
264 DEBUG_FRBUTTON(dprintf("frbutton_setsize: bad, w=%d h=%d\n", width, height));
267 g->Width = width;
268 g->Height = height;
273 /***********************************************************************************/
275 IPTR FrButtonClass__GM_HITTEST(Class *cl, struct Gadget * g, struct gpHitTest * msg)
277 struct Image *image = (struct Image *)g->GadgetRender;
279 DEBUG_FRBUTTON(dprintf("FrButtonClass__GM_HITTEST()\n"));
281 IPTR retval = GMR_GADGETHIT;
283 if (image)
285 if (image->Depth == CUSTOMIMAGEDEPTH)
287 struct impHitTest imph;
289 imph.MethodID = IM_HITFRAME;
290 imph.imp_Point.X = msg->gpht_Mouse.X;
291 imph.imp_Point.Y = msg->gpht_Mouse.Y;
293 retval = DoMethodA((Object *)image, (Msg)&imph) ? GMR_GADGETHIT : 0;
297 return retval;
300 /****************************************************************************/
302 IPTR FrButtonClass__OM_NEW(Class *cl, Object *o, struct opSet *msg)
304 struct Gadget *g = (struct Gadget *)DoSuperMethodA(cl, o, (Msg)msg);
306 DEBUG_FRBUTTON(dprintf("FrButtonClass__OM_NEW()\n"));
308 if (g)
310 frbutton_setsize(cl, g, msg);
312 return (IPTR)g;
315 /***********************************************************************************/
317 IPTR FrButtonClass__OM_SET(Class *cl, Object *o, struct opSet *msg)
319 IPTR retval = DoSuperMethodA(cl, o, (Msg)msg);
321 DEBUG_FRBUTTON(dprintf("FrButtonClass__OM_SET()\n"));
323 /* If we have been subclassed, OM_UPDATE should not cause a GM_RENDER
324 * because it would circumvent the subclass from fully overriding it.
325 * The check of cl == OCLASS(o) should fail if we have been
326 * subclassed, and we have gotten here via DoSuperMethodA().
328 if ( retval && ( (msg->MethodID != OM_UPDATE) || (cl == OCLASS(o)) ) )
330 struct GadgetInfo *gi = msg->ops_GInfo;
332 if (gi)
334 struct RastPort *rp = ObtainGIRPort(gi);
336 if (rp)
338 struct gpRender method;
340 method.MethodID = GM_RENDER;
341 method.gpr_GInfo = gi;
342 method.gpr_RPort = rp;
343 method.gpr_Redraw = GREDRAW_REDRAW;
345 DoMethodA(o, (Msg)&method);
347 ReleaseGIRPort(rp);
352 return retval;
355 /****************************************************************************/