added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / desktop / observer.c
bloba6ea31d153ac61971fad12ff4316b1d9b1a4c0ee
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #define DEBUG 1
9 #include <aros/debug.h>
11 #include <exec/types.h>
12 #include <exec/memory.h>
13 #include <intuition/classes.h>
14 #include <intuition/classusr.h>
15 #include <libraries/mui.h>
17 #include "support.h"
18 #include "worker.h"
19 #include "desktop_intern.h"
21 #include <proto/dos.h>
22 #include <proto/intuition.h>
23 #include <proto/utility.h>
25 #include "presentation.h"
26 #include "observer.h"
28 #include "desktop_intern_protos.h"
30 IPTR observerNew(Class * cl, Object * obj, struct opSet * msg)
32 IPTR retval = 0;
33 struct ObserverClassData *data;
34 struct TagItem *tstate = msg->ops_AttrList,
35 *tag;
36 Object *presentation = NULL,
37 *parent = NULL;
39 while ((tag = NextTagItem(&tstate)) != NULL)
41 switch (tag->ti_Tag)
43 case OA_Presentation:
44 presentation = (Object *) tag->ti_Data;
45 break;
47 case OA_Parent:
48 parent = (Object *) tag->ti_Data;
49 break;
51 default:
52 continue; /* Don't supress non-processed tags */
55 tag->ti_Tag = TAG_IGNORE;
58 retval = DoSuperMethodA(cl, obj, (Msg) msg);
59 if (retval)
61 obj = (Object *) retval;
62 data = INST_DATA(cl, obj);
63 data->presentation = presentation;
64 data->parent = parent;
65 NEWLIST((struct List *) &data->freeList);
66 data->inTree = FALSE;
68 DoMethod(presentation, MUIM_Notify, PA_InTree, MUIV_EveryTime, (IPTR) obj, 3,
69 MUIM_Set, OA_InTree, TRUE);
72 return retval;
75 IPTR observerSet(Class * cl, Object * obj, struct opSet * msg)
77 struct ObserverClassData *data;
78 IPTR retval = 1;
79 struct TagItem *tag,
80 *tstate = msg->ops_AttrList;
82 data = (struct ObserverClassData *) INST_DATA(cl, obj);
84 while ((tag = NextTagItem(&tstate)))
86 switch (tag->ti_Tag)
88 case OA_InTree:
90 Object *pparent = NULL;
92 data->inTree = tag->ti_Data;
93 GetAttr(MUIA_Parent, data->presentation, (IPTR *) &pparent);
94 // something has to be at the top of the tree...
95 // the top object won't have a parent
96 if (data->parent)
98 data->parent = _observer(pparent);
99 if (data->parent)
100 DoMethod(obj, MUIM_Notify, OA_Disused, TRUE,
101 MUIV_EveryTime, (IPTR) data->parent, 2,
102 OM_Delete, (IPTR) obj);
104 DoMethod(data->presentation, MUIM_Notify, PA_Disused,
105 TRUE, MUIV_EveryTime, (IPTR) obj, 3, MUIM_Set,
106 OA_Disused, TRUE);
107 break;
109 case OA_Parent:
110 data->parent = (Object *) tag->ti_Data;
111 if (data->inTree)
112 DoMethod(obj, MUIM_Notify, OA_Disused, TRUE,
113 MUIV_EveryTime, (IPTR) data->parent, 2, OM_Delete, (IPTR) obj);
114 break;
115 default:
116 break;
120 retval = DoSuperMethodA(cl, obj, (Msg) msg);
122 return retval;
125 IPTR observerGet(Class * cl, Object * obj, struct opGet * msg)
127 IPTR retval = 1;
128 struct ObserverClassData *data;
130 data = (struct ObserverClassData *) INST_DATA(cl, obj);
132 switch (msg->opg_AttrID)
134 default:
135 retval = DoSuperMethodA(cl, obj, (Msg) msg);
136 break;
139 return retval;
142 IPTR observerDispose(Class * cl, Object * obj, Msg msg)
144 IPTR retval;
145 struct ObserverClassData *data;
146 struct FreeNode *fn;
148 data = (struct ObserverClassData *) INST_DATA(cl, obj);
150 fn = (struct FreeNode *) RemHead((struct List *) &data->freeList);
151 while (fn)
153 FreeVec(fn->f_mem);
154 FreeVec(fn);
157 retval = DoSuperMethodA(cl, obj, msg);
159 return retval;
162 IPTR observerFreeListAdd(Class * cl, Object * obj,
163 struct ObsFreeListAddMsg * msg)
165 IPTR retval = 0;
166 struct FreeNode *fn;
167 struct ObserverClassData *data;
169 data = (struct ObserverClassData *) INST_DATA(cl, obj);
171 fn = AllocVec(sizeof(struct FreeNode), MEMF_ANY);
172 fn->f_mem = msg->free;
174 AddTail((struct List *) &data->freeList, (struct Node *) fn);
176 return retval;
179 IPTR observerDelete(Class * cl, Object * obj, struct ObsDeleteMsg * msg)
181 IPTR retval = 0;
182 struct ObserverClassData *data;
184 data = (struct ObserverClassData *) INST_DATA(cl, obj);
186 DisposeObject(msg->obj);
188 return retval;
191 BOOPSI_DISPATCHER(IPTR, observerDispatcher, cl, obj, msg)
193 ULONG retval = 0;
195 switch (msg->MethodID)
197 case OM_NEW:
198 retval = observerNew(cl, obj, (struct opSet *) msg);
199 break;
200 case OM_SET:
201 retval = observerSet(cl, obj, (struct opSet *) msg);
202 break;
203 case OM_GET:
204 retval = observerGet(cl, obj, (struct opGet *) msg);
205 break;
206 case OM_DISPOSE:
207 retval = observerDispose(cl, obj, msg);
208 break;
209 case OM_FreeList_Add:
210 retval =
211 observerFreeListAdd(cl, obj,
212 (struct ObsFreeListAddMsg *) msg);
213 break;
214 case OM_Delete:
215 retval = observerDelete(cl, obj, (struct ObsDeleteMsg *) msg);
216 break;
217 default:
218 retval = DoSuperMethodA(cl, obj, msg);
219 break;
222 return retval;
224 BOOPSI_DISPATCHER_END