add more arm feature flags
[AROS.git] / workbench / libs / gadtools / checkboxclass.c
blobbadd0c122aec41f15e83e920f9ca5a0de8e2de80
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 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 IPTR retval;
189 switch (msg->opg_AttrID)
191 case GTA_GadgetKind:
192 case GTA_ChildGadgetKind:
193 *(msg->opg_Storage) = CHECKBOX_KIND;
194 retval = 1UL;
195 break;
197 case GTCB_Checked:
198 *(msg->opg_Storage) = (g->Flags & GFLG_SELECTED) ? TRUE : FALSE;
199 retval = 1UL;
200 break;
202 default:
203 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
204 break;
207 return retval;
210 /**********************************************************************************************/
212 IPTR GTCheckBox__OM_NEW(Class *cl, Object *supercl, struct opSet *msg)
214 struct CheckBoxData *data;
215 struct TagItem tags[] =
217 {IA_Width , 0UL },
218 {IA_Height , 0UL },
219 {SYSIA_DrawInfo , 0UL },
220 {SYSIA_Which , CHECKIMAGE},
221 {TAG_DONE }
223 struct Gadget *g;
225 g = (struct Gadget *)DoSuperMethodA(cl, supercl, (Msg)msg);
226 if (!g)
227 return (IPTR)0;
229 g->Activation |= GACT_RELVERIFY;
231 data = INST_DATA(cl, g);
232 data->dri = NULL;
233 data->flags = 0;
234 GTCheckBox__OM_SET(cl, g, msg);
236 if (!g->GadgetRender)
238 tags[0].ti_Data = g->Width;
239 tags[1].ti_Data = g->Height;
240 tags[2].ti_Data = (IPTR) data->dri;
241 g->GadgetRender = (struct Image *) NewObjectA(NULL, SYSICLASS,
242 tags);
243 data->flags |= CF_CustomImage;
246 if ((!data->dri) || (!g->GadgetRender))
248 CoerceMethod(cl, (Object *)g, OM_DISPOSE);
249 g = NULL;
252 return (IPTR)g;
255 /**********************************************************************************************/
257 IPTR GTCheckBox__OM_DISPOSE(Class *cl, struct Gadget *g, Msg msg)
259 struct CheckBoxData *data;
260 IPTR retval;
262 data = INST_DATA(cl, g);
264 if (data->flags & CF_CustomImage)
266 DisposeObject(g->GadgetRender);
267 g->GadgetRender = NULL;
269 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
271 return retval;
274 /**********************************************************************************************/
276 IPTR GTCheckBox__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
278 struct CheckBoxData *data;
279 IPTR result = TRUE;
281 data = INST_DATA(cl, g);
283 /* Render image */
284 drawimage(cl, g, msg->gpr_RPort,
285 g->Flags&GFLG_SELECTED, g->Flags&GFLG_DISABLED);
287 /* Render gadget label */
288 if (msg->gpr_Redraw == GREDRAW_REDRAW)
290 result = renderlabel(GadToolsBase, g, msg->gpr_RPort, data->labelplace);
293 return result;
296 /**********************************************************************************************/
298 IPTR GTCheckBox__GM_GOACTIVE(Class *cl, struct Gadget *g, struct gpInput *msg)
300 struct CheckBoxData *data;
301 struct RastPort *rp;
302 IPTR retval;
304 data = INST_DATA(cl, g);
305 data->flags |= CF_MouseOverGad;
307 rp = ObtainGIRPort(msg->gpi_GInfo);
308 if (rp)
310 drawimage(cl, g, rp, (g->Flags&GFLG_SELECTED) ? FALSE : TRUE, FALSE);
311 ReleaseGIRPort(rp);
312 retval = GMR_MEACTIVE;
314 else
316 retval = GMR_NOREUSE;
319 return retval;
322 /**********************************************************************************************/
324 IPTR GTCheckBox__GM_HANDLEINPUT(Class *cl, struct Gadget *g, struct gpInput *msg)
326 struct CheckBoxData *data;
327 struct RastPort *rp;
328 IPTR retval = GMR_MEACTIVE;
330 data = INST_DATA(cl, g);
332 if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE)
334 if (msg->gpi_IEvent->ie_Code == SELECTUP)
336 if (data->flags & CF_MouseOverGad)
338 /* mouse is over gadget */
340 g->Flags ^= GFLG_SELECTED;
342 *msg->gpi_Termination = g->Flags&GFLG_SELECTED?TRUE:FALSE;
343 retval = GMR_NOREUSE | GMR_VERIFY;
345 else
347 /* mouse is not over gadget */
348 retval = GMR_NOREUSE;
351 else if (msg->gpi_IEvent->ie_Code == IECODE_NOBUTTON)
353 if ((msg->gpi_Mouse.X < 0) || (msg->gpi_Mouse.Y < 0) ||
354 (msg->gpi_Mouse.X >= g->Width ) || (msg->gpi_Mouse.Y >= g->Height))
356 if (data->flags & CF_MouseOverGad)
358 rp = ObtainGIRPort(msg->gpi_GInfo);
359 if (rp)
361 drawimage(cl, g, rp,
362 g->Flags&GFLG_SELECTED, FALSE);
363 ReleaseGIRPort(rp);
365 data->flags &= ~CF_MouseOverGad;
368 else
370 if (!(data->flags & CF_MouseOverGad))
372 rp = ObtainGIRPort(msg->gpi_GInfo);
373 if (rp)
375 drawimage(cl, g, rp,
376 (g->Flags&GFLG_SELECTED)?FALSE:TRUE, FALSE);
377 ReleaseGIRPort(rp);
379 data->flags |= CF_MouseOverGad;
383 } /* else if (msg->gpi_IEvent->ie_Code == IECODE_NOBUTTON) */
384 else if (msg->gpi_IEvent->ie_Code == MENUDOWN)
386 retval = GMR_NOREUSE;
389 } /* if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE) */
391 return retval;
394 /**********************************************************************************************/
396 IPTR GTCheckBox__GM_GOINACTIVE(Class *cl, struct Gadget *g, struct gpGoInactive *msg)
398 struct CheckBoxData *data;
399 struct RastPort *rp;
401 data = INST_DATA(cl, g);
402 data->flags &= ~CF_MouseOverGad;
403 rp = ObtainGIRPort(msg->gpgi_GInfo);
404 if (rp)
406 drawimage(cl, g, rp, g->Flags & GFLG_SELECTED, FALSE);
407 ReleaseGIRPort(rp);
410 return 0;
413 /**********************************************************************************************/