added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / muimaster / classes / scrollbutton.c
blob38f763278d3bfcf7f8caf032066a03530847eb8e
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <stdlib.h>
8 #include <stdio.h>
10 #include <intuition/intuitionbase.h>
12 #include <clib/alib_protos.h>
13 #include <proto/exec.h>
14 #include <proto/utility.h>
15 #include <proto/intuition.h>
16 #include <proto/muimaster.h>
18 #include "mui.h"
19 #include "muimaster_intern.h"
20 #include "support.h"
22 extern struct Library *MUIMasterBase;
24 struct Scrollbutton_DATA
26 WORD mx,my;
27 WORD cx,cy;
28 ULONG pos;
29 Object *horiz_prop;
30 Object *vert_prop;
31 struct MUI_EventHandlerNode ehn;
35 IPTR Scrollbutton__OM_NEW(struct IClass * cl, Object * o, struct opSet * msg)
37 return (ULONG) DoSuperNewTags(cl, o, NULL,
38 ButtonFrame,
39 MUIA_InputMode, MUIV_InputMode_RelVerify,
40 MUIA_Background, MUII_ButtonBack,
41 TAG_MORE, (IPTR) msg->ops_AttrList);
44 IPTR Scrollbutton__OM_GET(struct IClass * cl, Object * o, struct opGet * msg)
46 struct Scrollbutton_DATA *data = (struct Scrollbutton_DATA *) INST_DATA(cl, o);
47 switch (msg->opg_AttrID)
49 case MUIA_Scrollbutton_NewPosition:
50 *msg->opg_Storage = data->pos;
51 return TRUE;
53 case MUIA_Scrollbutton_HorizProp:
54 *msg->opg_Storage = (ULONG)data->horiz_prop;
55 return TRUE;
57 case MUIA_Scrollbutton_VertProp:
58 *msg->opg_Storage = (ULONG)data->horiz_prop;
59 return TRUE;
61 default:
62 return DoSuperMethodA(cl, o, (Msg) msg);
66 IPTR Scrollbutton__OM_SET(struct IClass * cl, Object * o, struct opSet * msg)
68 struct Scrollbutton_DATA *data = (struct Scrollbutton_DATA *) INST_DATA(cl, o);
69 struct TagItem *tl = msg->ops_AttrList;
70 struct TagItem *ti;
72 while ((ti = NextTagItem(&tl)))
74 switch (ti->ti_Tag)
76 case MUIA_Scrollbutton_Horiz:
77 data->cx = ti->ti_Data;
78 break;
80 case MUIA_Scrollbutton_Vert:
81 data->cy = ti->ti_Data;
82 break;
85 return DoSuperMethodA(cl, o, (Msg) msg);
88 IPTR Scrollbutton__MUIM_AskMinMax(struct IClass *cl, Object *o, struct MUIP_AskMinMax *msg)
90 DoSuperMethodA(cl, o, (Msg) msg);
92 msg->MinMaxInfo->MinWidth += 2;
93 msg->MinMaxInfo->DefWidth += 2;
94 msg->MinMaxInfo->MaxWidth += MUI_MAXMAX;
96 msg->MinMaxInfo->MinHeight += 2;
97 msg->MinMaxInfo->DefHeight += 2;
98 msg->MinMaxInfo->MaxHeight += MUI_MAXMAX;
99 return 0;
102 IPTR Scrollbutton__MUIM_Setup(struct IClass * cl, Object * o, Msg msg)
104 struct Scrollbutton_DATA *data = (struct Scrollbutton_DATA *) INST_DATA(cl, o);
105 if (!DoSuperMethodA(cl, o, msg))
106 return FALSE;
108 data->ehn.ehn_Events = IDCMP_MOUSEBUTTONS;
109 data->ehn.ehn_Priority = 0;
110 data->ehn.ehn_Flags = 0;
111 data->ehn.ehn_Object = o;
112 data->ehn.ehn_Class = cl;
114 DoMethod(_win(o), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);
116 return TRUE;
119 IPTR Scrollbutton__MUIM_Cleanup(struct IClass * cl, Object * o, Msg msg)
121 struct Scrollbutton_DATA *data = (struct Scrollbutton_DATA *) INST_DATA(cl, o);
122 DoMethod(_win(o), MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
123 DoSuperMethodA(cl, o, msg);
124 return 0;
127 IPTR Scrollbutton__MUIM_HandleEvent(struct IClass * cl, Object * o, struct MUIP_HandleEvent * msg)
129 struct Scrollbutton_DATA *data = (struct Scrollbutton_DATA *) INST_DATA(cl, o);
130 if (msg->imsg)
132 switch (msg->imsg->Class)
134 case IDCMP_MOUSEBUTTONS:
135 if (msg->imsg->Code == SELECTDOWN)
137 if (msg->imsg->MouseX >= _left(o) && msg->imsg->MouseX <= _right(o) && msg->imsg->MouseY >= _top(o) && msg->imsg->MouseY <= _bottom(o))
139 DoMethod(_win(o), MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
140 data->ehn.ehn_Events |= IDCMP_MOUSEMOVE;
141 DoMethod(_win(o), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);
143 set(o,MUIA_Selected, TRUE);
144 data->mx = msg->imsg->MouseX;
145 data->my = msg->imsg->MouseY;
148 } else
150 if (data->ehn.ehn_Events & IDCMP_MOUSEMOVE)
152 DoMethod(_win(o), MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
153 data->ehn.ehn_Events &= ~IDCMP_MOUSEMOVE;
154 DoMethod(_win(o), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);
156 set(o,MUIA_Selected, FALSE);
159 break;
161 case IDCMP_MOUSEMOVE:
163 int sel;
164 get(o,MUIA_Selected, &sel);
165 if (sel)
167 UWORD x = (msg->imsg->MouseX - data->mx) + data->cx;
168 UWORD y = (msg->imsg->MouseY - data->my) + data->cy;
169 ULONG pos = x << 16 | y;
171 data->pos = pos;
172 set(o,MUIA_Scrollbutton_NewPosition,pos);
174 break;
178 return 0;
182 BOOPSI_DISPATCHER(IPTR, Scrollbutton_Dispatcher, cl, obj, msg)
184 switch (msg->MethodID)
186 case OM_NEW: return Scrollbutton__OM_NEW(cl, obj, (struct opSet *) msg);
187 case OM_GET: return Scrollbutton__OM_GET(cl, obj, (struct opGet *) msg);
188 case OM_SET: return Scrollbutton__OM_SET(cl, obj, (struct opSet *) msg);
189 case MUIM_AskMinMax: return Scrollbutton__MUIM_AskMinMax(cl, obj, (struct MUIP_AskMinMax *) msg);
190 case MUIM_Setup: return Scrollbutton__MUIM_Setup(cl, obj, msg);
191 case MUIM_Cleanup: return Scrollbutton__MUIM_Cleanup(cl, obj, msg);
192 case MUIM_HandleEvent: return Scrollbutton__MUIM_HandleEvent(cl, obj, (struct MUIP_HandleEvent *) msg);
193 default: return DoSuperMethodA(cl, obj, msg);
196 BOOPSI_DISPATCHER_END
198 const struct __MUIBuiltinClass _MUI_Scrollbutton_desc =
200 MUIC_Scrollbutton,
201 MUIC_Area,
202 sizeof(struct Scrollbutton_DATA),
203 (void*)Scrollbutton_Dispatcher