2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: AROS specific checkbox class implementation.
9 /****************************************************************************************/
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
);
51 ULONG state
= IDS_NORMAL
;
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(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
;
106 if (data
->flags
& CF_CustomImage
)
108 tag
= FindTagItem(GA_Image
, taglist
);
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
)))
129 if (msg
->MethodID
== OM_NEW
)
130 data
->dri
= (struct DrawInfo
*) tag
->ti_Data
;
134 case GA_SelectRender
:
139 if (msg
->MethodID
== OM_NEW
)
140 data
->labelplace
= (LONG
)tag
->ti_Data
;
145 data
->flags
|= CF_Checked
;
147 data
->flags
&= ~CF_Checked
;
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
);
168 DoMethod(obj
, GM_RENDER
, (IPTR
)msg
->ops_GInfo
, (IPTR
)rport
, GREDRAW_UPDATE
);
169 ReleaseGIRPort(rport
);
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
;
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
[] =
201 {SYSIA_DrawInfo
, 0UL },
202 {SYSIA_Which
, CHECKIMAGE
},
207 //EnterFunc(bug("CheckBox::New()\n"));
209 obj
= (Object
*)DoSuperMethodA(cl
, (Object
*)rootcl
, (Msg
)msg
);
213 G(obj
)->Activation
|= GACT_RELVERIFY
;
215 data
= INST_DATA(cl
, obj
);
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
,
227 data
->flags
|= CF_CustomImage
;
230 if ((!data
->dri
) || (!G(obj
)->GadgetRender
))
232 CoerceMethod(cl
, obj
, OM_DISPOSE
);
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
);
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
);
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
;
290 data
->flags
|= CF_Checked
;
291 *msg
->gpi_Termination
= data
->flags
&CF_Checked
?TRUE
:FALSE
;
292 retval
= GMR_NOREUSE
| GMR_VERIFY
;
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
);
316 drawimage(cl
, G(obj
), rport
,
317 data
->flags
&CF_Checked
, FALSE
);
318 ReleaseGIRPort(rport
);
320 G(obj
)->Flags
&= ~GFLG_SELECTED
;
325 if (!(G(obj
)->Flags
& GFLG_SELECTED
))
327 rport
= ObtainGIRPort(msg
->gpi_GInfo
);
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
)
344 } /* if (msg->gpi_IEvent->ie_Class == IECLASS_RAWMOUSE) */
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
);
360 drawimage(cl
, G(obj
), rport
,
361 (data
->flags
&CF_Checked
)?FALSE
:TRUE
, FALSE
);
362 ReleaseGIRPort(rport
);
363 return (IPTR
)GMR_MEACTIVE
;
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
);
380 drawimage(cl
, G(obj
), rport
,
381 data
->flags
& CF_Checked
, FALSE
383 ReleaseGIRPort(rport
);
387 /****************************************************************************************/