2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: Internal GadTools checkbox class.
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() */
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
;
49 ULONG state
= IDS_NORMAL
;
51 data
= INST_DATA(cl
, (Object
*)gad
);
55 if (gad
->SelectRender
)
57 img
= gad
->SelectRender
;
62 img
= gad
->GadgetRender
;
68 img
= gad
->GadgetRender
;
74 if ((gad
->Flags
& GFLG_IMAGEDISABLE
) && (state
== IDS_NORMAL
))
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
))
92 gad
->LeftEdge
+ gad
->Width
- 1,
93 gad
->TopEdge
+ gad
->Height
- 1,
94 data
->dri
->dri_Pens
[SHADOWPEN
],
100 /**********************************************************************************************/
102 IPTR
GTCheckBox__OM_SET(Class
*cl
, struct Gadget
*g
, struct opSet
*msg
)
104 struct CheckBoxData
*data
;
106 struct TagItem
*taglist
= msg
->ops_AttrList
;
110 data
= INST_DATA(cl
, g
);
112 if (data
->flags
& CF_CustomImage
)
114 tag
= FindTagItem(GA_Image
, taglist
);
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
)))
135 if (msg
->MethodID
== OM_NEW
)
136 data
->dri
= (struct DrawInfo
*) tag
->ti_Data
;
140 case GA_SelectRender
:
145 if (msg
->MethodID
== OM_NEW
)
146 data
->labelplace
= (LONG
)tag
->ti_Data
;
151 g
->Flags
|= GFLG_SELECTED
;
153 g
->Flags
&= ~GFLG_SELECTED
;
157 } /* switch (tag->ti_Tag) */
159 } /* while ((tag = NextTagItem(&taglist))) */
162 g
->Width
= CHECKBOX_WIDTH
;
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
);
174 DoMethod((Object
*)g
, GM_RENDER
, (IPTR
) msg
->ops_GInfo
, (IPTR
) rp
, GREDRAW_UPDATE
);
183 /**********************************************************************************************/
185 IPTR
GTCheckBox__OM_GET(Class
*cl
, struct Gadget
*g
, struct opGet
*msg
)
189 switch (msg
->opg_AttrID
)
192 case GTA_ChildGadgetKind
:
193 *(msg
->opg_Storage
) = CHECKBOX_KIND
;
198 *(msg
->opg_Storage
) = (g
->Flags
& GFLG_SELECTED
) ? TRUE
: FALSE
;
203 retval
= DoSuperMethodA(cl
, (Object
*)g
, (Msg
)msg
);
210 /**********************************************************************************************/
212 IPTR
GTCheckBox__OM_NEW(Class
*cl
, Object
*supercl
, struct opSet
*msg
)
214 struct CheckBoxData
*data
;
215 struct TagItem tags
[] =
219 {SYSIA_DrawInfo
, 0UL },
220 {SYSIA_Which
, CHECKIMAGE
},
225 g
= (struct Gadget
*)DoSuperMethodA(cl
, supercl
, (Msg
)msg
);
229 g
->Activation
|= GACT_RELVERIFY
;
231 data
= INST_DATA(cl
, g
);
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
,
243 data
->flags
|= CF_CustomImage
;
246 if ((!data
->dri
) || (!g
->GadgetRender
))
248 CoerceMethod(cl
, (Object
*)g
, OM_DISPOSE
);
255 /**********************************************************************************************/
257 IPTR
GTCheckBox__OM_DISPOSE(Class
*cl
, struct Gadget
*g
, Msg msg
)
259 struct CheckBoxData
*data
;
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
);
274 /**********************************************************************************************/
276 IPTR
GTCheckBox__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
278 struct CheckBoxData
*data
;
281 data
= INST_DATA(cl
, g
);
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
);
296 /**********************************************************************************************/
298 IPTR
GTCheckBox__GM_GOACTIVE(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
300 struct CheckBoxData
*data
;
304 data
= INST_DATA(cl
, g
);
305 data
->flags
|= CF_MouseOverGad
;
307 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
310 drawimage(cl
, g
, rp
, (g
->Flags
&GFLG_SELECTED
) ? FALSE
: TRUE
, FALSE
);
312 retval
= GMR_MEACTIVE
;
316 retval
= GMR_NOREUSE
;
322 /**********************************************************************************************/
324 IPTR
GTCheckBox__GM_HANDLEINPUT(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
326 struct CheckBoxData
*data
;
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
;
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
);
362 g
->Flags
&GFLG_SELECTED
, FALSE
);
365 data
->flags
&= ~CF_MouseOverGad
;
370 if (!(data
->flags
& CF_MouseOverGad
))
372 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
376 (g
->Flags
&GFLG_SELECTED
)?FALSE
:TRUE
, FALSE
);
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) */
394 /**********************************************************************************************/
396 IPTR
GTCheckBox__GM_GOINACTIVE(Class
*cl
, struct Gadget
*g
, struct gpGoInactive
*msg
)
398 struct CheckBoxData
*data
;
401 data
= INST_DATA(cl
, g
);
402 data
->flags
&= ~CF_MouseOverGad
;
403 rp
= ObtainGIRPort(msg
->gpgi_GInfo
);
406 drawimage(cl
, g
, rp
, g
->Flags
& GFLG_SELECTED
, FALSE
);
413 /**********************************************************************************************/