added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / muimaster / classes / popasl.c
blobe6e3aa443d6ffbb842cc61453f88bd9d1998a25e
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <string.h>
9 #include <stdio.h>
11 #include <graphics/gfx.h>
12 #include <graphics/view.h>
13 #include <dos/dostags.h>
14 #include <libraries/asl.h>
15 #include <clib/alib_protos.h>
16 #include <proto/exec.h>
17 #include <proto/graphics.h>
18 #include <proto/utility.h>
19 #include <proto/intuition.h>
20 #include <proto/asl.h>
21 #include <proto/dos.h>
22 #include <proto/muimaster.h>
24 #include "mui.h"
25 #include "muimaster_intern.h"
26 #include "support.h"
27 #include "support_classes.h"
28 #include "popasl_private.h"
30 extern struct Library *MUIMasterBase;
32 struct Asl_Startup
34 struct Message msg;
35 APTR asl_req;
36 struct TagItem *tags;
37 Object *app; /* the application */
38 Object *pop;
39 STRPTR buf; /* asl_entry must FreeVec() this before exiting!!! */
42 SAVEDS static LONG Asl_Entry(void)
44 struct Process *proc;
45 struct Asl_Startup *msg;
47 APTR asl_req;
48 struct TagItem *tags;
49 Object *app;
50 Object *pop;
51 STRPTR buf;
53 proc = (struct Process *) FindTask(NULL);
54 WaitPort(&proc->pr_MsgPort); /* Wait for the startup message */
55 msg = (struct Asl_Startup*)GetMsg(&proc->pr_MsgPort);
57 asl_req = msg->asl_req;
58 tags = msg->tags;
59 app = msg->app;
60 pop = msg->pop;
61 buf = msg->buf;
63 ReplyMsg(&msg->msg);
65 if (AslRequest(asl_req, tags))
66 DoMethod(app,MUIM_Application_PushMethod, (IPTR)pop, 2, MUIM_Popstring_Close, TRUE);
67 else DoMethod(app,MUIM_Application_PushMethod, (IPTR)pop, 2, MUIM_Popstring_Close, FALSE);
69 if (buf != NULL) FreeVec(buf);
71 return 0;
74 static ULONG Popasl_Open_Function(struct Hook *hook, Object *obj, void **msg)
76 char *buf = NULL;
77 struct Popasl_DATA *data = (struct Popasl_DATA *)hook->h_Data;
78 struct Asl_Startup *startup;
79 Object *string = (Object*)msg[0];
80 struct MsgPort *msg_port;
82 if (data->asl_proc) return 0;
84 data->tag_list[0].ti_Tag = ASLFR_Screen;
85 data->tag_list[0].ti_Data = (IPTR)_screen(obj);
86 data->tag_list[1].ti_Tag = ASLFR_PrivateIDCMP;
87 data->tag_list[1].ti_Data = 1;
88 data->tag_list[2].ti_Tag = ASLFR_InitialLeftEdge;
89 data->tag_list[2].ti_Data = _left(obj);
90 data->tag_list[3].ti_Tag = ASLFR_InitialTopEdge;
91 data->tag_list[3].ti_Data = _top(obj);
92 data->tag_list[4].ti_Tag = ASLFR_InitialWidth;
93 data->tag_list[4].ti_Data = _width(obj);
94 data->tag_list[5].ti_Tag = TAG_DONE;
95 data->tag_list[5].ti_Data = 0;
97 if (data->start_hook)
99 if (!(CallHookPkt(data->start_hook,obj,data->tag_list)))
100 return 0;
101 } else
103 if (data->type == ASL_FileRequest)
105 char *str, *path_end;
106 get(string,MUIA_String_Contents,&str);
108 path_end = PathPart(str);
109 buf = (char*)AllocVec(path_end - str + 10, MEMF_PUBLIC);
110 if (!buf) return 0;
112 strncpy(buf,str,path_end - str);
113 buf[path_end - str] = 0;
115 data->tag_list[5].ti_Tag = ASLFR_InitialFile;
116 data->tag_list[5].ti_Data = (IPTR)FilePart(str);
117 data->tag_list[6].ti_Tag = ASLFR_InitialDrawer;
118 data->tag_list[6].ti_Data = (IPTR)buf;
119 data->tag_list[7].ti_Tag = TAG_DONE;
120 data->tag_list[7].ti_Data = 0;
123 if (data->type == ASL_FontRequest)
125 char *str, *name_end;
126 LONG size;
127 get(string,MUIA_String_Contents,&str);
129 if (str)
131 name_end = PathPart(str);
132 buf = (char*)AllocVec(name_end - str + 10, MEMF_PUBLIC);
133 if (!buf) return 0;
135 strncpy(buf,str,name_end - str);
136 strcpy(buf + (name_end - str),".font");
137 StrToLong(FilePart(str),&size);
139 data->tag_list[5].ti_Tag = ASLFO_InitialName;
140 data->tag_list[5].ti_Data = (IPTR)buf;
141 data->tag_list[6].ti_Tag = ASLFO_InitialSize;
142 data->tag_list[6].ti_Data = size;
143 data->tag_list[7].ti_Tag = TAG_DONE;
144 data->tag_list[7].ti_Data = 0;
149 if (!(msg_port = CreateMsgPort())) return 0;
150 if (!(startup = (struct Asl_Startup*)AllocVec(sizeof(struct Asl_Startup),MEMF_PUBLIC)))
152 DeleteMsgPort(msg_port);
153 return 0;
157 struct TagItem processTags[2] =
159 { NP_Entry, 0 },
160 { TAG_DONE, 0 }
163 processTags[0].ti_Data = (IPTR)Asl_Entry;
165 if (!(data->asl_proc = CreateNewProc( processTags )))
167 FreeVec(startup);
168 DeleteMsgPort(msg_port);
169 return 0;
173 startup->msg.mn_ReplyPort = msg_port;
174 startup->msg.mn_Length = sizeof(struct Asl_Startup);
175 startup->tags = data->tag_list;
176 startup->app = _app(obj);
177 startup->asl_req = data->asl_req;
178 startup->pop = obj;
179 startup->buf = buf;
180 PutMsg(&data->asl_proc->pr_MsgPort,&startup->msg);
181 WaitPort(msg_port);
183 FreeVec(startup);
184 DeleteMsgPort(msg_port);
186 return 1;
190 static ULONG Popasl_Close_Function(struct Hook *hook, Object *obj, void **msg)
192 struct Popasl_DATA *data= (struct Popasl_DATA *)hook->h_Data;
193 Object *string = (Object*)msg[0];
194 LONG suc = (LONG)msg[1];
196 if (suc)
198 if (data->stop_hook)
200 CallHookPkt(data->stop_hook,obj,data->asl_req);
202 else
204 if (data->type == ASL_FileRequest)
206 struct FileRequester *file_req = (struct FileRequester*)data->asl_req;
207 char *file = (char*)file_req->fr_File?(char*)file_req->fr_File:(char*)"";
208 char *drawer = (char*)file_req->fr_Drawer?(char*)file_req->fr_Drawer:(char*)"";
209 int len = strlen(file)+strlen(drawer)+10;
210 char *buf = (char*)AllocVec(len,MEMF_CLEAR);
211 if (buf)
213 IPTR contents;
215 strcpy(buf, drawer);
216 AddPart(buf, file, len);
217 set(string, MUIA_String_Contents, (IPTR)buf);
218 get(string, MUIA_String_Contents, &contents);
219 /* trigger string notification */
220 set(string, MUIA_String_Acknowledge, contents);
221 FreeVec(buf);
224 else if (data->type == ASL_FontRequest)
226 struct FontRequester *font_req = (struct FontRequester*)data->asl_req;
227 char *name = font_req->fo_Attr.ta_Name;
228 LONG size = font_req->fo_Attr.ta_YSize;
229 int len = strlen(name)+20;
230 char *buf = (char*)AllocVec(len,MEMF_CLEAR);
231 if (buf)
233 char num_buf[20];
234 char *font_ext;
235 IPTR contents;
237 strcpy(buf,name);
239 /* Remove the .font extension */
240 if ((font_ext = strstr(buf,".font"))) *font_ext = 0;
241 snprintf(num_buf, 20, "%ld", size);
242 AddPart(buf,num_buf,len);
243 set(string, MUIA_String_Contents, (IPTR)buf);
244 get(string, MUIA_String_Contents, &contents);
245 /* trigger string notification */
246 set(string, MUIA_String_Acknowledge, contents);
247 FreeVec(buf);
253 data->asl_proc = NULL;
254 nfset(obj, MUIA_Popasl_Active, FALSE);
256 return 0;
259 IPTR Popasl__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
261 struct Popasl_DATA *data;
262 struct TagItem *tag, *tags;
263 ULONG asl_type = GetTagData(MUIA_Popasl_Type,ASL_FileRequest,msg->ops_AttrList);
264 APTR asl_req;
266 if (!(asl_req = AllocAslRequest(asl_type,msg->ops_AttrList))) return 0;
268 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
269 MUIA_Popstring_Toggle, FALSE,
270 TAG_MORE, (IPTR) msg->ops_AttrList);
271 if (!obj) return FALSE;
273 data = INST_DATA(cl, obj);
275 /* parse initial taglist */
277 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
279 switch (tag->ti_Tag)
281 case MUIA_Popasl_StartHook:
282 data->start_hook = (struct Hook*)tag->ti_Data;
283 break;
285 case MUIA_Popasl_StopHook:
286 data->stop_hook = (struct Hook*)tag->ti_Data;
287 break;
291 data->open_hook.h_Entry = HookEntry;
292 data->open_hook.h_SubEntry = (HOOKFUNC)Popasl_Open_Function;
293 data->open_hook.h_Data = data;
294 data->close_hook.h_Entry = HookEntry;
295 data->close_hook.h_SubEntry = (HOOKFUNC)Popasl_Close_Function;
296 data->close_hook.h_Data = data;
297 data->asl_req = asl_req;
298 data->type = asl_type;
300 SetAttrs(obj,
301 MUIA_Popstring_OpenHook, (IPTR)&data->open_hook,
302 MUIA_Popstring_CloseHook, (IPTR)&data->close_hook,
303 MUIA_Popstring_Toggle, FALSE,
304 TAG_DONE);
306 return (IPTR)obj;
309 IPTR Popasl__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
311 struct Popasl_DATA *data = INST_DATA(cl, obj);
312 if (data->asl_req) FreeAslRequest(data->asl_req);
313 return DoSuperMethodA(cl,obj,(Msg)msg);
316 #define STORE *(msg->opg_Storage)
317 IPTR Popasl__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
319 struct Popasl_DATA *data = INST_DATA(cl, obj);
321 switch(msg->opg_AttrID)
323 case MUIA_Popasl_Active: STORE = !!data->asl_proc; return 1;
325 return DoSuperMethodA(cl, obj, (Msg) msg);
327 #undef STORE
329 IPTR Popasl__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
331 struct Popasl_DATA *data = INST_DATA(cl, obj);
332 if (data->asl_proc) AbortAslRequest(data->asl_req);
333 return DoSuperMethodA(cl, obj, (Msg) msg);
336 #if ZUNE_BUILTIN_POPASL
337 BOOPSI_DISPATCHER(IPTR, Popasl_Dispatcher, cl, obj, msg)
339 switch (msg->MethodID)
341 case OM_NEW: return Popasl__OM_NEW(cl, obj, (struct opSet *)msg);
342 case OM_DISPOSE: return Popasl__OM_DISPOSE(cl, obj, msg);
343 case OM_GET: return Popasl__OM_GET(cl, obj, (struct opGet *)msg);
344 case MUIM_Cleanup: return Popasl__MUIM_Cleanup(cl, obj, (struct MUIP_Cleanup*)msg);
345 default: return DoSuperMethodA(cl, obj, msg);
348 BOOPSI_DISPATCHER_END
350 const struct __MUIBuiltinClass _MUI_Popasl_desc =
352 MUIC_Popasl,
353 MUIC_Popstring,
354 sizeof(struct Popasl_DATA),
355 (void*)Popasl_Dispatcher
357 #endif /* ZUNE_BUILTIN_POPASL */