make.tmpl: add missing compiler attribute to build_progs
[AROS.git] / external / openurl / prefs / popport.c
blob7a9e2e39d13d7dd0bfa6baafe53da657fb20fb7d
1 /***************************************************************************
3 openurl.library - universal URL display and browser launcher library
4 Copyright (C) 1998-2005 by Troels Walsted Hansen, et al.
5 Copyright (C) 2005-2013 by openurl.library Open Source Team
7 This library is free software; it has been placed in the public domain
8 and you can freely redistribute it and/or modify it. Please note, however,
9 that some components may be under the LGPL or GPL license.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 openurl.library project: http://sourceforge.net/projects/openurllib/
17 $Id$
19 ***************************************************************************/
21 #include "openurl.h"
23 #include <libraries/openurl.h>
24 #include <exec/execbase.h>
26 #include "SDI_hook.h"
27 #include "macros.h"
29 #include "debug.h"
31 /**************************************************************************/
33 ** Public ports list
36 static struct MUI_CustomClass *listClass = NULL;
37 #define listObject NewObject(listClass->mcc_Class,NULL
39 static IPTR mListNew(struct IClass *cl, Object *obj, struct opSet *msg)
41 return (IPTR)DoSuperNew(cl,obj,
42 MUIA_Frame, MUIV_Frame_InputList,
43 MUIA_Background, MUII_ListBack,
44 MUIA_List_AutoVisible, TRUE,
45 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
46 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
47 TAG_MORE,(IPTR)msg->ops_AttrList);
50 /**************************************************************************/
52 static IPTR mListSetup(struct IClass *cl, Object *obj, Msg msg)
54 IPTR success = FALSE;
56 ENTER();
58 if(DoSuperMethodA(cl, obj, msg))
60 struct List *portList;
61 struct PortNode
63 struct Node node;
64 STRPTR name;
67 DoSuperMethod(cl, obj, MUIM_List_Clear);
69 #if defined(__amigaos4__)
70 portList = AllocSysObjectTags(ASOT_LIST, TAG_DONE);
71 #else
72 portList = AllocVec(sizeof(*portList), MEMF_ANY);
73 #endif
75 if(portList != NULL)
77 struct Node *mstate;
78 struct PortNode *portNode;
80 #if !defined(__amigaos4__)
81 NewList(portList);
82 #endif
84 Forbid();
86 for(mstate = SysBase->PortList.lh_Head; mstate->ln_Succ; mstate = mstate->ln_Succ)
88 // don't distinguish between OS4 and other systems here, because AllocSysObject()
89 // might do things which break the surrounding Forbid(), which AllocVec() is
90 // guaranteed *NOT* to do.
91 if((portNode = AllocVecShared(sizeof(*portNode), MEMF_CLEAR)) != NULL)
93 if((portNode->name = AllocVecShared(strlen(mstate->ln_Name)+1, MEMF_ANY)) != NULL)
95 strcpy(portNode->name, mstate->ln_Name);
96 AddTail(portList, &portNode->node);
98 else
99 FreeVec(portNode);
103 Permit();
105 // now that the port names have been copied we can insert them into the list
106 while((portNode = (struct PortNode *)RemHead(portList)) != NULL)
108 DoSuperMethod(cl, obj, MUIM_List_InsertSingle, portNode->name, MUIV_List_Insert_Sorted);
110 // free the complete node, the name was already copied during MUIM_List_InsertSingle
111 // due to the given construct hook
112 FreeVec(portNode->name);
113 FreeVec(portNode);
116 #if defined(__amigaos4__)
117 FreeSysObject(ASOT_LIST, portList);
118 #else
119 FreeVec(portList);
120 #endif
123 // signal success, even if copying the list failed for some reason
124 // but the MUIM_Setup invocation of the super class succeeded.
125 success = TRUE;
128 RETURN(success);
129 return success;
132 /**************************************************************************/
134 SDISPATCHER(listDispatcher)
136 switch (msg->MethodID)
138 case OM_NEW: return mListNew(cl,obj,(APTR)msg);
140 case MUIM_Setup: return mListSetup(cl,obj,(APTR)msg);
142 default: return DoSuperMethodA(cl,obj,msg);
146 /**************************************************************************/
148 static BOOL initListClass(void)
150 BOOL success = FALSE;
152 ENTER();
154 if((listClass = MUI_CreateCustomClass(NULL, MUIC_List, NULL, 0, ENTRY(listDispatcher))) != NULL)
155 success = TRUE;
157 RETURN(success);
158 return success;
161 /**************************************************************************/
163 static void disposeListClass(void)
165 ENTER();
167 if(listClass != NULL)
168 MUI_DeleteCustomClass(listClass);
170 LEAVE();
173 /**************************************************************************/
175 HOOKPROTONH(windowFun, void, Object *pop, Object *win)
177 set(win,MUIA_Window_DefaultObject,pop);
179 MakeStaticHook(windowHook, windowFun);
181 /***********************************************************************/
183 HOOKPROTONH(openFun, ULONG, Object *list, Object *str)
185 STRPTR s, x;
186 int i;
188 s = (STRPTR)xget(str,MUIA_String_Contents);
190 for (i = 0; ;i++)
192 DoMethod(list,MUIM_List_GetEntry,i,(IPTR)&x);
193 if (!x)
195 set(list,MUIA_List_Active,MUIV_List_Active_Off);
196 break;
198 else
199 if (!stricmp(x,s))
201 set(list,MUIA_List_Active,i);
202 break;
206 return TRUE;
208 MakeStaticHook(openHook, openFun);
210 /***********************************************************************/
212 HOOKPROTONH(closeFun, void, Object *list, Object *str)
214 STRPTR port;
216 DoMethod(list,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,(IPTR)&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 strlcpy(buf, port, dot-port);
237 port = buf;
242 set(str,MUIA_String_Contents,port);
244 MakeStaticHook(closeHook, closeFun);
246 /***********************************************************************/
248 static IPTR mNew(struct IClass *cl, Object *obj, struct opSet *msg)
250 Object *lv;
252 if((obj = (Object *)DoSuperNew(cl,obj,
254 MUIA_Popstring_String, ostring(GetTagData(MUIA_Popport_Len,64,msg->ops_AttrList),GetTagData(MUIA_Popport_Key,0,msg->ops_AttrList),0),
255 MUIA_Popstring_Button, opopbutton(MUII_PopUp,0),
257 MUIA_Popobject_Object, lv = ListviewObject,
258 MUIA_Listview_List, listObject, End,
259 End,
260 MUIA_Popobject_WindowHook, &windowHook,
261 MUIA_Popobject_StrObjHook, &openHook,
262 MUIA_Popobject_ObjStrHook, &closeHook,
264 TAG_MORE,(IPTR)msg->ops_AttrList)) != NULL)
266 DoMethod(lv,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,(IPTR)obj,2,MUIM_Popstring_Close,TRUE);
269 return (IPTR)obj;
272 /***********************************************************************/
274 SDISPATCHER(dispatcher)
276 switch (msg->MethodID)
278 case OM_NEW: return mNew(cl,obj,(APTR)msg);
279 default: return DoSuperMethodA(cl,obj,msg);
283 /***********************************************************************/
285 BOOL initPopportClass(void)
287 BOOL success = FALSE;
289 ENTER();
291 if(initListClass() == TRUE)
293 if((g_popportClass = MUI_CreateCustomClass(NULL, MUIC_Popobject, NULL, 0, ENTRY(dispatcher))) != NULL)
294 success = TRUE;
295 else
296 disposeListClass();
299 RETURN(success);
300 return success;
303 /**************************************************************************/
305 void disposePopportClass(void)
307 ENTER();
309 disposeListClass();
310 if(g_popportClass != NULL)
311 MUI_DeleteCustomClass(g_popportClass);
313 LEAVE();
316 /**************************************************************************/