add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / gadtools / checkboxclass.c
blobbf5a65faee7014441f231ddbb90401c7f647ec34
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Internal GadTools checkbox class.
6 Lang: English
7 */
10 #include <proto/exec.h>
11 #include <exec/libraries.h>
12 #include <exec/memory.h>
13 #include <proto/dos.h>
14 #include <intuition/classes.h>
15 #include <intuition/classusr.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/imageclass.h>
18 #include <intuition/intuition.h>
19 #include <intuition/cghooks.h>
20 #include <graphics/rastport.h>
21 #include <graphics/text.h>
22 #include <utility/tagitem.h>
23 #include <devices/inputevent.h>
24 #include <proto/alib.h>
25 #include <proto/utility.h>
27 #include <string.h> /* memset() */
29 #define SDEBUG 0
30 #define DEBUG 0
31 #include <aros/debug.h>
33 #include "gadtools_intern.h"
35 /**********************************************************************************************/
37 #define CF_MouseOverGad 0x0001
38 #define CF_CustomImage 0x0002
40 #define GadToolsBase ((struct GadToolsBase_intern *)cl->cl_UserData)
42 /**********************************************************************************************/
44 STATIC VOID drawimage(Class *cl, struct Gadget *gad, struct RastPort *rp,
45 BOOL checked, BOOL disabled)
47 struct CheckBoxData *data;
48 struct Image *img;
49 ULONG state = IDS_NORMAL;
51 data = INST_DATA(cl, (Object *)gad);
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(rp, 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 DoDisabledPattern(rp,
90 gad->LeftEdge,
91 gad->TopEdge,
92 gad->LeftEdge + gad->Width - 1,
93 gad->TopEdge + gad->Height - 1,
94 data->dri->dri_Pens[SHADOWPEN],
95 GadToolsBase);
100 /**********************************************************************************************/
102 IPTR GTCheckBox__OM_SET(Class *cl, struct Gadget *g, struct opSet *msg)
104 struct CheckBoxData *data;
105 struct TagItem *tag;
106 const struct TagItem *taglist = msg->ops_AttrList;
107 struct RastPort *rp;
108 IPTR retval = FALSE;
110 data = INST_DATA(cl, g);
112 if (data->flags & CF_CustomImage)
114 tag = FindTagItem(GA_Image, taglist);
115 if (tag)
117 DisposeObject(g->GadgetRender);
118 g->GadgetRender = NULL;
119 data->flags &= ~CF_CustomImage;
123 if (msg->MethodID != OM_NEW)
124 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
126 while ((tag = NextTagItem(&taglist)))
128 switch (tag->ti_Tag)
130 case GA_Disabled:
131 retval = TRUE;
132 break;
134 case GA_DrawInfo:
135 if (msg->MethodID == OM_NEW)
136 data->dri = (struct DrawInfo *) tag->ti_Data;
137 break;
139 case GA_Image:
140 case GA_SelectRender:
141 retval = TRUE;
142 break;
144 case GA_LabelPlace:
145 if (msg->MethodID == OM_NEW)
146 data->labelplace = (LONG)tag->ti_Data;
147 break;
149 case GTCB_Checked:
150 if (tag->ti_Data)
151 g->Flags |= GFLG_SELECTED;
152 else
153 g->Flags &= ~GFLG_SELECTED;
154 retval = TRUE;
155 break;
157 } /* switch (tag->ti_Tag) */
159 } /* while ((tag = NextTagItem(&taglist))) */
161 if (g->Width == 0)
162 g->Width = CHECKBOX_WIDTH;
163 if (g->Height == 0)
164 g->Height = CHECKBOX_HEIGHT;
166 /* Redraw ourself? */
168 if ((retval) && (msg->MethodID != OM_NEW) &&
169 ((msg->MethodID != OM_UPDATE) || (OCLASS(g) == cl)))
171 rp = ObtainGIRPort(msg->ops_GInfo);
172 if (rp)
174 DoMethod((Object *)g, GM_RENDER, (IPTR) msg->ops_GInfo, (IPTR) rp, GREDRAW_UPDATE);
175 ReleaseGIRPort(rp);
176 retval = FALSE;
180 return retval;
183 /**********************************************************************************************/
185 IPTR GTCheckBox__OM_GET(Class *cl, struct Gadget *g, struct opGet *msg)
187 struct CheckBoxData *data;
188 IPTR retval;
190 data = INST_DATA(cl, g);
192 switch (msg->opg_AttrID)
194 case GTA_GadgetKind:
195 case GTA_ChildGadgetKind:
196 *(msg->opg_Storage) = CHECKBOX_KIND;
197 retval = 1UL;
198 break;
200 case GTCB_Checked:
201 *(msg->opg_Storage) = (g->Flags & GFLG_SELECTED) ? TRUE : FALSE;
202 retval = 1UL;
203 break;
205 default:
206 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
207 break;
210 return retval;
213 /**********************************************************************************************/
215 IPTR GTCheckBox__OM_NEW(Class *cl, Object *supercl, struct opSet *msg)
217 struct CheckBoxData *data;
218 struct TagItem tags[] =
220 {IA_Width , 0UL },
221 {IA_Height , 0UL },
222 {SYSIA_DrawInfo , 0UL },
223 {SYSIA_Which , CHECKIMAGE},
224 {TAG_DONE }
226 struct Gadget *g;
228 g = (struct Gadget *)DoSuperMethodA(cl, supercl, (Msg)msg);
229 if (!g)
230 return (IPTR)0;
232 g->Activation |= GACT_RELVERIFY;
234 data = INST_DATA(cl, g);
235 data->dri = NULL;
236 data->flags = 0;
237 GTCheckBox__OM_SET(cl, g, msg);
239 if (!g->GadgetRender)
241 tags[0].ti_Data = g->Width;
242 tags[1].ti_Data = g->Height;
243 tags[2].ti_Data = (IPTR) data->dri;
244 g->GadgetRender = (struct Image *) NewObjectA(NULL, SYSICLASS,
245 tags);
246 data->flags |= CF_CustomImage;
249 if ((!data->dri) || (!g->GadgetRender))
251 CoerceMethod(cl, (Object *)g, OM_DISPOSE);
252 g = NULL;
255 return (IPTR)g;
258 /**********************************************************************************************/
260 IPTR GTCheckBox__OM_DISPOSE(Class *cl, struct Gadget *g, Msg msg)
262 struct CheckBoxData *data;
263 IPTR retval;
265 data = INST_DATA(cl, g);
267 if (data->flags & CF_CustomImage)
269 DisposeObject(g->GadgetRender);
270 g->GadgetRender = NULL;
272 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
274 return retval;
277 /**********************************************************************************************/
279 IPTR GTCheckBox__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
281 struct CheckBoxData *data;
282 IPTR result = TRUE;
284 data = INST_DATA(cl, g);
286 /* Render image */
287 drawimage(cl, g, msg->gpr_RPort,
288 g->Flags&GFLG_SELECTED, g->Flags&GFLG_DISABLED);
290 /* Render gadget label */
291 if (msg->gpr_Redraw == GREDRAW_REDRAW)
293 result = renderlabel(GadToolsBase, g, msg->gpr_RPort, data->labelplace);
296 return result;
299 /**********************************************************************************************/
301 IPTR GTCheckBox__GM_GOACTIVE(Class *cl, struct Gadget *g, struct gpInput *msg)
303 struct CheckBoxData *data;
304 struct RastPort *rp;
305 IPTR retval;
307 data = INST_DATA(cl, g);
308 data->flags |= CF_MouseOverGad;
310 rp = ObtainGIRPort(msg->gpi_GInfo);
311 if (rp)
313 drawimage(cl, g, rp, (g->Flags&GFLG_SELECTED) ? FALSE : TRUE, FALSE);
314 ReleaseGIRPort(rp);
315 retval = GMR_MEACTIVE;
317 else
319 retval = GMR_NOREUSE;
322 return retval;
325 /**********************************************************************************************/
327 IPTR GTCheckBox__GM_HANDLEINPUT(Class *cl, struct Gadget *g, struct gpInput *msg)
329 struct CheckBoxData *data;
330 struct RastPort *rp;
331 IPTR retval = GMR_MEACTIVE;
333 data = INST_DATA(cl, g);
335 if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE)
337 if (msg->gpi_IEvent->ie_Code == SELECTUP)
339 if (data->flags & CF_MouseOverGad)
341 /* mouse is over gadget */
343 g->Flags ^= GFLG_SELECTED;
345 *msg->gpi_Termination = g->Flags&GFLG_SELECTED?TRUE:FALSE;
346 retval = GMR_NOREUSE | GMR_VERIFY;
348 else
350 /* mouse is not over gadget */
351 retval = GMR_NOREUSE;
354 else if (msg->gpi_IEvent->ie_Code == IECODE_NOBUTTON)
356 if ((msg->gpi_Mouse.X < 0) || (msg->gpi_Mouse.Y < 0) ||
357 (msg->gpi_Mouse.X >= g->Width ) || (msg->gpi_Mouse.Y >= g->Height))
359 if (data->flags & CF_MouseOverGad)
361 rp = ObtainGIRPort(msg->gpi_GInfo);
362 if (rp)
364 drawimage(cl, g, rp,
365 g->Flags&GFLG_SELECTED, FALSE);
366 ReleaseGIRPort(rp);
368 data->flags &= ~CF_MouseOverGad;
371 else
373 if (!(data->flags & CF_MouseOverGad))
375 rp = ObtainGIRPort(msg->gpi_GInfo);
376 if (rp)
378 drawimage(cl, g, rp,
379 (g->Flags&GFLG_SELECTED)?FALSE:TRUE, FALSE);
380 ReleaseGIRPort(rp);
382 data->flags |= CF_MouseOverGad;
386 } /* else if (msg->gpi_IEvent->ie_Code == IECODE_NOBUTTON) */
387 else if (msg->gpi_IEvent->ie_Code == MENUDOWN)
389 retval = GMR_NOREUSE;
392 } /* if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE) */
394 return retval;
397 /**********************************************************************************************/
399 IPTR GTCheckBox__GM_GOINACTIVE(Class *cl, struct Gadget *g, struct gpGoInactive *msg)
401 struct CheckBoxData *data;
402 struct RastPort *rp;
404 data = INST_DATA(cl, g);
405 data->flags &= ~CF_MouseOverGad;
406 rp = ObtainGIRPort(msg->gpgi_GInfo);
407 if (rp)
409 drawimage(cl, g, rp, g->Flags & GFLG_SELECTED, FALSE);
410 ReleaseGIRPort(rp);
413 return 0;
416 /**********************************************************************************************/