Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / openurl / prefs / popport.c
blob2f3625dd1c23d79a318e879fa13aca24e7407dc9
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 ** Pop public ports object
17 #include "OpenURL.h"
18 #include "libraries/openurl.h"
19 #include <exec/execbase.h>
21 /**************************************************************************/
23 ** Public ports 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 static ULONG
34 mListNew(struct IClass *cl,Object *obj,struct opSet *msg)
36 return (ULONG)DoSuperNew(cl,obj,
37 MUIA_Frame, MUIV_Frame_InputList,
38 MUIA_Background, MUII_ListBack,
39 MUIA_List_AutoVisible, TRUE,
40 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
41 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
42 TAG_MORE,(ULONG)msg->ops_AttrList);
45 /**************************************************************************/
47 static ULONG
48 mListSetup(struct IClass *cl,Object *obj,Msg msg)
50 struct Node *mstate;
52 if (!DoSuperMethodA(cl,obj,msg)) return FALSE;
54 DoSuperMethod(cl,obj,MUIM_List_Clear);
56 Forbid();
58 for (mstate = SysBase->PortList.lh_Head; mstate->ln_Succ; mstate = mstate->ln_Succ)
59 #ifdef __AROS__
60 // Zune Listclass doesn't support Insert_Sorted
61 DoSuperMethod(cl,obj,MUIM_List_InsertSingle,(ULONG)mstate->ln_Name,MUIV_List_Insert_Bottom);
62 #else
63 DoSuperMethod(cl,obj,MUIM_List_InsertSingle,(ULONG)mstate->ln_Name,MUIV_List_Insert_Sorted);
64 #endif
66 Permit();
68 return TRUE;
71 /**************************************************************************/
73 M_DISP(listDispatcher)
75 M_DISPSTART
77 switch (msg->MethodID)
79 case OM_NEW: return mListNew(cl,obj,(APTR)msg);
81 case MUIM_Setup: return mListSetup(cl,obj,(APTR)msg);
83 default: return DoSuperMethodA(cl,obj,msg);
87 M_DISPEND(listDispatcher)
89 /**************************************************************************/
91 static ULONG
92 initListClass(void)
94 return (ULONG)(listClass = MUI_CreateCustomClass(NULL,MUIC_List,NULL,0,DISP(listDispatcher)));
97 /**************************************************************************/
99 static void
100 disposeListClass(void)
102 if (listClass) MUI_DeleteCustomClass(listClass);
105 /**************************************************************************/
107 #ifdef __MORPHOS__
108 static void
109 windowFun(void)
111 //struct Hook *hook = (struct Hook *)REG_A0;
112 Object *pop = (Object *)REG_A2;
113 Object *win = (Object *)REG_A1;
114 #elif defined(__AROS__)
115 AROS_UFH3S(void, windowFun,
116 AROS_UFHA(struct Hook *, hook, A0),
117 AROS_UFHA(Object * , pop , A2),
118 AROS_UFHA(Object * , win , A1))
120 AROS_USERFUNC_INIT
121 #else
122 static void SAVEDS ASM
123 windowFun(REG(a0,struct Hook *hook),REG(a2,Object *pop),REG(a1,Object *win))
125 #endif
126 set(win,MUIA_Window_DefaultObject,pop);
127 #ifdef __AROS__
128 AROS_USERFUNC_EXIT
129 #endif
132 #ifdef __MORPHOS__
133 static struct EmulLibEntry windowTrap = {TRAP_LIB,0,(void (*)(void))windowFun};
134 static struct Hook windowHook = {0,0,(HOOKFUNC)&windowTrap};
135 #else
136 static struct Hook windowHook = {0,0,(HOOKFUNC)&windowFun};
137 #endif
139 /***********************************************************************/
141 #ifdef __MORPHOS__
142 static ULONG
143 openFun(void)
145 //struct Hook *hook = (struct Hook *)REG_A0;
146 Object *list = (Object *)REG_A2;
147 Object *str = (Object *)REG_A1;
148 #elif defined(__AROS__)
149 AROS_UFH3S(ULONG, openFun,
150 AROS_UFHA(struct Hook *, hook, A0),
151 AROS_UFHA(Object * , list, A2),
152 AROS_UFHA(Object * , str , A1))
154 AROS_USERFUNC_INIT
155 #else
156 static ULONG SAVEDS ASM
157 openFun(REG(a0,struct Hook *hook),REG(a2,Object *list),REG(a1,Object *str))
159 #endif
160 STRPTR s, x;
161 int i;
163 s = (STRPTR)xget(str,MUIA_String_Contents);
165 for (i = 0; ;i++)
167 DoMethod(list,MUIM_List_GetEntry,i,(ULONG)&x);
168 if (!x)
170 set(list,MUIA_List_Active,MUIV_List_Active_Off);
171 break;
173 else
174 if (!stricmp(x,s))
176 set(list,MUIA_List_Active,i);
177 break;
181 return TRUE;
182 #ifdef __AROS__
183 AROS_USERFUNC_EXIT
184 #endif
187 #ifdef __MORPHOS__
188 static struct EmulLibEntry openTrap = {TRAP_LIB,0,(void (*)(void))openFun};
189 static struct Hook openHook = {0,0,(HOOKFUNC)&openTrap};
190 #else
191 static struct Hook openHook = {0,0,(HOOKFUNC)&openFun};
192 #endif
194 /***********************************************************************/
196 #ifdef __MORPHOS__
197 static void closeFun(void)
199 //struct Hook *hook = (struct Hook *)REG_A0;
200 Object *list = (Object *)REG_A2;
201 Object *str = (Object *)REG_A1;
202 #elif defined(__AROS__)
203 AROS_UFH3S(void, closeFun,
204 AROS_UFHA(struct Hook *, hook, A0),
205 AROS_UFHA(Object * , list, A2),
206 AROS_UFHA(Object * , str , A1))
208 AROS_USERFUNC_INIT
209 #else
210 static void SAVEDS ASM
211 closeFun(REG(a0,struct Hook *hook),REG(a2,Object *list),REG(a1,Object *str))
213 #endif
214 STRPTR port;
216 DoMethod(list,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,(ULONG)&port);
217 if (port)
219 TEXT buf[PORT_LEN], *dot, *digit;
221 dot = strrchr(port,'.');
223 if (dot)
225 dot++;
227 for (digit = dot; *digit; digit++)
228 if (!isdigit(*digit))
230 dot = NULL;
231 break;
234 if (dot)
236 stccpy(buf,port,dot-port);
237 port = buf;
242 set(str,MUIA_String_Contents,port);
243 #ifdef __AROS__
244 AROS_USERFUNC_EXIT
245 #endif
248 #ifdef __MORPHOS__
249 static struct EmulLibEntry closeTrap = {TRAP_LIB,0,(void (*)(void))closeFun};
250 static struct Hook closeHook = {0,0,(HOOKFUNC)&closeTrap};
251 #else
252 static struct Hook closeHook = {0,0,(HOOKFUNC)&closeFun};
253 #endif
255 /***********************************************************************/
257 static ULONG
258 mNew(struct IClass *cl,Object *obj,struct opSet *msg)
260 Object *lv;
262 if (obj = (Object *)DoSuperNew(cl,obj,
264 MUIA_Popstring_String, ostring(GetTagData(MUIA_Popport_Len,64,msg->ops_AttrList),GetTagData(MUIA_Popport_Key,0,msg->ops_AttrList),0),
265 MUIA_Popstring_Button, opopbutton(MUII_PopUp,0),
267 MUIA_Popobject_Object, lv = ListviewObject,
268 MUIA_Listview_List, listObject, End,
269 End,
270 MUIA_Popobject_WindowHook, &windowHook,
271 MUIA_Popobject_StrObjHook, &openHook,
272 MUIA_Popobject_ObjStrHook, &closeHook,
274 TAG_MORE,(ULONG)msg->ops_AttrList))
276 DoMethod(lv,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,(ULONG)obj,2,MUIM_Popstring_Close,TRUE);
279 return (ULONG)obj;
282 /***********************************************************************/
284 M_DISP(dispatcher)
286 M_DISPSTART
288 switch (msg->MethodID)
290 case OM_NEW: return mNew(cl,obj,(APTR)msg);
291 default: return DoSuperMethodA(cl,obj,msg);
295 M_DISPEND(dispatcher)
297 /***********************************************************************/
299 ULONG
300 initPopportClass(void)
302 if (initListClass())
304 if (g_popportClass = MUI_CreateCustomClass(NULL,MUIC_Popobject,NULL,0,DISP(dispatcher)))
305 return TRUE;
307 disposeListClass();
310 return FALSE;
313 /**************************************************************************/
315 void
316 disposePopportClass(void)
318 disposeListClass();
319 if (g_popportClass) MUI_DeleteCustomClass(g_popportClass);
322 /**************************************************************************/