2 ** OpenURL - MUI preferences for openurl.library
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
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
18 #include <exec/execbase.h>
19 #include <libraries/asl.h>
21 /**************************************************************************/
26 static struct MUI_CustomClass
*listClass
= NULL
;
27 #define listObject NewObject(listClass->mcc_Class,NULL
36 /**************************************************************************/
44 static ULONG SAVEDS ASM
45 conFun(REG(a0
,struct Hook
*hook
),REG(a2
,APTR pool
),REG(a1
,ULONG num
))
52 static struct EmulLibEntry conTrap
= {TRAP_LIB
,0,(void (*)(void))conFun
};
53 static struct Hook conHook
= {0,0,(HOOKFUNC
)&conTrap
};
55 static struct Hook conHook
= {0,0,(HOOKFUNC
)conFun
};
58 /**************************************************************************/
64 struct Hook
*hook
= (struct Hook
*)REG_a0
;
65 UBYTE
**array
= (UBYTE
**)REG_A2
;
68 static void SAVEDS ASM
69 dispFun(REG(a0
,struct Hook
*hook
),REG(a2
,UBYTE
**array
),REG(a1
,ULONG num
))
72 struct listData
*data
= hook
->h_Data
;
78 *array
++ = data
->phs
[num
];
79 *array
= data
->names
[num
];
84 static struct EmulLibEntry dispTrap
= {TRAP_LIBNR
,0,(void (*)(void))dispFun
};
87 /**************************************************************************/
90 mListNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
92 struct TagItem
*attrs
= msg
->ops_AttrList
;
95 phs
= (UBYTE
**)GetTagData(MUIA_Popph_Syms
,(ULONG
)NULL
,attrs
);
96 names
= (UBYTE
**)GetTagData(MUIA_Popph_Names
,(ULONG
)NULL
,attrs
);
97 if (!phs
|| !names
) return 0;
99 if (obj
= (Object
*)DoSuperNew(cl
,obj
,
101 MUIA_List_Format
, ",",
102 MUIA_List_Pool
, g_pool
,
103 MUIA_List_ConstructHook
, &conHook
,
106 struct listData
*data
= INST_DATA(cl
,obj
);
113 data
->dispHook
.h_Entry
= (HOOKFUNC
)&dispTrap
;
115 data
->dispHook
.h_Entry
= (HOOKFUNC
)dispFun
;
117 data
->dispHook
.h_Data
= data
;
119 superset(cl
,obj
,MUIA_List_DisplayHook
,&data
->dispHook
);
121 conHook
.h_Data
= data
;
123 for (i
= 0; phs
[i
]; i
++)
124 DoSuperMethod(cl
,obj
,MUIM_List_InsertSingle
,i
,MUIV_List_Insert_Bottom
);
130 /**************************************************************************/
132 M_DISP(listDispatcher
)
136 switch (msg
->MethodID
)
138 case OM_NEW
: return mListNew(cl
,obj
,(APTR
)msg
);
140 default: return DoSuperMethodA(cl
,obj
,msg
);
144 M_DISPEND(listDispatcher
)
146 /**************************************************************************/
151 return (ULONG
)(listClass
= MUI_CreateCustomClass(NULL
,MUIC_List
,NULL
,sizeof(struct listData
),DISP(listDispatcher
)));
154 /**************************************************************************/
157 disposeListClass(void)
159 if (listClass
) MUI_DeleteCustomClass(listClass
);
162 /**************************************************************************/
168 struct Hook closeHook
;
169 struct FileRequester
*req
;
175 /**************************************************************************/
181 //struct Hook *hook = (struct Hook *)REG_A0;
182 Object
*pop
= (Object
*)REG_A2
;
183 Object
*win
= (Object
*)REG_A1
;
185 static void SAVEDS ASM
186 windowFun(REG(a0
,struct Hook
*hook
),REG(a2
,Object
*pop
),REG(a1
,Object
*win
))
189 set(win
,MUIA_Window_DefaultObject
,pop
);
193 static struct EmulLibEntry windowTrap
= {TRAP_LIB
,0,(void (*)(void))windowFun
};
194 static struct Hook windowHook
= {0,0,(HOOKFUNC
)&windowTrap
};
196 static struct Hook windowHook
= {0,0,(HOOKFUNC
)&windowFun
};
199 /***********************************************************************/
202 static void closeFun(void)
204 struct Hook
*hook
= (struct Hook
*)REG_A0
;
205 Object
*list
= (Object
*)REG_A2
;
206 Object
*str
= (Object
*)REG_A1
;
208 static void SAVEDS ASM
209 closeFun(REG(a0
,struct Hook
*hook
),REG(a2
,Object
*list
),REG(a1
,Object
*str
))
212 struct data
*data
= hook
->h_Data
;
215 get(list
,MUIA_List_Active
,&a
);
221 get(str
,MUIA_String_BufferPos
,&pos
);
222 get(str
,MUIA_String_Contents
,&x
);
225 l
= strlen(data
->phs
[a
]);
227 if (buf
= AllocPooled(g_pool
,lx
+l
+1))
229 if (pos
>0) CopyMem(x
,buf
,pos
);
230 CopyMem(data
->phs
[a
],buf
+pos
,l
);
231 if (lx
) CopyMem(x
+pos
,buf
+pos
+l
,lx
-pos
+1);
232 set(str
,MUIA_String_Contents
,buf
);
233 FreePooled(g_pool
,buf
,lx
+l
+1);
239 static struct EmulLibEntry closeTrap
= {TRAP_LIB
,0,(void (*)(void))closeFun
};
243 mNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
246 struct TagItem
*attrs
= msg
->ops_AttrList
;
249 phs
= (STRPTR
*)GetTagData(MUIA_Popph_Syms
,(ULONG
)NULL
,attrs
);
252 names
= (STRPTR
*)GetTagData(MUIA_Popph_Names
,FALSE
,attrs
);
253 if (!names
) return 0;
255 if (obj
= (Object
*)DoSuperNew(cl
,obj
,
256 MUIA_Group_Horiz
, TRUE
,
257 MUIA_Group_HorizSpacing
, 1,
259 Child
, PopobjectObject
,
260 MUIA_Popstring_String
, str
= ostring(GetTagData(MUIA_Popph_MaxLen
,0,attrs
),GetTagData(MUIA_Popph_Key
,(ULONG
)NULL
,attrs
),0),
261 MUIA_Popstring_Button
, opopbutton(MUII_PopUp
,0),
262 MUIA_Popobject_Object
, lv
= ListviewObject
,
263 MUIA_Listview_List
, listObject
,
264 MUIA_Popph_Syms
, phs
,
265 MUIA_Popph_Names
, names
,
268 MUIA_Popobject_WindowHook
, &windowHook
,
274 struct data
*data
= INST_DATA(cl
,obj
);
282 data
->closeHook
.h_Entry
= (HOOKFUNC
)&closeTrap
;
284 data
->closeHook
.h_Entry
= (HOOKFUNC
)closeFun
;
286 data
->closeHook
.h_Data
= data
;
287 set(obj
,MUIA_Popobject_ObjStrHook
,&data
->closeHook
);
289 if (GetTagData(MUIA_Popph_Asl
,FALSE
,attrs
))
293 if (req
= MUI_AllocAslRequest(ASL_FileRequest
,NULL
))
297 if (bt
= opopbutton(MUII_PopFile
,0))
299 DoSuperMethod(cl
,obj
,OM_ADDMEMBER
,(ULONG
)bt
);
303 DoMethod(bt
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(ULONG
)obj
,1,MUIM_Popph_RequestFile
);
305 else MUI_FreeAslRequest(req
);
309 DoMethod(lv
,MUIM_Notify
,MUIA_Listview_DoubleClick
,TRUE
,(ULONG
)obj
,2,MUIM_Popstring_Close
,TRUE
);
315 /***********************************************************************/
318 mDispose(struct IClass
*cl
,Object
*obj
,Msg msg
)
320 struct data
*data
= INST_DATA(cl
,obj
);
322 if (data
->req
) MUI_FreeAslRequest(data
->req
);
324 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
327 /***********************************************************************/
333 struct Hook
*hook
= (struct Hook
*)REG_A0
;
334 struct IntuiMessage
*imsg
= (struct IntuiMessage
*)REG_A1
;
336 static void SAVEDS ASM
337 reqIntuiFun(REG(a0
,struct Hook
*hook
),REG(a1
,struct IntuiMessage
*imsg
))
340 if (imsg
->Class
==IDCMP_REFRESHWINDOW
)
341 DoMethod(hook
->h_Data
,MUIM_Application_CheckRefresh
);
345 static struct EmulLibEntry reqIntuiTrap
= {TRAP_LIBNR
,0,(void (*)(void))reqIntuiFun
};
349 mRequestFile(struct IClass
*cl
,Object
*obj
,Msg msg
)
351 struct data
*data
= INST_DATA(cl
,obj
);
352 struct Hook reqIntuiHook
= {0};
353 TEXT path
[256], *x
, *file
, *p
;
355 set(_app(obj
),MUIA_Application_Sleep
,TRUE
);
358 reqIntuiHook
.h_Entry
= (HOOKFUNC
)&reqIntuiTrap
;
360 reqIntuiHook
.h_Entry
= (HOOKFUNC
)reqIntuiFun
;
362 reqIntuiHook
.h_Data
= _app(obj
);
365 get(data
->str
,MUIA_String_Contents
,&x
);
369 stccpy(path
,x
,p
-x
+1);
373 if (MUI_AslRequestTags(data
->req
,
374 ASLFR_InitialFile
, (ULONG
)file
,
375 p
? ASLFR_InitialDrawer
: TAG_IGNORE
, (ULONG
)p
,
376 ASLFR_IntuiMsgFunc
, (ULONG
)&reqIntuiHook
,
377 ASLFR_Window
, (ULONG
)_window(obj
),
378 ASLFR_PrivateIDCMP
, TRUE
,
379 ASLFR_Flags1
, FRF_INTUIFUNC
,
384 strcpy(buf
,data
->req
->fr_Drawer
);
385 AddPart(buf
,data
->req
->fr_File
,sizeof(buf
));
387 if (*buf
) set(data
->str
,MUIA_String_Contents
,buf
);
389 else if (IoErr()) DisplayBeep(0);
391 set(_app(obj
),MUIA_Application_Sleep
,FALSE
);
396 /***********************************************************************/
402 switch (msg
->MethodID
)
404 case OM_NEW
: return mNew(cl
,obj
,(APTR
)msg
);
405 case OM_DISPOSE
: return mDispose(cl
,obj
,(APTR
)msg
);
407 case MUIM_Popph_RequestFile
: return mRequestFile(cl
,obj
,(APTR
)msg
);
409 default: return DoSuperMethodA(cl
,obj
,msg
);
413 M_DISPEND(dispatcher
)
415 /***********************************************************************/
422 if (g_popphClass
= MUI_CreateCustomClass(NULL
,MUIC_Group
,NULL
,sizeof(struct data
),DISP(dispatcher
)))
433 /**************************************************************************/
436 disposePopphClass(void)
439 if (g_popphClass
) MUI_DeleteCustomClass(g_popphClass
);
442 /**************************************************************************/