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/
19 ***************************************************************************/
23 #include <libraries/openurl.h>
24 #include <exec/execbase.h>
31 /**************************************************************************/
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
)
58 if(DoSuperMethodA(cl
, obj
, msg
))
60 struct List
*portList
;
67 DoSuperMethod(cl
, obj
, MUIM_List_Clear
);
69 #if defined(__amigaos4__)
70 portList
= AllocSysObjectTags(ASOT_LIST
, TAG_DONE
);
72 portList
= AllocVec(sizeof(*portList
), MEMF_ANY
);
78 struct PortNode
*portNode
;
80 #if !defined(__amigaos4__)
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
);
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
);
116 #if defined(__amigaos4__)
117 FreeSysObject(ASOT_LIST
, portList
);
123 // signal success, even if copying the list failed for some reason
124 // but the MUIM_Setup invocation of the super class succeeded.
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
;
154 if((listClass
= MUI_CreateCustomClass(NULL
, MUIC_List
, NULL
, 0, ENTRY(listDispatcher
))) != NULL
)
161 /**************************************************************************/
163 static void disposeListClass(void)
167 if(listClass
!= NULL
)
168 MUI_DeleteCustomClass(listClass
);
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
)
188 s
= (STRPTR
)xget(str
,MUIA_String_Contents
);
192 DoMethod(list
,MUIM_List_GetEntry
,i
,(IPTR
)&x
);
195 set(list
,MUIA_List_Active
,MUIV_List_Active_Off
);
201 set(list
,MUIA_List_Active
,i
);
208 MakeStaticHook(openHook
, openFun
);
210 /***********************************************************************/
212 HOOKPROTONH(closeFun
, void, Object
*list
, Object
*str
)
216 DoMethod(list
,MUIM_List_GetEntry
,MUIV_List_GetEntry_Active
,(IPTR
)&port
);
219 TEXT buf
[PORT_LEN
], *dot
, *digit
;
221 dot
= strrchr(port
,'.');
227 for (digit
= dot
; *digit
; digit
++)
228 if (!isdigit(*digit
))
236 strlcpy(buf
, port
, dot
-port
);
242 set(str
,MUIA_String_Contents
,port
);
244 MakeStaticHook(closeHook
, closeFun
);
246 /***********************************************************************/
248 static IPTR
mNew(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
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
,
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
);
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
;
291 if(initListClass() == TRUE
)
293 if((g_popportClass
= MUI_CreateCustomClass(NULL
, MUIC_Popobject
, NULL
, 0, ENTRY(dispatcher
))) != NULL
)
303 /**************************************************************************/
305 void disposePopportClass(void)
310 if(g_popportClass
!= NULL
)
311 MUI_DeleteCustomClass(g_popportClass
);
316 /**************************************************************************/