revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / gadgets / aroscheckbox / checkboxclass.c
blob04345723676f98a656962550e8f557b21f9c72e6
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: AROS specific checkbox class implementation.
6 Lang: English
7 */
9 /****************************************************************************************/
11 #undef SDEBUG
12 #define SDEBUG 0
13 #undef DEBUG
14 #define DEBUG 0
15 #include <aros/debug.h>
17 #define USE_BOOPSI_STUBS
19 /****************************************************************************************/
21 #include <proto/exec.h>
22 #include <exec/libraries.h>
23 #include <proto/intuition.h>
24 #include <intuition/classes.h>
25 #include <intuition/classusr.h>
26 #include <intuition/imageclass.h>
27 #include <intuition/intuition.h>
28 #include <gadgets/aroscheckbox.h>
29 #include <proto/graphics.h>
30 #include <graphics/rastport.h>
31 #include <graphics/text.h>
32 #include <proto/utility.h>
33 #include <utility/tagitem.h>
34 #include <devices/inputevent.h>
35 #include <libraries/gadtools.h>
36 #include <proto/alib.h>
38 #include "aroscheckbox_intern.h"
40 /****************************************************************************************/
42 #include <clib/boopsistubs.h>
44 /****************************************************************************************/
46 void drawimage(Class *cl, struct Gadget *gad, struct RastPort *rport,
47 BOOL checked, BOOL disabled)
49 struct CheckData *data = INST_DATA(cl, (Object *)gad);
50 struct Image *img;
51 ULONG state = IDS_NORMAL;
53 if (checked)
55 if (gad->SelectRender)
57 img = gad->SelectRender;
58 state = IDS_NORMAL;
60 else
62 img = gad->GadgetRender;
63 state = IDS_SELECTED;
66 else
68 img = gad->GadgetRender;
69 state = IDS_NORMAL;
72 if (disabled)
74 if ((gad->Flags & GFLG_IMAGEDISABLE) && (state == IDS_NORMAL))
76 state = IDS_DISABLED;
78 else if (gad->Flags & GFLG_IMAGEDISABLE)
80 state = IDS_SELECTEDDISABLED;
84 DrawImageState(rport, img, gad->LeftEdge, gad->TopEdge, state, data->dri);
86 /* Draw disabled pattern, if not supported by imageclass. */
87 if ((disabled) && !(gad->Flags & GFLG_IMAGEDISABLE))
89 drawdisabledpattern(rport, data->dri->dri_Pens[SHADOWPEN],
90 gad->LeftEdge, gad->TopEdge,
91 gad->Width, gad->Height
97 /****************************************************************************************/
99 IPTR AROSCheckbox__OM_SET(Class * cl, Object * obj, struct opSet * msg)
101 struct CheckData *data = INST_DATA(cl, obj);
102 struct TagItem *tag, *taglist = msg->ops_AttrList;
103 struct RastPort *rport;
104 IPTR retval = FALSE;
106 if (data->flags & CF_CustomImage)
108 tag = FindTagItem(GA_Image, taglist);
109 if (tag)
111 DisposeObject(G(obj)->GadgetRender);
112 G(obj)->GadgetRender = NULL;
113 data->flags &= ~CF_CustomImage;
117 if (msg->MethodID != OM_NEW)
118 retval = DoSuperMethodA(cl, obj, (Msg)msg);
120 while ((tag = NextTagItem(&taglist)))
122 switch (tag->ti_Tag)
124 case GA_Disabled:
125 retval = TRUE;
126 break;
128 case GA_DrawInfo:
129 if (msg->MethodID == OM_NEW)
130 data->dri = (struct DrawInfo *) tag->ti_Data;
131 break;
133 case GA_Image:
134 case GA_SelectRender:
135 retval = TRUE;
136 break;
138 case GA_LabelPlace:
139 if (msg->MethodID == OM_NEW)
140 data->labelplace = (LONG)tag->ti_Data;
141 break;
143 case AROSCB_Checked:
144 if (tag->ti_Data)
145 data->flags |= CF_Checked;
146 else
147 data->flags &= ~CF_Checked;
148 retval = TRUE;
149 break;
151 } /* switch (tag->ti_Tag) */
153 } /* while ((tag = NextTagItem(&taglist))) */
155 if (G(obj)->Width == 0)
156 G(obj)->Width = CHECKBOX_WIDTH;
157 if (G(obj)->Height == 0)
158 G(obj)->Height = CHECKBOX_HEIGHT;
160 /* Redraw ourself? */
162 if ((retval) && (msg->MethodID != OM_NEW) &&
163 ((msg->MethodID != OM_UPDATE) || (OCLASS(obj) == cl)))
165 rport = ObtainGIRPort(msg->ops_GInfo);
166 if (rport)
168 DoMethod(obj, GM_RENDER, (IPTR)msg->ops_GInfo, (IPTR)rport, GREDRAW_UPDATE);
169 ReleaseGIRPort(rport);
170 retval = FALSE;
174 return retval;
177 /****************************************************************************************/
179 IPTR AROSCheckbox__OM_GET(Class * cl, Object * obj, struct opGet * msg)
181 struct CheckData *data = INST_DATA(cl, obj);
183 if (msg->opg_AttrID == AROSCB_Checked)
185 *(msg->opg_Storage) = data->flags & CF_Checked;
186 return (IPTR)1UL;
188 else
189 return DoSuperMethodA(cl, obj, (Msg)msg);
192 /****************************************************************************************/
194 Object *AROSCheckbox__OM_NEW(Class *cl, Class *rootcl, struct opSet *msg)
196 struct CheckData *data;
197 struct TagItem tags[] =
199 {IA_Width , 0UL },
200 {IA_Height , 0UL },
201 {SYSIA_DrawInfo , 0UL },
202 {SYSIA_Which , CHECKIMAGE},
203 {TAG_DONE }
205 Object *obj;
207 //EnterFunc(bug("CheckBox::New()\n"));
209 obj = (Object *)DoSuperMethodA(cl, (Object *)rootcl, (Msg)msg);
210 if (!obj)
211 return NULL;
213 G(obj)->Activation |= GACT_RELVERIFY;
215 data = INST_DATA(cl, obj);
216 data->dri = NULL;
217 data->flags = 0;
218 AROSCheckbox__OM_SET(cl, obj, msg);
220 if (!G(obj)->GadgetRender)
222 tags[0].ti_Data = G(obj)->Width;
223 tags[1].ti_Data = G(obj)->Height;
224 tags[2].ti_Data = (IPTR) data->dri;
225 G(obj)->GadgetRender = (struct Image *) NewObjectA(NULL, SYSICLASS,
226 tags);
227 data->flags |= CF_CustomImage;
230 if ((!data->dri) || (!G(obj)->GadgetRender))
232 CoerceMethod(cl, obj, OM_DISPOSE);
233 return NULL;
236 ReturnPtr("CheckBox::New", Object *, obj);
239 /****************************************************************************************/
241 IPTR AROSCheckbox__OM_DISPOSE(Class *cl, Class *obj, struct opSet *msg)
243 struct CheckData *data = INST_DATA(cl, obj);
244 if (data->flags & CF_CustomImage)
246 DisposeObject(G(obj)->GadgetRender);
247 G(obj)->GadgetRender = NULL;
249 return DoSuperMethodA(cl, (Object *)obj, (Msg)msg);
252 /****************************************************************************************/
254 IPTR AROSCheckbox__GM_RENDER(Class * cl, Object * obj, struct gpRender * msg)
256 struct CheckData *data = INST_DATA(cl, obj);
257 IPTR result = TRUE;
259 /* Render image */
260 drawimage(cl, G(obj), msg->gpr_RPort,
261 data->flags&CF_Checked, G(obj)->Flags&GFLG_DISABLED);
263 /* Render gadget label */
264 if (msg->gpr_Redraw == GREDRAW_REDRAW)
266 result = renderlabel(G(obj), msg->gpr_RPort, data->labelplace);
269 return result;
272 /****************************************************************************************/
274 IPTR AROSCheckbox__GM_HANDLEINPUT(Class * cl, Object * obj, struct gpInput * msg)
276 struct CheckData *data = INST_DATA(cl, obj);
277 struct RastPort *rport;
278 IPTR retval = GMR_MEACTIVE;
280 if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE)
282 if (msg->gpi_IEvent->ie_Code == SELECTUP)
284 if (G(obj)->Flags & GFLG_SELECTED)
286 /* mouse is over gadget */
287 if (data->flags & CF_Checked)
288 data->flags &= ~CF_Checked;
289 else
290 data->flags |= CF_Checked;
291 *msg->gpi_Termination = data->flags&CF_Checked?TRUE:FALSE;
292 retval = GMR_NOREUSE | GMR_VERIFY;
294 else
296 /* mouse is not over gadget */
297 retval = GMR_NOREUSE;
300 else if (msg->gpi_IEvent->ie_Code == IECODE_NOBUTTON)
302 struct gpHitTest htmsg, *p_htmsg = &htmsg;
304 htmsg.MethodID = GM_HITTEST;
305 htmsg.gpht_GInfo = msg->gpi_GInfo;
306 htmsg.gpht_Mouse.X = msg->gpi_Mouse.X;
307 htmsg.gpht_Mouse.Y = msg->gpi_Mouse.Y;
309 if (DoMethodA(obj, (Msg) p_htmsg) != GMR_GADGETHIT)
311 if (G(obj)->Flags & GFLG_SELECTED)
313 rport = ObtainGIRPort(msg->gpi_GInfo);
314 if (rport)
316 drawimage(cl, G(obj), rport,
317 data->flags&CF_Checked, FALSE);
318 ReleaseGIRPort(rport);
320 G(obj)->Flags &= ~GFLG_SELECTED;
323 else
325 if (!(G(obj)->Flags & GFLG_SELECTED))
327 rport = ObtainGIRPort(msg->gpi_GInfo);
328 if (rport)
330 drawimage(cl, G(obj), rport,
331 (data->flags&CF_Checked)?FALSE:TRUE, FALSE);
332 ReleaseGIRPort(rport);
334 G(obj)->Flags |= GFLG_SELECTED;
338 } /* else if (msg->gpi_IEvent->ie_Code == IECODE_NOBUTTON) */
339 else if (msg->gpi_IEvent->ie_Code == MENUDOWN)
341 retval = GMR_REUSE;
344 } /* if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE) */
346 return retval;
349 /****************************************************************************************/
351 IPTR AROSCheckbox__GM_GOACTIVE(Class *cl, Object *obj, struct gpInput *msg)
353 struct CheckData *data = INST_DATA(cl, obj);
354 struct RastPort *rport;
356 G(obj)->Flags |= GFLG_SELECTED;
357 rport = ObtainGIRPort(msg->gpi_GInfo);
358 if (rport)
360 drawimage(cl, G(obj), rport,
361 (data->flags&CF_Checked)?FALSE:TRUE, FALSE);
362 ReleaseGIRPort(rport);
363 return (IPTR)GMR_MEACTIVE;
365 else
366 return (IPTR)GMR_NOREUSE;
369 /****************************************************************************************/
371 void AROSCheckbox__GM_GOINACTIVE(Class *cl, Object *obj, struct gpGoInactive *msg)
373 struct CheckData *data = INST_DATA(cl, obj);
374 struct RastPort *rport;
376 G(obj)->Flags &= ~GFLG_SELECTED;
377 rport = ObtainGIRPort(msg->gpgi_GInfo);
378 if (rport)
380 drawimage(cl, G(obj), rport,
381 data->flags & CF_Checked, FALSE
383 ReleaseGIRPort(rport);
387 /****************************************************************************************/