Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / classes / popasl.c
blob4da1a0f10a7cf9c3e4d1a51cedc421b83a89cda4
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 const struct TagItem processTags[2] =
159 { NP_Entry, (IPTR)Asl_Entry },
160 { TAG_DONE, 0 }
163 if (!(data->asl_proc = CreateNewProc( processTags )))
165 FreeVec(startup);
166 DeleteMsgPort(msg_port);
167 return 0;
171 startup->msg.mn_ReplyPort = msg_port;
172 startup->msg.mn_Length = sizeof(struct Asl_Startup);
173 startup->tags = data->tag_list;
174 startup->app = _app(obj);
175 startup->asl_req = data->asl_req;
176 startup->pop = obj;
177 startup->buf = buf;
178 PutMsg(&data->asl_proc->pr_MsgPort,&startup->msg);
179 WaitPort(msg_port);
181 FreeVec(startup);
182 DeleteMsgPort(msg_port);
184 return 1;
188 static ULONG Popasl_Close_Function(struct Hook *hook, Object *obj, void **msg)
190 struct Popasl_DATA *data= (struct Popasl_DATA *)hook->h_Data;
191 Object *string = (Object*)msg[0];
192 LONG suc = (LONG)msg[1];
194 if (suc)
196 if (data->stop_hook)
198 CallHookPkt(data->stop_hook,obj,data->asl_req);
200 else
202 if (data->type == ASL_FileRequest)
204 struct FileRequester *file_req = (struct FileRequester*)data->asl_req;
205 char *file = (char*)file_req->fr_File?(char*)file_req->fr_File:(char*)"";
206 char *drawer = (char*)file_req->fr_Drawer?(char*)file_req->fr_Drawer:(char*)"";
207 int len = strlen(file)+strlen(drawer)+10;
208 char *buf = (char*)AllocVec(len,MEMF_CLEAR);
209 if (buf)
211 IPTR contents;
213 strcpy(buf, drawer);
214 AddPart(buf, file, len);
215 set(string, MUIA_String_Contents, (IPTR)buf);
216 get(string, MUIA_String_Contents, &contents);
217 /* trigger string notification */
218 set(string, MUIA_String_Acknowledge, contents);
219 FreeVec(buf);
222 else if (data->type == ASL_FontRequest)
224 struct FontRequester *font_req = (struct FontRequester*)data->asl_req;
225 char *name = font_req->fo_Attr.ta_Name;
226 LONG size = font_req->fo_Attr.ta_YSize;
227 int len = strlen(name)+20;
228 char *buf = (char*)AllocVec(len,MEMF_CLEAR);
229 if (buf)
231 char num_buf[20];
232 char *font_ext;
233 IPTR contents;
235 strcpy(buf,name);
237 /* Remove the .font extension */
238 if ((font_ext = strstr(buf,".font"))) *font_ext = 0;
239 snprintf(num_buf, 20, "%ld", size);
240 AddPart(buf,num_buf,len);
241 set(string, MUIA_String_Contents, (IPTR)buf);
242 get(string, MUIA_String_Contents, &contents);
243 /* trigger string notification */
244 set(string, MUIA_String_Acknowledge, contents);
245 FreeVec(buf);
251 data->asl_proc = NULL;
252 nfset(obj, MUIA_Popasl_Active, FALSE);
254 return 0;
257 IPTR Popasl__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
259 struct Popasl_DATA *data;
260 const struct TagItem *tags;
261 struct TagItem *tag;
262 ULONG asl_type = GetTagData(MUIA_Popasl_Type,ASL_FileRequest,msg->ops_AttrList);
263 APTR asl_req;
265 if (!(asl_req = AllocAslRequest(asl_type,msg->ops_AttrList))) return 0;
267 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
268 MUIA_Popstring_Toggle, FALSE,
269 TAG_MORE, (IPTR) msg->ops_AttrList);
270 if (!obj) return FALSE;
272 data = INST_DATA(cl, obj);
274 /* parse initial taglist */
276 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
278 switch (tag->ti_Tag)
280 case MUIA_Popasl_StartHook:
281 data->start_hook = (struct Hook*)tag->ti_Data;
282 break;
284 case MUIA_Popasl_StopHook:
285 data->stop_hook = (struct Hook*)tag->ti_Data;
286 break;
290 data->open_hook.h_Entry = HookEntry;
291 data->open_hook.h_SubEntry = (HOOKFUNC)Popasl_Open_Function;
292 data->open_hook.h_Data = data;
293 data->close_hook.h_Entry = HookEntry;
294 data->close_hook.h_SubEntry = (HOOKFUNC)Popasl_Close_Function;
295 data->close_hook.h_Data = data;
296 data->asl_req = asl_req;
297 data->type = asl_type;
299 SetAttrs(obj,
300 MUIA_Popstring_OpenHook, (IPTR)&data->open_hook,
301 MUIA_Popstring_CloseHook, (IPTR)&data->close_hook,
302 MUIA_Popstring_Toggle, FALSE,
303 TAG_DONE);
305 return (IPTR)obj;
308 IPTR Popasl__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
310 struct Popasl_DATA *data = INST_DATA(cl, obj);
311 if (data->asl_req) FreeAslRequest(data->asl_req);
312 return DoSuperMethodA(cl,obj,(Msg)msg);
315 #define STORE *(msg->opg_Storage)
316 IPTR Popasl__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
318 struct Popasl_DATA *data = INST_DATA(cl, obj);
320 switch(msg->opg_AttrID)
322 case MUIA_Popasl_Active: STORE = !!data->asl_proc; return 1;
324 return DoSuperMethodA(cl, obj, (Msg) msg);
326 #undef STORE
328 IPTR Popasl__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
330 struct Popasl_DATA *data = INST_DATA(cl, obj);
331 const struct TagItem *tags = msg->ops_AttrList;
332 struct TagItem *tag;
334 while ((tag = NextTagItem(&tags)) != NULL)
336 switch(tag->ti_Tag)
338 case MUIA_Popasl_StartHook:
339 data->start_hook = (struct Hook*) tag->ti_Data;
340 break;
341 case MUIA_Popasl_StopHook:
342 data->stop_hook = (struct Hook*) tag->ti_Data;
343 break;
344 } /* switch(tag->ti_Tag) */
346 } /* while ((tag = NextTagItem(&tags)) != NULL) */
348 return DoSuperMethodA(cl, obj, (Msg)msg);
351 IPTR Popasl__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
353 struct Popasl_DATA *data = INST_DATA(cl, obj);
354 if (data->asl_proc) AbortAslRequest(data->asl_req);
355 return DoSuperMethodA(cl, obj, (Msg) msg);
358 #if ZUNE_BUILTIN_POPASL
359 BOOPSI_DISPATCHER(IPTR, Popasl_Dispatcher, cl, obj, msg)
361 switch (msg->MethodID)
363 case OM_NEW: return Popasl__OM_NEW(cl, obj, (struct opSet *)msg);
364 case OM_DISPOSE: return Popasl__OM_DISPOSE(cl, obj, msg);
365 case OM_GET: return Popasl__OM_GET(cl, obj, (struct opGet *)msg);
366 case OM_SET: return Popasl__OM_SET(cl, obj, (struct opSet *)msg);
367 case MUIM_Cleanup: return Popasl__MUIM_Cleanup(cl, obj, (struct MUIP_Cleanup*)msg);
368 default: return DoSuperMethodA(cl, obj, msg);
371 BOOPSI_DISPATCHER_END
373 const struct __MUIBuiltinClass _MUI_Popasl_desc =
375 MUIC_Popasl,
376 MUIC_Popstring,
377 sizeof(struct Popasl_DATA),
378 (void*)Popasl_Dispatcher
380 #endif /* ZUNE_BUILTIN_POPASL */