2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
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>
25 #include "muimaster_intern.h"
27 #include "support_classes.h"
28 #include "popasl_private.h"
30 extern struct Library
*MUIMasterBase
;
37 Object
*app
; /* the application */
39 STRPTR buf
; /* asl_entry must FreeVec() this before exiting!!! */
42 SAVEDS
static LONG
Asl_Entry(void)
45 struct Asl_Startup
*msg
;
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
;
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
);
74 static ULONG
Popasl_Open_Function(struct Hook
*hook
, Object
*obj
, void **msg
)
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;
99 if (!(CallHookPkt(data
->start_hook
,obj
,data
->tag_list
)))
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
);
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
;
127 get(string
,MUIA_String_Contents
,&str
);
131 name_end
= PathPart(str
);
132 buf
= (char*)AllocVec(name_end
- str
+ 10, MEMF_PUBLIC
);
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
);
157 struct TagItem processTags
[2] =
163 processTags
[0].ti_Data
= (IPTR
)Asl_Entry
;
165 if (!(data
->asl_proc
= CreateNewProc( processTags
)))
168 DeleteMsgPort(msg_port
);
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
;
180 PutMsg(&data
->asl_proc
->pr_MsgPort
,&startup
->msg
);
184 DeleteMsgPort(msg_port
);
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];
200 CallHookPkt(data
->stop_hook
,obj
,data
->asl_req
);
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
);
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
);
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
);
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
);
253 data
->asl_proc
= NULL
;
254 nfset(obj
, MUIA_Popasl_Active
, FALSE
);
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
);
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
)); )
281 case MUIA_Popasl_StartHook
:
282 data
->start_hook
= (struct Hook
*)tag
->ti_Data
;
285 case MUIA_Popasl_StopHook
:
286 data
->stop_hook
= (struct Hook
*)tag
->ti_Data
;
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
;
301 MUIA_Popstring_OpenHook
, (IPTR
)&data
->open_hook
,
302 MUIA_Popstring_CloseHook
, (IPTR
)&data
->close_hook
,
303 MUIA_Popstring_Toggle
, FALSE
,
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
);
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
=
354 sizeof(struct Popasl_DATA
),
355 (void*)Popasl_Dispatcher
357 #endif /* ZUNE_BUILTIN_POPASL */