Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / openurl / prefs / popph.c
blob1a76ee1b466e22444f5a6e0e983cde9e7b78a181
1 /*
2 ** OpenURL - MUI preferences for openurl.library
3 **
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
6 **
7 ** Developed by:
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
13 ** Popplaceholder replacement
17 #include "OpenURL.h"
18 #include <exec/execbase.h>
19 #include <libraries/asl.h>
21 /**************************************************************************/
23 ** Place holders list
26 static struct MUI_CustomClass *listClass = NULL;
27 #ifdef __AROS__
28 #define listObject BOOPSIOBJMACRO_START(listClass->mcc_Class)
29 #else
30 #define listObject NewObject(listClass->mcc_Class,NULL
31 #endif
33 struct listData
35 UBYTE **phs;
36 UBYTE **names;
37 struct Hook dispHook;
40 /**************************************************************************/
42 #ifdef __MORPHOS__
43 static ULONG
44 conFun(void)
46 ULONG num = REG_A1;
47 #elif defined(__AROS__)
48 AROS_UFH3S(ULONG, conFun,
49 AROS_UFHA(struct Hook *, hook, A0),
50 AROS_UFHA(APTR , pool, A2),
51 AROS_UFHA(ULONG , num , A1))
53 AROS_USERFUNC_INIT
54 #else
55 static ULONG SAVEDS ASM
56 conFun(REG(a0,struct Hook *hook),REG(a2,APTR pool),REG(a1,ULONG num))
58 #endif
59 return num+1;
60 #ifdef __AROS__
61 AROS_USERFUNC_EXIT
62 #endif
65 #ifdef __MORPHOS__
66 static struct EmulLibEntry conTrap = {TRAP_LIB,0,(void (*)(void))conFun};
67 static struct Hook conHook = {0,0,(HOOKFUNC)&conTrap};
68 #else
69 static struct Hook conHook = {0,0,(HOOKFUNC)conFun};
70 #endif
72 /**************************************************************************/
74 #ifdef __MORPHOS__
75 static void
76 dispFun(void)
78 struct Hook *hook = (struct Hook *)REG_a0;
79 UBYTE **array = (UBYTE **)REG_A2;
80 ULONG num = REG_A1;
81 #elif defined(__AROS__)
82 AROS_UFH3S(void, dispFun,
83 AROS_UFHA(struct Hook *, hook , A0),
84 AROS_UFHA(UBYTE ** , array, A2),
85 AROS_UFHA(ULONG , num , A1))
87 AROS_USERFUNC_INIT
88 #else
89 static void SAVEDS ASM
90 dispFun(REG(a0,struct Hook *hook),REG(a2,UBYTE **array),REG(a1,ULONG num))
92 #endif
93 struct listData *data = hook->h_Data;
95 if (num)
97 num--;
99 *array++ = data->phs[num];
100 *array = data->names[num];
102 #ifdef __AROS__
103 AROS_USERFUNC_EXIT
104 #endif
107 #ifdef __MORPHOS__
108 static struct EmulLibEntry dispTrap = {TRAP_LIBNR,0,(void (*)(void))dispFun};
109 #endif
111 /**************************************************************************/
113 static ULONG
114 mListNew(struct IClass *cl,Object *obj,struct opSet *msg)
116 struct TagItem *attrs = msg->ops_AttrList;
117 UBYTE **phs, **names;
119 phs = (UBYTE **)GetTagData(MUIA_Popph_Syms,(ULONG)NULL,attrs);
120 names = (UBYTE **)GetTagData(MUIA_Popph_Names,(ULONG)NULL,attrs);
121 if (!phs || !names) return 0;
123 if (obj = (Object *)DoSuperNew(cl,obj,
124 InputListFrame,
125 MUIA_List_Format, ",",
126 MUIA_List_Pool, g_pool,
127 MUIA_List_ConstructHook, &conHook,
128 TAG_MORE, attrs))
130 struct listData *data = INST_DATA(cl,obj);
131 int i;
133 data->phs = phs;
134 data->names = names;
136 #ifdef __MORPHOS__
137 data->dispHook.h_Entry = (HOOKFUNC)&dispTrap;
138 #else
139 data->dispHook.h_Entry = (HOOKFUNC)dispFun;
140 #endif
141 data->dispHook.h_Data = data;
143 superset(cl,obj,MUIA_List_DisplayHook,&data->dispHook);
145 conHook.h_Data = data;
147 for (i = 0; phs[i]; i++)
148 DoSuperMethod(cl,obj,MUIM_List_InsertSingle,i,MUIV_List_Insert_Bottom);
151 return (ULONG)obj;
154 /**************************************************************************/
156 M_DISP(listDispatcher)
158 M_DISPSTART
160 switch (msg->MethodID)
162 case OM_NEW: return mListNew(cl,obj,(APTR)msg);
164 default: return DoSuperMethodA(cl,obj,msg);
168 M_DISPEND(listDispatcher)
170 /**************************************************************************/
172 static ULONG
173 initListClass(void)
175 return (ULONG)(listClass = MUI_CreateCustomClass(NULL,MUIC_List,NULL,sizeof(struct listData),DISP(listDispatcher)));
178 /**************************************************************************/
180 static void
181 disposeListClass(void)
183 if (listClass) MUI_DeleteCustomClass(listClass);
186 /**************************************************************************/
188 struct data
190 Object *str;
192 struct Hook closeHook;
193 struct FileRequester *req;
195 STRPTR *phs;
196 STRPTR *names;
199 /**************************************************************************/
201 #ifdef __MORPHOS__
202 static void
203 windowFun(void)
205 //struct Hook *hook = (struct Hook *)REG_A0;
206 Object *pop = (Object *)REG_A2;
207 Object *win = (Object *)REG_A1;
208 #elif defined(__AROS__)
209 AROS_UFH3S(void, windowFun,
210 AROS_UFHA(struct Hook *, hook, A0),
211 AROS_UFHA(Object * , pop , A2),
212 AROS_UFHA(Object * , win , A1))
214 AROS_USERFUNC_INIT
215 #else
216 static void SAVEDS ASM
217 windowFun(REG(a0,struct Hook *hook),REG(a2,Object *pop),REG(a1,Object *win))
219 #endif
220 set(win,MUIA_Window_DefaultObject,pop);
221 #ifdef __AROS__
222 AROS_USERFUNC_EXIT
223 #endif
226 #ifdef __MORPHOS__
227 static struct EmulLibEntry windowTrap = {TRAP_LIB,0,(void (*)(void))windowFun};
228 static struct Hook windowHook = {0,0,(HOOKFUNC)&windowTrap};
229 #else
230 static struct Hook windowHook = {0,0,(HOOKFUNC)&windowFun};
231 #endif
233 /***********************************************************************/
235 #ifdef __MORPHOS__
236 static void closeFun(void)
238 struct Hook *hook = (struct Hook *)REG_A0;
239 Object *list = (Object *)REG_A2;
240 Object *str = (Object *)REG_A1;
241 #elif defined(__AROS__)
242 AROS_UFH3S(void, closeFun,
243 AROS_UFHA(struct Hook *, hook, A0),
244 AROS_UFHA(Object * , list, A2),
245 AROS_UFHA(Object * , str , A1))
247 AROS_USERFUNC_INIT
248 #else
249 static void SAVEDS ASM
250 closeFun(REG(a0,struct Hook *hook),REG(a2,Object *list),REG(a1,Object *str))
252 #endif
253 struct data *data = hook->h_Data;
254 ULONG a;
256 get(list,MUIA_List_Active,&a);
257 if (a>=0)
259 STRPTR buf, x;
260 ULONG pos, lx, l;
262 get(str,MUIA_String_BufferPos,&pos);
263 get(str,MUIA_String_Contents,&x);
265 lx = strlen(x);
266 l = strlen(data->phs[a]);
268 if (buf = AllocPooled(g_pool,lx+l+1))
270 if (pos>0) CopyMem(x,buf,pos);
271 CopyMem(data->phs[a],buf+pos,l);
272 if (lx) CopyMem(x+pos,buf+pos+l,lx-pos+1);
273 set(str,MUIA_String_Contents,buf);
274 FreePooled(g_pool,buf,lx+l+1);
277 #ifdef __AROS__
278 AROS_USERFUNC_EXIT
279 #endif
282 #ifdef __MORPHOS__
283 static struct EmulLibEntry closeTrap = {TRAP_LIB,0,(void (*)(void))closeFun};
284 #endif
286 static ULONG
287 mNew(struct IClass *cl,Object *obj,struct opSet *msg)
289 Object *str, *lv;
290 struct TagItem *attrs = msg->ops_AttrList;
291 STRPTR *phs, *names;
293 phs = (STRPTR*)GetTagData(MUIA_Popph_Syms,(ULONG)NULL,attrs);
294 if (!phs) return 0;
296 names = (STRPTR*)GetTagData(MUIA_Popph_Names,FALSE,attrs);
297 if (!names) return 0;
299 if (obj = (Object *)DoSuperNew(cl,obj,
300 MUIA_Group_Horiz, TRUE,
301 MUIA_Group_HorizSpacing, 1,
303 Child, PopobjectObject,
304 MUIA_Popstring_String, str = ostring(GetTagData(MUIA_Popph_MaxLen,0,attrs),GetTagData(MUIA_Popph_Key,(ULONG)NULL,attrs),0),
305 MUIA_Popstring_Button, opopbutton(MUII_PopUp,0),
306 MUIA_Popobject_Object, lv = ListviewObject,
307 MUIA_Listview_List, listObject,
308 MUIA_Popph_Syms, phs,
309 MUIA_Popph_Names, names,
310 End,
311 End,
312 MUIA_Popobject_WindowHook, &windowHook,
313 End,
315 TAG_MORE, attrs))
318 struct data *data = INST_DATA(cl,obj);
320 data->str = str;
322 data->phs = phs;
323 data->names = names;
325 #ifdef __MORPHOS__
326 data->closeHook.h_Entry = (HOOKFUNC)&closeTrap;
327 #else
328 data->closeHook.h_Entry = (HOOKFUNC)closeFun;
329 #endif
330 data->closeHook.h_Data = data;
331 set(obj,MUIA_Popobject_ObjStrHook,&data->closeHook);
333 if (GetTagData(MUIA_Popph_Asl,FALSE,attrs))
335 APTR req;
337 if (req = MUI_AllocAslRequest(ASL_FileRequest,NULL))
339 Object *bt;
341 if (bt = opopbutton(MUII_PopFile,0))
343 DoSuperMethod(cl,obj,OM_ADDMEMBER,(ULONG)bt);
345 data->req = req;
347 DoMethod(bt,MUIM_Notify,MUIA_Pressed,FALSE,(ULONG)obj,1,MUIM_Popph_RequestFile);
349 else MUI_FreeAslRequest(req);
353 DoMethod(lv,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,(ULONG)obj,2,MUIM_Popstring_Close,TRUE);
356 return (ULONG)obj;
359 /***********************************************************************/
361 static ULONG
362 mDispose(struct IClass *cl,Object *obj,Msg msg)
364 struct data *data = INST_DATA(cl,obj);
366 if (data->req) MUI_FreeAslRequest(data->req);
368 return DoSuperMethodA(cl,obj,(Msg)msg);
371 /***********************************************************************/
373 #ifdef __MORPHOS__
374 static void
375 reqIntuiFun(void)
377 struct Hook *hook = (struct Hook *)REG_A0;
378 struct IntuiMessage *imsg = (struct IntuiMessage *)REG_A1;
379 #elif defined(__AROS__)
380 AROS_UFH3S(void, reqIntuiFun,
381 AROS_UFHA(struct Hook * , hook, A0),
382 AROS_UFHA(Object * , dummy, A2),
383 AROS_UFHA(struct IntuiMessage *, imsg, A1))
385 AROS_USERFUNC_INIT
386 #else
387 static void SAVEDS ASM
388 reqIntuiFun(REG(a0,struct Hook *hook),REG(a1,struct IntuiMessage *imsg))
390 #endif
391 if (imsg->Class==IDCMP_REFRESHWINDOW)
392 DoMethod(hook->h_Data,MUIM_Application_CheckRefresh);
393 #ifdef __AROS__
394 AROS_USERFUNC_EXIT
395 #endif
398 #ifdef __MORPHOS__
399 static struct EmulLibEntry reqIntuiTrap = {TRAP_LIBNR,0,(void (*)(void))reqIntuiFun};
400 #endif
402 static ULONG
403 mRequestFile(struct IClass *cl,Object *obj,Msg msg)
405 struct data *data = INST_DATA(cl,obj);
406 struct Hook reqIntuiHook = {0};
407 TEXT path[256], *x, *file, *p;
409 set(_app(obj),MUIA_Application_Sleep,TRUE);
411 #ifdef __MORPHOS__
412 reqIntuiHook.h_Entry = (HOOKFUNC)&reqIntuiTrap;
413 #else
414 reqIntuiHook.h_Entry = (HOOKFUNC)reqIntuiFun;
415 #endif
416 reqIntuiHook.h_Data = _app(obj);
419 get(data->str,MUIA_String_Contents,&x);
420 file = FilePart(x);
421 if (p = PathPart(x))
423 stccpy(path,x,p-x+1);
424 p = path;
427 if (MUI_AslRequestTags(data->req,
428 ASLFR_InitialFile, (ULONG)file,
429 p ? ASLFR_InitialDrawer : TAG_IGNORE, (ULONG)p,
430 ASLFR_IntuiMsgFunc, (ULONG)&reqIntuiHook,
431 ASLFR_Window, (ULONG)_window(obj),
432 ASLFR_PrivateIDCMP, TRUE,
433 ASLFR_Flags1, FRF_INTUIFUNC,
434 TAG_DONE))
436 TEXT buf[256];
438 strcpy(buf,data->req->fr_Drawer);
439 AddPart(buf,data->req->fr_File,sizeof(buf));
441 if (*buf) set(data->str,MUIA_String_Contents,buf);
443 else if (IoErr()) DisplayBeep(0);
445 set(_app(obj),MUIA_Application_Sleep,FALSE);
447 return 0;
450 /***********************************************************************/
452 M_DISP(dispatcher)
454 M_DISPSTART
456 switch (msg->MethodID)
458 case OM_NEW: return mNew(cl,obj,(APTR)msg);
459 case OM_DISPOSE: return mDispose(cl,obj,(APTR)msg);
461 case MUIM_Popph_RequestFile: return mRequestFile(cl,obj,(APTR)msg);
463 default: return DoSuperMethodA(cl,obj,msg);
467 M_DISPEND(dispatcher)
469 /***********************************************************************/
471 ULONG
472 initPopphClass(void)
474 if (initListClass())
476 if (g_popphClass = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct data),DISP(dispatcher)))
478 return TRUE;
481 disposeListClass();
484 return FALSE;
487 /**************************************************************************/
489 void
490 disposePopphClass(void)
492 disposeListClass();
493 if (g_popphClass) MUI_DeleteCustomClass(g_popphClass);
496 /**************************************************************************/