added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / intuition / frbuttonclass.c
blobd6bb8e3b371944f48cac153b56a4ec0e16e996c8
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(dprintf("frbutton_render: rp %p[%p] win %p[%p] req %p[%p] gi->rp %p[%p]\n",
65 rp, rp->Layer,
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));
69 SANITY_CHECK(rp)
71 GetGadgetIBox(g, msg->gpr_GInfo, &container);
73 if (container.Width <= 1 || container.Height <= 1)
74 return (IPTR)0;
76 if ((g->Flags & GFLG_GADGIMAGE) == 0) /* not an image-button */
78 /* draw border */
79 if ((g->SelectRender != NULL ) && (g->Flags & GFLG_SELECTED))
80 DrawBorder(rp,
81 ((struct Border *)g->SelectRender),
82 container.Left,
83 container.Top);
84 else if (g->GadgetRender != NULL)
85 DrawBorder(rp,
86 ((struct Border *)g->GadgetRender),
87 container.Left,
88 container.Top);
90 else /* GFLG_GADGIMAGE set */
92 struct TagItem image_tags[] =
94 {IA_Width , g->Width },
95 {IA_Height, g->Height},
96 {TAG_DONE }
99 if ((g->SelectRender != NULL) &&
100 (g->Flags & GFLG_SELECTED)) /* render selected image */
102 ULONG x, y;
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);
115 DrawImageState(rp,
117 x, y,
118 IDS_SELECTED,
119 msg->gpr_GInfo->gi_DrInfo );
121 else if ( g->GadgetRender != NULL ) /* render normal image */
123 ULONG x, y;
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);
136 DrawImageState(rp,
138 x, y,
139 ((g->Flags & GFLG_SELECTED) ? IDS_SELECTED : IDS_NORMAL ),
140 msg->gpr_GInfo->gi_DrInfo);
144 /* print label */
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 };
153 SetDrMd( rp, JAM1 );
154 SetAPen( rp, pens[SHADOWPEN] );
155 SetAfPt( rp, pattern, 1);
157 /* render disable pattern */
158 RectFill(rp,
159 container.Left,
160 container.Top,
161 container.Left + container.Width - 1,
162 container.Top + container.Height - 1 );
164 /* } FIXME */
166 return (IPTR)0;
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);
188 contents.Left = 0;
189 contents.Top = 0;
191 switch (g->Flags & GFLG_LABELMASK)
193 //case GFLG_LABELITEXT:
194 //break;
196 case GFLG_LABELSTRING:
197 if (dri)
199 struct RastPort rp;
200 STRPTR text = (STRPTR)g->GadgetText;
202 InitRastPort(&rp);
203 SetFont(&rp, dri->dri_Font);
205 contents.Height = dri->dri_Font->tf_YSize;
206 contents.Width = LabelWidth(&rp, text, strlen(text), IntuitionBase);
208 DeinitRastPort(&rp);
210 else
211 do_framebox = FALSE;
212 break;
214 case GFLG_LABELIMAGE:
215 contents.Width = ((struct Image *)g->GadgetText)->Width;
216 contents.Height = ((struct Image *)g->GadgetText)->Height;
217 break;
219 default:
220 do_framebox = FALSE;
221 break;
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));
226 if (do_framebox)
228 struct impFrameBox method;
229 int width, height;
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))
239 width = frame.Width;
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));
243 else
245 width = image->Width;
246 height = image->Height;
247 DEBUG_FRBUTTON(dprintf("frbutton_setsize: bad, w=%d h=%d\n", width, height));
250 g->Width = width;
251 g->Height = 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;
264 if (image)
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;
278 return retval;
281 /****************************************************************************/
283 IPTR FrButtonClass__OM_NEW(Class *cl, Object *o, struct opSet *msg)
285 struct Gadget *g = (struct Gadget *)DoSuperMethodA(cl, o, (Msg)msg);
286 if (g)
288 frbutton_setsize(cl, g, msg);
290 return (IPTR)g;
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;
308 if (gi)
310 struct RastPort *rp = ObtainGIRPort(gi);
312 if (rp)
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);
323 ReleaseGIRPort(rp);
328 return retval;
331 /****************************************************************************/