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
;
28 #define listObject BOOPSIOBJMACRO_START(listClass->mcc_Class)
30 #define listObject NewObject(listClass->mcc_Class,NULL
40 /**************************************************************************/
47 #elif defined(__AROS__)
48 AROS_UFH3S(ULONG
, conFun
,
49 AROS_UFHA(struct Hook
*, hook
, A0
),
50 AROS_UFHA(APTR
, pool
, A2
),
51 AROS_UFHA(ULONG
, num
, A1
))
55 static ULONG SAVEDS ASM
56 conFun(REG(a0
,struct Hook
*hook
),REG(a2
,APTR pool
),REG(a1
,ULONG num
))
66 static struct EmulLibEntry conTrap
= {TRAP_LIB
,0,(void (*)(void))conFun
};
67 static struct Hook conHook
= {0,0,(HOOKFUNC
)&conTrap
};
69 static struct Hook conHook
= {0,0,(HOOKFUNC
)conFun
};
72 /**************************************************************************/
78 struct Hook
*hook
= (struct Hook
*)REG_a0
;
79 UBYTE
**array
= (UBYTE
**)REG_A2
;
81 #elif defined(__AROS__)
82 AROS_UFH3S(void, dispFun
,
83 AROS_UFHA(struct Hook
*, hook
, A0
),
84 AROS_UFHA(UBYTE
** , array
, A2
),
85 AROS_UFHA(ULONG
, num
, A1
))
89 static void SAVEDS ASM
90 dispFun(REG(a0
,struct Hook
*hook
),REG(a2
,UBYTE
**array
),REG(a1
,ULONG num
))
93 struct listData
*data
= hook
->h_Data
;
99 *array
++ = data
->phs
[num
];
100 *array
= data
->names
[num
];
108 static struct EmulLibEntry dispTrap
= {TRAP_LIBNR
,0,(void (*)(void))dispFun
};
111 /**************************************************************************/
114 mListNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
116 struct TagItem
*attrs
= msg
->ops_AttrList
;
117 UBYTE
**phs
, **names
;
119 phs
= (UBYTE
**)GetTagData(MUIA_Popph_Syms
,(ULONG
)NULL
,attrs
);
120 names
= (UBYTE
**)GetTagData(MUIA_Popph_Names
,(ULONG
)NULL
,attrs
);
121 if (!phs
|| !names
) return 0;
123 if (obj
= (Object
*)DoSuperNew(cl
,obj
,
125 MUIA_List_Format
, ",",
126 MUIA_List_Pool
, g_pool
,
127 MUIA_List_ConstructHook
, &conHook
,
130 struct listData
*data
= INST_DATA(cl
,obj
);
137 data
->dispHook
.h_Entry
= (HOOKFUNC
)&dispTrap
;
139 data
->dispHook
.h_Entry
= (HOOKFUNC
)dispFun
;
141 data
->dispHook
.h_Data
= data
;
143 superset(cl
,obj
,MUIA_List_DisplayHook
,&data
->dispHook
);
145 conHook
.h_Data
= data
;
147 for (i
= 0; phs
[i
]; i
++)
148 DoSuperMethod(cl
,obj
,MUIM_List_InsertSingle
,i
,MUIV_List_Insert_Bottom
);
154 /**************************************************************************/
156 M_DISP(listDispatcher
)
160 switch (msg
->MethodID
)
162 case OM_NEW
: return mListNew(cl
,obj
,(APTR
)msg
);
164 default: return DoSuperMethodA(cl
,obj
,msg
);
168 M_DISPEND(listDispatcher
)
170 /**************************************************************************/
175 return (ULONG
)(listClass
= MUI_CreateCustomClass(NULL
,MUIC_List
,NULL
,sizeof(struct listData
),DISP(listDispatcher
)));
178 /**************************************************************************/
181 disposeListClass(void)
183 if (listClass
) MUI_DeleteCustomClass(listClass
);
186 /**************************************************************************/
192 struct Hook closeHook
;
193 struct FileRequester
*req
;
199 /**************************************************************************/
205 //struct Hook *hook = (struct Hook *)REG_A0;
206 Object
*pop
= (Object
*)REG_A2
;
207 Object
*win
= (Object
*)REG_A1
;
208 #elif defined(__AROS__)
209 AROS_UFH3S(void, windowFun
,
210 AROS_UFHA(struct Hook
*, hook
, A0
),
211 AROS_UFHA(Object
* , pop
, A2
),
212 AROS_UFHA(Object
* , win
, A1
))
216 static void SAVEDS ASM
217 windowFun(REG(a0
,struct Hook
*hook
),REG(a2
,Object
*pop
),REG(a1
,Object
*win
))
220 set(win
,MUIA_Window_DefaultObject
,pop
);
227 static struct EmulLibEntry windowTrap
= {TRAP_LIB
,0,(void (*)(void))windowFun
};
228 static struct Hook windowHook
= {0,0,(HOOKFUNC
)&windowTrap
};
230 static struct Hook windowHook
= {0,0,(HOOKFUNC
)&windowFun
};
233 /***********************************************************************/
236 static void closeFun(void)
238 struct Hook
*hook
= (struct Hook
*)REG_A0
;
239 Object
*list
= (Object
*)REG_A2
;
240 Object
*str
= (Object
*)REG_A1
;
241 #elif defined(__AROS__)
242 AROS_UFH3S(void, closeFun
,
243 AROS_UFHA(struct Hook
*, hook
, A0
),
244 AROS_UFHA(Object
* , list
, A2
),
245 AROS_UFHA(Object
* , str
, A1
))
249 static void SAVEDS ASM
250 closeFun(REG(a0
,struct Hook
*hook
),REG(a2
,Object
*list
),REG(a1
,Object
*str
))
253 struct data
*data
= hook
->h_Data
;
256 get(list
,MUIA_List_Active
,&a
);
262 get(str
,MUIA_String_BufferPos
,&pos
);
263 get(str
,MUIA_String_Contents
,&x
);
266 l
= strlen(data
->phs
[a
]);
268 if (buf
= AllocPooled(g_pool
,lx
+l
+1))
270 if (pos
>0) CopyMem(x
,buf
,pos
);
271 CopyMem(data
->phs
[a
],buf
+pos
,l
);
272 if (lx
) CopyMem(x
+pos
,buf
+pos
+l
,lx
-pos
+1);
273 set(str
,MUIA_String_Contents
,buf
);
274 FreePooled(g_pool
,buf
,lx
+l
+1);
283 static struct EmulLibEntry closeTrap
= {TRAP_LIB
,0,(void (*)(void))closeFun
};
287 mNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
290 struct TagItem
*attrs
= msg
->ops_AttrList
;
293 phs
= (STRPTR
*)GetTagData(MUIA_Popph_Syms
,(ULONG
)NULL
,attrs
);
296 names
= (STRPTR
*)GetTagData(MUIA_Popph_Names
,FALSE
,attrs
);
297 if (!names
) return 0;
299 if (obj
= (Object
*)DoSuperNew(cl
,obj
,
300 MUIA_Group_Horiz
, TRUE
,
301 MUIA_Group_HorizSpacing
, 1,
303 Child
, PopobjectObject
,
304 MUIA_Popstring_String
, str
= ostring(GetTagData(MUIA_Popph_MaxLen
,0,attrs
),GetTagData(MUIA_Popph_Key
,(ULONG
)NULL
,attrs
),0),
305 MUIA_Popstring_Button
, opopbutton(MUII_PopUp
,0),
306 MUIA_Popobject_Object
, lv
= ListviewObject
,
307 MUIA_Listview_List
, listObject
,
308 MUIA_Popph_Syms
, phs
,
309 MUIA_Popph_Names
, names
,
312 MUIA_Popobject_WindowHook
, &windowHook
,
318 struct data
*data
= INST_DATA(cl
,obj
);
326 data
->closeHook
.h_Entry
= (HOOKFUNC
)&closeTrap
;
328 data
->closeHook
.h_Entry
= (HOOKFUNC
)closeFun
;
330 data
->closeHook
.h_Data
= data
;
331 set(obj
,MUIA_Popobject_ObjStrHook
,&data
->closeHook
);
333 if (GetTagData(MUIA_Popph_Asl
,FALSE
,attrs
))
337 if (req
= MUI_AllocAslRequest(ASL_FileRequest
,NULL
))
341 if (bt
= opopbutton(MUII_PopFile
,0))
343 DoSuperMethod(cl
,obj
,OM_ADDMEMBER
,(ULONG
)bt
);
347 DoMethod(bt
,MUIM_Notify
,MUIA_Pressed
,FALSE
,(ULONG
)obj
,1,MUIM_Popph_RequestFile
);
349 else MUI_FreeAslRequest(req
);
353 DoMethod(lv
,MUIM_Notify
,MUIA_Listview_DoubleClick
,TRUE
,(ULONG
)obj
,2,MUIM_Popstring_Close
,TRUE
);
359 /***********************************************************************/
362 mDispose(struct IClass
*cl
,Object
*obj
,Msg msg
)
364 struct data
*data
= INST_DATA(cl
,obj
);
366 if (data
->req
) MUI_FreeAslRequest(data
->req
);
368 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
371 /***********************************************************************/
377 struct Hook
*hook
= (struct Hook
*)REG_A0
;
378 struct IntuiMessage
*imsg
= (struct IntuiMessage
*)REG_A1
;
379 #elif defined(__AROS__)
380 AROS_UFH3S(void, reqIntuiFun
,
381 AROS_UFHA(struct Hook
* , hook
, A0
),
382 AROS_UFHA(Object
* , dummy
, A2
),
383 AROS_UFHA(struct IntuiMessage
*, imsg
, A1
))
387 static void SAVEDS ASM
388 reqIntuiFun(REG(a0
,struct Hook
*hook
),REG(a1
,struct IntuiMessage
*imsg
))
391 if (imsg
->Class
==IDCMP_REFRESHWINDOW
)
392 DoMethod(hook
->h_Data
,MUIM_Application_CheckRefresh
);
399 static struct EmulLibEntry reqIntuiTrap
= {TRAP_LIBNR
,0,(void (*)(void))reqIntuiFun
};
403 mRequestFile(struct IClass
*cl
,Object
*obj
,Msg msg
)
405 struct data
*data
= INST_DATA(cl
,obj
);
406 struct Hook reqIntuiHook
= {0};
407 TEXT path
[256], *x
, *file
, *p
;
409 set(_app(obj
),MUIA_Application_Sleep
,TRUE
);
412 reqIntuiHook
.h_Entry
= (HOOKFUNC
)&reqIntuiTrap
;
414 reqIntuiHook
.h_Entry
= (HOOKFUNC
)reqIntuiFun
;
416 reqIntuiHook
.h_Data
= _app(obj
);
419 get(data
->str
,MUIA_String_Contents
,&x
);
423 stccpy(path
,x
,p
-x
+1);
427 if (MUI_AslRequestTags(data
->req
,
428 ASLFR_InitialFile
, (ULONG
)file
,
429 p
? ASLFR_InitialDrawer
: TAG_IGNORE
, (ULONG
)p
,
430 ASLFR_IntuiMsgFunc
, (ULONG
)&reqIntuiHook
,
431 ASLFR_Window
, (ULONG
)_window(obj
),
432 ASLFR_PrivateIDCMP
, TRUE
,
433 ASLFR_Flags1
, FRF_INTUIFUNC
,
438 strcpy(buf
,data
->req
->fr_Drawer
);
439 AddPart(buf
,data
->req
->fr_File
,sizeof(buf
));
441 if (*buf
) set(data
->str
,MUIA_String_Contents
,buf
);
443 else if (IoErr()) DisplayBeep(0);
445 set(_app(obj
),MUIA_Application_Sleep
,FALSE
);
450 /***********************************************************************/
456 switch (msg
->MethodID
)
458 case OM_NEW
: return mNew(cl
,obj
,(APTR
)msg
);
459 case OM_DISPOSE
: return mDispose(cl
,obj
,(APTR
)msg
);
461 case MUIM_Popph_RequestFile
: return mRequestFile(cl
,obj
,(APTR
)msg
);
463 default: return DoSuperMethodA(cl
,obj
,msg
);
467 M_DISPEND(dispatcher
)
469 /***********************************************************************/
476 if (g_popphClass
= MUI_CreateCustomClass(NULL
,MUIC_Group
,NULL
,sizeof(struct data
),DISP(dispatcher
)))
487 /**************************************************************************/
490 disposePopphClass(void)
493 if (g_popphClass
) MUI_DeleteCustomClass(g_popphClass
);
496 /**************************************************************************/