added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / muimaster / classes / popobject.c
bloba0500a7f0fd3273dd5d772b24e0d8ca7a5db17f3
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <graphics/gfx.h>
7 #include <graphics/view.h>
8 #include <clib/alib_protos.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
15 #include "mui.h"
16 #include "muimaster_intern.h"
17 #include "support.h"
18 #include "debug.h"
20 extern struct Library *MUIMasterBase;
22 struct Popobject_DATA
24 struct MUI_EventHandlerNode ehn;
25 int light;
26 int vol;
27 int follow;
28 struct Hook *strobj_hook;
29 struct Hook *objstr_hook;
30 struct Hook *window_hook;
31 struct Hook open_hook;
32 struct Hook close_hook;
33 Object *object;
34 Object *wnd;
37 AROS_UFH3(ULONG,Popobject_Open_Function,
38 AROS_UFHA(struct Hook *, hook, A0),
39 AROS_UFHA(Object *, obj, A2),
40 AROS_UFHA(void **, msg, A1))
42 AROS_USERFUNC_INIT
44 struct Popobject_DATA *data = (struct Popobject_DATA *)hook->h_Data;
45 Object *string = (Object*)msg[0];
47 if (!data->wnd)
49 static struct TagItem light_tags[] =
51 {MUIA_Window_Borderless , TRUE },
52 {MUIA_Window_CloseGadget, FALSE },
53 {MUIA_Window_SizeGadget , FALSE },
54 {MUIA_Window_DepthGadget, FALSE },
55 {MUIA_Window_DragBar , FALSE },
56 {TAG_DONE }
59 data->wnd = WindowObject,
60 WindowContents,data->object,
61 data->light ? TAG_MORE : TAG_IGNORE, (IPTR)light_tags,
62 End;
64 if (!data->wnd) return 0;
66 DoMethod(_app(obj),OM_ADDMEMBER,(IPTR)data->wnd);
68 DoMethod(data->wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
69 (IPTR)obj, 2, MUIM_Popstring_Close, FALSE);
72 if (data->strobj_hook)
74 if (!(CallHookPkt(data->strobj_hook,data->object,string)))
75 return 0;
78 if (data->window_hook)
80 CallHookPkt(data->window_hook,data->object,data->wnd);
83 SetAttrs(data->wnd,
84 MUIA_Window_LeftEdge, _left(obj) + _window(obj)->LeftEdge,
85 MUIA_Window_TopEdge, _bottom(obj)+1 + _window(obj)->TopEdge,
86 MUIA_Window_Width, _width(obj),
87 MUIA_Window_Open, TRUE,
88 TAG_DONE);
90 if (!(data->ehn.ehn_Events & IDCMP_CHANGEWINDOW))
92 data->ehn.ehn_Events |= IDCMP_CHANGEWINDOW;
93 DoMethod(_win(obj), MUIM_Window_AddEventHandler, (IPTR)&data->ehn);
96 return 1;
98 AROS_USERFUNC_EXIT
102 AROS_UFH3(ULONG,Popobject_Close_Function,
103 AROS_UFHA(struct Hook *, hook, A0),
104 AROS_UFHA(Object *, obj, A2),
105 AROS_UFHA(void **, msg, A1))
107 AROS_USERFUNC_INIT
109 struct Popobject_DATA *data= (struct Popobject_DATA *)hook->h_Data;
110 Object *string = (Object*)msg[0];
111 LONG suc = (LONG)msg[1];
113 if (data->wnd)
115 set(data->wnd,MUIA_Window_Open,FALSE);
117 if (data->objstr_hook && suc)
118 CallHookPkt(data->objstr_hook,data->object,string);
120 if (data->ehn.ehn_Events & IDCMP_CHANGEWINDOW)
122 DoMethod(_win(obj), MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
123 data->ehn.ehn_Events &= ~IDCMP_CHANGEWINDOW;
127 return 0;
129 AROS_USERFUNC_EXIT
132 IPTR Popobject__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
134 struct Popobject_DATA *data;
135 struct TagItem *tag, *tags;
137 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
138 if (!obj) return FALSE;
140 data = INST_DATA(cl, obj);
141 data->follow = 1;
142 data->vol = 1;
143 data->light = 1;
145 data->ehn.ehn_Events = 0;
146 data->ehn.ehn_Priority = 0;
147 data->ehn.ehn_Flags = 0;
148 data->ehn.ehn_Object = obj;
149 data->ehn.ehn_Class = cl;
151 data->open_hook.h_Entry = (HOOKFUNC)Popobject_Open_Function;
152 data->open_hook.h_Data = data;
153 data->close_hook.h_Entry = (HOOKFUNC)Popobject_Close_Function;
154 data->close_hook.h_Data = data;
156 /* parse initial taglist */
158 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
160 switch (tag->ti_Tag)
162 case MUIA_Popobject_Follow:
163 data->follow = tag->ti_Data;
164 break;
166 case MUIA_Popobject_Light:
167 data->light = tag->ti_Data;
168 break;
170 case MUIA_Popobject_Object:
171 data->object = (Object*)tag->ti_Data;
172 break;
174 case MUIA_Popobject_ObjStrHook:
175 data->objstr_hook = (struct Hook*)tag->ti_Data;
176 break;
178 case MUIA_Popobject_StrObjHook:
179 data->strobj_hook = (struct Hook*)tag->ti_Data;
180 break;
182 case MUIA_Popobject_Volatile:
183 data->vol = tag->ti_Data;
184 break;
186 case MUIA_Popobject_WindowHook:
187 data->window_hook = (struct Hook*)tag->ti_Data;
188 break;
192 SetAttrs(obj,
193 MUIA_Popstring_OpenHook, (IPTR)&data->open_hook,
194 MUIA_Popstring_CloseHook, (IPTR)&data->close_hook,
195 MUIA_Popstring_Toggle, TRUE,
196 TAG_DONE);
198 return (IPTR)obj;
201 IPTR Popobject__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
203 struct Popobject_DATA *data = INST_DATA(cl, obj);
205 if (!data->wnd && data->object)
206 MUI_DisposeObject(data->object);
208 return DoSuperMethodA(cl, obj, msg);
211 IPTR Popobject__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
213 struct Popobject_DATA *data = INST_DATA(cl, obj);
214 struct TagItem *tag, *tags;
216 /* parse initial taglist */
218 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
220 switch (tag->ti_Tag)
222 case MUIA_Popobject_Follow:
223 data->follow = tag->ti_Data;
224 break;
226 case MUIA_Popobject_ObjStrHook:
227 data->objstr_hook = (struct Hook*)tag->ti_Data;
228 break;
230 case MUIA_Popobject_StrObjHook:
231 data->strobj_hook = (struct Hook*)tag->ti_Data;
232 break;
234 case MUIA_Popobject_Volatile:
235 data->vol = tag->ti_Data;
236 break;
238 case MUIA_Popobject_WindowHook:
239 data->window_hook = (struct Hook*)tag->ti_Data;
240 break;
243 return DoSuperMethodA(cl,obj,(Msg)msg);
247 IPTR Popobject__MUIM_Get(struct IClass *cl, Object *obj, struct opGet *msg)
249 struct Popobject_DATA *data = INST_DATA(cl, obj);
251 switch (msg->opg_AttrID)
253 case MUIA_Popobject_Follow:
254 *msg->opg_Storage = data->follow;
255 return TRUE;
257 case MUIA_Popobject_Light:
258 *msg->opg_Storage = data->light;
259 return TRUE;
261 case MUIA_Popobject_Object:
262 *msg->opg_Storage = (IPTR)data->object;
263 return TRUE;
265 case MUIA_Popobject_ObjStrHook:
266 *msg->opg_Storage = (IPTR)data->objstr_hook;
267 return TRUE;
269 case MUIA_Popobject_StrObjHook:
270 *msg->opg_Storage = (IPTR)data->strobj_hook;
271 return TRUE;
273 case MUIA_Popobject_Volatile:
274 *msg->opg_Storage = data->vol;
275 return TRUE;
277 case MUIA_Popobject_WindowHook:
278 *msg->opg_Storage = (IPTR)data->window_hook;
279 return TRUE;
282 return DoSuperMethodA(cl, obj, (Msg)msg);
286 IPTR Popobject__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
288 struct Popobject_DATA *data = INST_DATA(cl, obj);
290 if (data->ehn.ehn_Events & IDCMP_CHANGEWINDOW)
292 DoMethod(_win(obj),MUIM_Window_RemEventHandler, (IPTR)&data->ehn);
293 data->ehn.ehn_Events &= ~IDCMP_CHANGEWINDOW;
296 return DoSuperMethodA(cl,obj,(Msg)msg);
299 IPTR Popobject__MUIM_Show(struct IClass *cl, Object *obj, struct MUIP_Show *msg)
301 IPTR rc = DoSuperMethodA(cl,obj,(Msg)msg);
302 if (!rc) return 0;
303 return rc;
306 IPTR Popobject__MUIM_Hide(struct IClass *cl, Object *obj, struct MUIP_Hide *msg)
308 return DoSuperMethodA(cl,obj,(Msg)msg);
311 IPTR Popobject__MUIM_HandleEvent(struct IClass *cl, Object *obj, struct MUIP_HandleEvent *msg)
313 struct Popobject_DATA *data = INST_DATA(cl, obj);
315 if (data->follow && msg->imsg && data->wnd)
317 if (msg->imsg->Class == IDCMP_CHANGEWINDOW)
319 struct Window *popwin = NULL;
320 struct Window *parentwin = _window(obj);
322 get(data->wnd, MUIA_Window_Window, &popwin);
324 if (popwin && parentwin)
326 ChangeWindowBox(popwin, _left(obj) + parentwin->LeftEdge,
327 _bottom(obj) + parentwin->TopEdge + 1,
328 popwin->Width,
329 popwin->Height);
334 return DoSuperMethodA(cl,obj,(Msg)msg);
337 BOOPSI_DISPATCHER(IPTR, Popobject_Dispatcher, cl, obj, msg)
339 switch (msg->MethodID)
341 case OM_NEW: return Popobject__OM_NEW(cl, obj, (struct opSet *)msg);
342 case OM_DISPOSE: return Popobject__OM_DISPOSE(cl, obj, msg);
343 case OM_SET: return Popobject__OM_SET(cl, obj, (struct opSet *)msg);
344 case OM_GET: return Popobject__MUIM_Get(cl, obj, (struct opGet *)msg);
345 case MUIM_Cleanup: return Popobject__MUIM_Cleanup(cl, obj, (struct MUIP_Cleanup *)msg);
346 case MUIM_Show: return Popobject__MUIM_Show(cl, obj, (struct MUIP_Show*)msg);
347 case MUIM_Hide: return Popobject__MUIM_Hide(cl, obj, (struct MUIP_Hide*)msg);
348 case MUIM_HandleEvent: return Popobject__MUIM_HandleEvent(cl, obj, (struct MUIP_HandleEvent *)msg);
351 return DoSuperMethodA(cl, obj, msg);
353 BOOPSI_DISPATCHER_END
355 const struct __MUIBuiltinClass _MUI_Popobject_desc =
357 MUIC_Popobject,
358 MUIC_Popstring,
359 sizeof(struct Popobject_DATA),
360 (void*)Popobject_Dispatcher