2 // 13 Nov 2004 19:37:42
7 #include <exec/types.h>
8 #include <intuition/classes.h>
9 #include <datatypes/iconobject.h>
11 #include <dos/dosextens.h>
12 #include <dos/dostags.h>
13 #include <scalos/scalos.h>
14 #include <workbench/workbench.h>
15 #include <workbench/icon.h>
17 #include <clib/alib_protos.h>
19 #include <proto/iconobject.h>
20 #include <proto/utility.h>
21 #include <proto/dos.h>
22 #include <proto/exec.h>
23 #include <proto/icon.h>
24 #include <proto/intuition.h>
25 #include <proto/scalos.h>
31 gets the "Global Identify Hook" from icon.library and calls this hook itself.
32 If DefIcons is being started automatically, like it is default in OS3.9,
33 its identify hook will be got from icon.library.
36 //----------------------------------------------------------------------------
40 // Forgot to set DTA_Name for generated default icons. Fixed.
41 //----------------------------------------------------------------------------
47 ULONG filetype
; // from FileInfoBlock fib_DirEntryType
58 extern int kprintf(const char *fmt
, ...);
60 static BOOL
Init(void);
61 SAVEDS(void) INTERRUPT ASM
DefIconsCleanup(void);
62 static BOOL
OpenLibraries(void);
63 static void CloseLibraries(void);
64 static Object
*GetDefIcon(Class
*cl
, Object
*obj
, struct SM_GetDefIcon
*msg
);
67 struct ExecBase
*SysBase
;
68 struct DosLibrary
*DOSBase
;
69 struct Library
*IconobjectBase
;
70 struct Library
*UtilityBase
;
71 struct Library
*IconBase
;
72 struct Library
*ScalosBase
;
73 struct IntuitionBase
*IntuitionBase
;
79 SAVEDS(ULONG
) INTERRUPT ASM
myHookFunc(REG(a0
, Class
*cl
),
85 d(kprintf(__FUNC__
"/%ld: MethodID=%08lx\n", __LINE__
, msg
->MethodID
));
87 switch (msg
->MethodID
)
89 case SCCM_IconWin_GetDefIcon
:
90 Result
= (ULONG
) GetDefIcon(cl
, obj
, (struct SM_GetDefIcon
*) msg
);
92 d(kprintf(__FUNC__
"/%ld: RootList=%08lx InternInfos=%08lx\n", __LINE__
, \
93 rList
, rList
->rl_internInfos
));
98 d(kprintf(__FUNC__
"/%ld: MethodID=%08lx\n", __LINE__
, msg
->MethodID
));
99 Result
= DoSuperMethodA(cl
, obj
, msg
);
107 SAVEDS(ULONG
) INTERRUPT ASM
DefIconsInit(void)
109 d(kprintf(__FUNC__
"/%ld: \n", __LINE__
));
113 BOOL Success
= fInit
= Init();
125 static BOOL
Init(void)
127 if (!OpenLibraries())
130 d(kprintf(__FUNC__
"/%ld: IconobjectBase=%08lx UtilityBase=%08lx\n", \
131 __LINE__
, IconobjectBase
, UtilityBase
));
137 SAVEDS(void) INTERRUPT ASM
DefIconsCleanup(void)
145 static BOOL
OpenLibraries(void)
148 SysBase
= *( (struct ExecBase
**) 4l);
151 DOSBase
= (struct DosLibrary
*) OpenLibrary(DOSNAME
, 39);
155 IconobjectBase
= OpenLibrary("iconobject.library", 39);
156 if (NULL
== IconobjectBase
)
159 UtilityBase
= OpenLibrary("utility.library", 40);
160 if (NULL
== UtilityBase
)
163 IconBase
= OpenLibrary("icon.library", 44);
164 if (NULL
== IconBase
)
167 IntuitionBase
= (struct IntuitionBase
*) OpenLibrary("intuition.library", 39);
168 if (NULL
== IntuitionBase
)
171 ScalosBase
= OpenLibrary(SCALOSNAME
, 41);
172 if (NULL
== ScalosBase
)
179 static void CloseLibraries(void)
183 CloseLibrary(ScalosBase
);
188 CloseLibrary((struct Library
*) IntuitionBase
);
189 IntuitionBase
= NULL
;
193 CloseLibrary(IconBase
);
198 CloseLibrary((struct Library
*) DOSBase
);
203 CloseLibrary(IconobjectBase
);
204 IconobjectBase
= NULL
;
208 CloseLibrary(UtilityBase
);
219 static Object
*GetDefIcon(Class
*cl
, Object
*obj
, struct SM_GetDefIcon
*msg
)
221 Object
*IconObj
= NULL
;
222 struct DiskObject
*diskObj
= NULL
;
223 struct Hook
*pHook
= NULL
;
225 d1(kprintf(__FUNC__
"/%ld: filename=<%s> type=%08lx protection=%08lx\n", __LINE__
, \
226 msg
->filename
, msg
->filetype
, msg
->protectionbits
));
230 ICONCTRLA_GetGlobalIdentifyHook
, &pHook
,
233 d1(kprintf(__FUNC__
"/%ld: pHook=%08lx\n", __LINE__
, pHook
));
236 struct TagItem EmptyTagList
= { TAG_END
, 0 };
238 struct FileInfoBlock
*fib
;
240 fLock
= Lock(msg
->filename
, ACCESS_READ
);
241 d1(kprintf(__FUNC__
"/%ld: fLock=%08lx\n", __LINE__
, fLock
));
245 BPTR parentLock
= ParentDir(fLock
);
247 fh
= Open(msg
->filename
, MODE_OLDFILE
);
249 fib
= AllocDosObject(DOS_FIB
, TAG_END
);
250 d1(kprintf(__FUNC__
"/%ld: fib=%08lx fh=%08lx\n", __LINE__
, fib
, fh
));
253 struct IconIdentifyMsg iim
;
257 iim
.iim_SysBase
= (struct Library
*) SysBase
;
258 iim
.iim_DOSBase
= (struct Library
*) DOSBase
;
259 iim
.iim_UtilityBase
= UtilityBase
;
260 iim
.iim_IconBase
= IconBase
;
262 iim
.iim_FileLock
= fLock
;
263 iim
.iim_ParentLock
= parentLock
;
265 iim
.iim_FileHandle
= fh
;
267 iim
.iim_Tags
= &EmptyTagList
;
269 diskObj
= (struct DiskObject
*) CallHookPkt(pHook
, NULL
, &iim
);
271 d1(kprintf(__FUNC__
"/%ld: diskobj=%08lx\n", __LINE__
, diskObj
));
273 FreeDosObject(DOS_FIB
, fib
);
285 d1(kprintf(__FUNC__
"/%ld: diskobj=%08lx FileType=%ld\n", __LINE__
, diskObj
, msg
->filetype
));
287 if (NULL
== diskObj
&& IconBase
->lib_Version
>= 44)
291 switch (msg
->filetype
)
303 iconType
= WBPROJECT
;
308 diskObj
= GetIconTags(msg
->filename
,
309 ICONGETA_GetDefaultType
, iconType
,
310 ICONGETA_FailIfUnavailable
, FALSE
,
312 d1(kprintf(__FUNC__
"/%ld: diskobj=%08lx\n", __LINE__
, diskObj
));
317 diskObj
= GetDiskObjectNew(msg
->filename
);
318 d1(kprintf(__FUNC__
"/%ld: diskobj=%08lx\n", __LINE__
, diskObj
));
321 d1(kprintf(__FUNC__
"/%ld: diskobj=%08lx\n", __LINE__
, diskObj
));
325 ULONG SupportedIconTypes
= ~0;
327 if (ScalosBase
->lib_Version
>= 40)
329 SCA_ScalosControl(NULL
,
330 SCALOSCTRLA_GetSupportedIconTypes
, &SupportedIconTypes
,
334 IconObj
= Convert2IconObjectTags(diskObj
,
335 IDTA_SupportedIconTypes
, SupportedIconTypes
,
341 DTA_Name
, msg
->filename
,
342 IDTA_DoFreeDiskObject
, TRUE
,
346 FreeDiskObject(diskObj
);
349 d1(if (diskObj
&& diskObj
->do_DrawerData
)\
350 kprintf(__FUNC__
"/%ld: dd_Flags=%08lx\n", __LINE__
, diskObj
->do_DrawerData
->dd_Flags
));
352 d1(kprintf(__FUNC__
"/%ld: IconObj=%08lx\n", __LINE__
, diskObj
, IconObj
));