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 <exec/execbase.h>
24 #include <libraries/asl.h>
31 /**************************************************************************/
36 static struct MUI_CustomClass
*listClass
= NULL
;
37 #define listObject NewObject(listClass->mcc_Class,NULL
46 /**************************************************************************/
48 HOOKPROTONHNO(conFun
, ULONG
, ULONG num
)
52 MakeStaticHook(conHook
, conFun
);
54 /**************************************************************************/
56 HOOKPROTO(dispFun
, void, STRPTR
*array
, ULONG num
)
58 struct listData
*data
= hook
->h_Data
;
64 *array
++ = data
->phs
[num
];
65 *array
= data
->names
[num
];
68 MakeStaticHook(dispHook
, dispFun
);
70 /**************************************************************************/
73 mListNew(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
75 struct TagItem
*attrs
= msg
->ops_AttrList
;
78 phs
= (STRPTR
*)GetTagData(MUIA_Popph_Syms
,(IPTR
)NULL
,attrs
);
79 names
= (STRPTR
*)GetTagData(MUIA_Popph_Names
,(IPTR
)NULL
,attrs
);
80 if (!phs
|| !names
) return 0;
82 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
84 MUIA_List_Format
, ",",
85 MUIA_List_Pool
, g_pool
,
86 MUIA_List_ConstructHook
, &conHook
,
87 TAG_MORE
, attrs
)) != NULL
)
89 struct listData
*data
= INST_DATA(cl
,obj
);
95 InitHook(&data
->dispHook
, dispHook
, data
);
97 superset(cl
,obj
,MUIA_List_DisplayHook
,&data
->dispHook
);
99 conHook
.h_Data
= data
;
101 for (i
= 0; phs
[i
]; i
++)
102 DoSuperMethod(cl
,obj
,MUIM_List_InsertSingle
,i
,MUIV_List_Insert_Bottom
);
108 /**************************************************************************/
110 SDISPATCHER(listDispatcher
)
112 switch (msg
->MethodID
)
114 case OM_NEW
: return mListNew(cl
,obj
,(APTR
)msg
);
116 default: return DoSuperMethodA(cl
,obj
,msg
);
120 /**************************************************************************/
122 static BOOL
initListClass(void)
124 BOOL success
= FALSE
;
128 if((listClass
= MUI_CreateCustomClass(NULL
, MUIC_List
, NULL
, sizeof(struct listData
), ENTRY(listDispatcher
))) != NULL
)
135 /**************************************************************************/
137 static void disposeListClass(void)
139 if(listClass
!= NULL
)
140 MUI_DeleteCustomClass(listClass
);
143 /**************************************************************************/
149 struct Hook closeHook
;
150 struct FileRequester
*req
;
156 /**************************************************************************/
158 HOOKPROTONH(windowFun
, void, Object
*pop
, Object
*win
)
160 set(win
,MUIA_Window_DefaultObject
,pop
);
162 MakeStaticHook(windowHook
, windowFun
);
164 /***********************************************************************/
166 HOOKPROTO(closeFun
, void, Object
*list
, Object
*str
)
168 struct data
*data
= hook
->h_Data
;
171 a
= xget(list
,MUIA_List_Active
);
177 pos
= xget(str
, MUIA_String_BufferPos
);
178 x
= (STRPTR
)xget(str
, MUIA_String_Contents
);
181 l
= strlen(data
->phs
[a
]);
183 if((buf
= AllocPooled(g_pool
,lx
+l
+1)) != NULL
)
185 if (pos
>0) CopyMem(x
,buf
,pos
);
186 CopyMem(data
->phs
[a
],buf
+pos
,l
);
187 if (lx
) CopyMem(x
+pos
,buf
+pos
+l
,lx
-pos
+1);
188 set(str
,MUIA_String_Contents
,buf
);
189 FreePooled(g_pool
,buf
,lx
+l
+1);
193 MakeStaticHook(closeHook
, closeFun
);
195 static IPTR
mNew(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
198 struct TagItem
*attrs
= msg
->ops_AttrList
;
201 phs
= (STRPTR
*)GetTagData(MUIA_Popph_Syms
,(IPTR
)NULL
,attrs
);
204 names
= (STRPTR
*)GetTagData(MUIA_Popph_Names
,FALSE
,attrs
);
205 if (!names
) return 0;
207 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
208 MUIA_Group_Horiz
, TRUE
,
209 MUIA_Group_HorizSpacing
, 1,
211 Child
, PopobjectObject
,
212 MUIA_Popstring_String
, str
= ostring(GetTagData(MUIA_Popph_MaxLen
,0,attrs
),GetTagData(MUIA_Popph_Key
,(IPTR
)NULL
,attrs
),0),
213 MUIA_Popstring_Button
, opopbutton(MUII_PopUp
,0),
214 MUIA_Popobject_Object
, lv
= ListviewObject
,
215 MUIA_Listview_List
, listObject
,
216 MUIA_Popph_Syms
, phs
,
217 MUIA_Popph_Names
, names
,
220 MUIA_Popobject_WindowHook
, &windowHook
,
223 TAG_MORE
, attrs
)) != NULL
)
226 struct data
*data
= INST_DATA(cl
,obj
);
233 InitHook(&data
->closeHook
, closeHook
, data
);
234 set(obj
,MUIA_Popobject_ObjStrHook
,&data
->closeHook
);
236 if (GetTagData(MUIA_Popph_Asl
,FALSE
,attrs
))
240 if((req
= MUI_AllocAslRequest(ASL_FileRequest
, NULL
)) != NULL
)
244 if((bt
= opopbutton(MUII_PopFile
, 0)) != NULL
)
246 DoSuperMethod(cl
,obj
,OM_ADDMEMBER
,(IPTR
)bt
);
250 DoMethod(bt
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(IPTR
)obj
,1,MUIM_Popph_RequestFile
);
252 else MUI_FreeAslRequest(req
);
256 DoMethod(lv
,MUIM_Notify
,MUIA_Listview_DoubleClick
,TRUE
,(IPTR
)obj
,2,MUIM_Popstring_Close
,TRUE
);
262 /***********************************************************************/
264 static IPTR
mDispose(struct IClass
*cl
, Object
*obj
, Msg msg
)
266 struct data
*data
= INST_DATA(cl
,obj
);
268 if (data
->req
) MUI_FreeAslRequest(data
->req
);
270 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
273 /***********************************************************************/
275 HOOKPROTONO(reqIntuiFun
, void, struct IntuiMessage
*imsg
)
277 if(imsg
->Class
==IDCMP_REFRESHWINDOW
)
278 DoMethod(hook
->h_Data
,MUIM_Application_CheckRefresh
);
280 MakeStaticHook(reqIntuiHook
, reqIntuiFun
);
282 static IPTR
mRequestFile(struct IClass
*cl
, Object
*obj
, UNUSED Msg msg
)
284 struct data
*data
= INST_DATA(cl
,obj
);
285 struct Hook intuiHook
;
286 TEXT path
[256], *x
, *file
, *p
;
288 set(_app(obj
),MUIA_Application_Sleep
,TRUE
);
290 InitHook(&intuiHook
, reqIntuiHook
, _app(obj
));
292 x
= (STRPTR
)xget(data
->str
, MUIA_String_Contents
);
294 if((p
= PathPart(x
)) != NULL
)
296 strlcpy(path
, x
, p
-x
+1);
300 if (MUI_AslRequestTags(data
->req
,
301 ASLFR_InitialFile
, (IPTR
)file
,
302 p
? ASLFR_InitialDrawer
: TAG_IGNORE
, (IPTR
)p
,
303 ASLFR_IntuiMsgFunc
, (IPTR
)&intuiHook
,
304 ASLFR_Window
, (IPTR
)_window(obj
),
305 ASLFR_PrivateIDCMP
, TRUE
,
306 ASLFR_Flags1
, FRF_INTUIFUNC
,
311 strlcpy(buf
, data
->req
->fr_Drawer
, sizeof(buf
));
312 AddPart(buf
, data
->req
->fr_File
, sizeof(buf
));
314 if (*buf
) set(data
->str
,MUIA_String_Contents
,buf
);
316 else if (IoErr()) DisplayBeep(0);
318 set(_app(obj
),MUIA_Application_Sleep
,FALSE
);
323 /***********************************************************************/
325 SDISPATCHER(dispatcher
)
327 switch (msg
->MethodID
)
329 case OM_NEW
: return mNew(cl
,obj
,(APTR
)msg
);
330 case OM_DISPOSE
: return mDispose(cl
,obj
,(APTR
)msg
);
332 case MUIM_Popph_RequestFile
: return mRequestFile(cl
,obj
,(APTR
)msg
);
334 default: return DoSuperMethodA(cl
,obj
,msg
);
338 /***********************************************************************/
340 BOOL
initPopphClass(void)
346 if(initListClass() == TRUE
)
348 if((g_popphClass
= MUI_CreateCustomClass(NULL
, MUIC_Group
, NULL
, sizeof(struct data
), ENTRY(dispatcher
))) != NULL
)
358 /**************************************************************************/
360 void disposePopphClass(void)
365 if(g_popphClass
!= NULL
)
366 MUI_DeleteCustomClass(g_popphClass
);
371 /**************************************************************************/