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 const 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
)
187 struct CheckBoxData
*data
;
190 data
= INST_DATA(cl
, g
);
192 switch (msg
->opg_AttrID
)
195 case GTA_ChildGadgetKind
:
196 *(msg
->opg_Storage
) = CHECKBOX_KIND
;
201 *(msg
->opg_Storage
) = (g
->Flags
& GFLG_SELECTED
) ? TRUE
: FALSE
;
206 retval
= DoSuperMethodA(cl
, (Object
*)g
, (Msg
)msg
);
213 /**********************************************************************************************/
215 IPTR
GTCheckBox__OM_NEW(Class
*cl
, Object
*supercl
, struct opSet
*msg
)
217 struct CheckBoxData
*data
;
218 struct TagItem tags
[] =
222 {SYSIA_DrawInfo
, 0UL },
223 {SYSIA_Which
, CHECKIMAGE
},
228 g
= (struct Gadget
*)DoSuperMethodA(cl
, supercl
, (Msg
)msg
);
232 g
->Activation
|= GACT_RELVERIFY
;
234 data
= INST_DATA(cl
, g
);
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
,
246 data
->flags
|= CF_CustomImage
;
249 if ((!data
->dri
) || (!g
->GadgetRender
))
251 CoerceMethod(cl
, (Object
*)g
, OM_DISPOSE
);
258 /**********************************************************************************************/
260 IPTR
GTCheckBox__OM_DISPOSE(Class
*cl
, struct Gadget
*g
, Msg msg
)
262 struct CheckBoxData
*data
;
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
);
277 /**********************************************************************************************/
279 IPTR
GTCheckBox__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
281 struct CheckBoxData
*data
;
284 data
= INST_DATA(cl
, g
);
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
);
299 /**********************************************************************************************/
301 IPTR
GTCheckBox__GM_GOACTIVE(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
303 struct CheckBoxData
*data
;
307 data
= INST_DATA(cl
, g
);
308 data
->flags
|= CF_MouseOverGad
;
310 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
313 drawimage(cl
, g
, rp
, (g
->Flags
&GFLG_SELECTED
) ? FALSE
: TRUE
, FALSE
);
315 retval
= GMR_MEACTIVE
;
319 retval
= GMR_NOREUSE
;
325 /**********************************************************************************************/
327 IPTR
GTCheckBox__GM_HANDLEINPUT(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
329 struct CheckBoxData
*data
;
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
;
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
);
365 g
->Flags
&GFLG_SELECTED
, FALSE
);
368 data
->flags
&= ~CF_MouseOverGad
;
373 if (!(data
->flags
& CF_MouseOverGad
))
375 rp
= ObtainGIRPort(msg
->gpi_GInfo
);
379 (g
->Flags
&GFLG_SELECTED
)?FALSE
:TRUE
, FALSE
);
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) */
397 /**********************************************************************************************/
399 IPTR
GTCheckBox__GM_GOINACTIVE(Class
*cl
, struct Gadget
*g
, struct gpGoInactive
*msg
)
401 struct CheckBoxData
*data
;
404 data
= INST_DATA(cl
, g
);
405 data
->flags
&= ~CF_MouseOverGad
;
406 rp
= ObtainGIRPort(msg
->gpgi_GInfo
);
409 drawimage(cl
, g
, rp
, g
->Flags
& GFLG_SELECTED
, FALSE
);
416 /**********************************************************************************************/