2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: Internal GadTools scroller 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 GadToolsBase ((struct GadToolsBase_intern *)cl->cl_UserData)
39 /**********************************************************************************************/
41 STATIC IPTR
scroller_set(Class
* cl
, Object
* o
, struct opSet
* msg
)
44 struct TagItem
*tag
, tags
[] =
51 struct TagItem
*tstate
= msg
->ops_AttrList
;
53 struct ScrollerData
*data
= INST_DATA(cl
, o
);
55 D(bug("scroller_set(cl 0x%lx o 0x%lx msg 0x%lx)\n",cl
,o
,msg
));
57 tags
[3].ti_Data
= (IPTR
)msg
->ops_AttrList
;
60 DoSuperMethod(cl
, o
, OM_GET
, PGA_Total
, (IPTR
) &(tags
[0].ti_Data
));
61 DoSuperMethod(cl
, o
, OM_GET
, PGA_Top
, (IPTR
) &(tags
[1].ti_Data
));
62 DoSuperMethod(cl
, o
, OM_GET
, PGA_Visible
, (IPTR
) &(tags
[2].ti_Data
));
64 D(bug("scroller_set: Old Total %ld Top %ld Visible %ld\n",
70 while ((tag
= NextTagItem(&tstate
)))
76 data
->gadgetkind
= tag
->ti_Data
;
80 D(bug("scroller_set: GTSC_Total %ld\n",tag
->ti_Data
));
81 tags
[0].ti_Data
= tag
->ti_Data
;
85 D(bug("scroller_set: GTSC_Top %ld\n",tag
->ti_Data
));
86 tags
[1].ti_Data
= tag
->ti_Data
;
90 D(bug("scroller_set: GTSC_Visible %ld\n",tag
->ti_Data
));
91 tags
[2].ti_Data
= tag
->ti_Data
;
94 case GTA_Scroller_Dec
:
95 if (tags
[1].ti_Data
> 0)
102 case GTA_Scroller_Inc
:
103 /* Top < (Total - Visible) ? */
104 if (tags
[1].ti_Data
< (tags
[0].ti_Data
- tags
[2].ti_Data
))
111 case GTA_Scroller_Arrow1
:
112 data
->arrow1
= (struct Gadget
*)tag
->ti_Data
;
115 case GTA_Scroller_Arrow2
:
116 data
->arrow2
= (struct Gadget
*)tag
->ti_Data
;
121 struct TagItem set_tags
[] =
123 {GA_Disabled
, tag
->ti_Data
},
131 SetGadgetAttrsA(data
->arrow1
, msg
->ops_GInfo
->gi_Window
, 0, set_tags
);
133 SetAttrsA((Object
*)data
->arrow1
, set_tags
);
141 SetGadgetAttrsA(data
->arrow2
, msg
->ops_GInfo
->gi_Window
, 0, set_tags
);
143 SetAttrsA((Object
*)data
->arrow2
, set_tags
);
149 } /* switch (tag->ti_Tag) */
151 } /* while ((tag = NextTagItem(&tstate))) */
153 DoSuperMethod(cl
, o
, OM_SET
, (IPTR
) tags
, (IPTR
) msg
->ops_GInfo
);
158 /**********************************************************************************************/
160 IPTR
GTScroller__OM_GET(Class
* cl
, Object
* o
, struct opGet
*msg
)
162 struct ScrollerData
*data
= INST_DATA(cl
, o
);
163 struct opGet cloned_msg
= *msg
;
166 switch (msg
->opg_AttrID
)
169 *msg
->opg_Storage
= data
->gadgetkind
;
172 case GTA_ChildGadgetKind
:
173 *msg
->opg_Storage
= SCROLLER_KIND
;
177 cloned_msg
.opg_AttrID
= PGA_Top
;
178 retval
= DoSuperMethodA(cl
, o
, (Msg
)&cloned_msg
);
182 cloned_msg
.opg_AttrID
= PGA_Total
;
183 retval
= DoSuperMethodA(cl
, o
, (Msg
)&cloned_msg
);
187 cloned_msg
.opg_AttrID
= PGA_Visible
;
188 retval
= DoSuperMethodA(cl
, o
, (Msg
)&cloned_msg
);
192 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
199 /**********************************************************************************************/
201 IPTR
GTScroller__OM_NEW(Class
* cl
, Object
* o
, struct opSet
*msg
)
203 struct ScrollerData
*data
;
204 struct DrawInfo
*dri
;
205 struct TagItem fitags
[] =
209 {IA_Resolution
, 0UL },
210 {IA_FrameType
, FRAME_BUTTON
},
211 {IA_EdgesOnly
, TRUE
},
215 EnterFunc(bug("Scroller::New()\n"));
217 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
220 data
= INST_DATA(cl
, o
);
222 dri
= (struct DrawInfo
*)GetTagData(GA_DrawInfo
, 0, msg
->ops_AttrList
);
224 fitags
[0].ti_Data
= GetTagData(GA_Width
, 0, msg
->ops_AttrList
) + BORDERPROPSPACINGX
* 2;
225 fitags
[1].ti_Data
= GetTagData(GA_Height
, 0, msg
->ops_AttrList
) + BORDERPROPSPACINGY
* 2;
226 fitags
[2].ti_Data
= (dri
->dri_Resolution
.X
<< 16) + dri
->dri_Resolution
.Y
;
228 data
->frame
= NewObjectA(NULL
, FRAMEICLASS
, fitags
);
231 scroller_set(cl
, o
, msg
);
232 data
->labelplace
= GetTagData(GA_LabelPlace
, GV_LabelPlace_Left
, ((struct opSet
*)msg
)->ops_AttrList
);
234 CoerceMethod(cl
, o
, OM_DISPOSE
);
238 ReturnPtr("Scroller::New", IPTR
, (IPTR
)o
);
242 /**********************************************************************************************/
244 IPTR
GTScroller__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
246 struct ScrollerData
*data
;
249 data
= INST_DATA(cl
, g
);
251 if (msg
->gpr_Redraw
== GREDRAW_REDRAW
)
253 DrawImageState(msg
->gpr_RPort
,
254 (struct Image
*)data
->frame
,
255 g
->LeftEdge
- BORDERPROPSPACINGX
,
256 g
->TopEdge
- BORDERPROPSPACINGY
,
258 msg
->gpr_GInfo
->gi_DrInfo
);
260 renderlabel(GadToolsBase
, g
, msg
->gpr_RPort
, data
->labelplace
);
263 retval
= DoSuperMethodA(cl
, (Object
*)g
, (Msg
)msg
);
265 ReturnInt("Scroller::Render", IPTR
, retval
);
268 /**********************************************************************************************/
270 IPTR
GTScroller__OM_DISPOSE(Class
*cl
, Object
*o
, Msg msg
)
272 struct ScrollerData
*data
= INST_DATA(cl
, o
);
274 if (data
->frame
) DisposeObject(data
->frame
);
276 return DoSuperMethodA(cl
, o
, msg
);
279 /**********************************************************************************************/
281 IPTR
GTScroller__OM_SET(Class
*cl
, Object
*o
, struct opSet
*msg
)
283 IPTR retval
= scroller_set(cl
, o
, msg
);
285 /* If we have been subclassed, OM_UPDATE should not cause a GM_RENDER
286 * because it would circumvent the subclass from fully overriding it.
287 * The check of cl == OCLASS(o) should fail if we have been
288 * subclassed, and we have gotten here via DoSuperMethodA().
290 if ( retval
&& ( (msg
->MethodID
!= OM_UPDATE
) || (cl
== OCLASS(o
)) ) )
292 struct GadgetInfo
*gi
= msg
->ops_GInfo
;
295 struct RastPort
*rp
= ObtainGIRPort(gi
);
298 DoMethod(o
, GM_RENDER
, (IPTR
) gi
, (IPTR
) rp
, GREDRAW_REDRAW
);
307 /**********************************************************************************************/