Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / Wanderer / Classes / icondrawerlist.c
blob69843323adb766316a9d3e7d1bca55c8c3b80259
1 /*
2 Copyright 2002-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef __AROS__
7 #include "../portable_macros.h"
8 #define WANDERER_BUILTIN_ICONDRAWERLIST 1
9 #else
10 #define DEBUG 0
11 #include <aros/debug.h>
12 #endif
14 #define DEBUG_ILC_EVENTS
15 #define DEBUG_ILC_KEYEVENTS
16 #define DEBUG_ILC_ICONRENDERING
17 #define DEBUG_ILC_ICONSORTING
18 #define DEBUG_ILC_ICONSORTING_DUMP
19 #define DEBUG_ILC_ICONPOSITIONING
20 #define DEBUG_ILC_LASSO
21 #define DEBUG_ILC_MEMALLOC
23 //#define CREATE_FULL_DRAGIMAGE
25 #if !defined(__AROS__)
26 #define DRAWICONSTATE DrawIconState
27 #else
28 #define DRAWICONSTATE DrawIconStateA
29 #endif
31 #include <string.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <math.h>
37 #include <dos/dos.h>
38 #include <dos/datetime.h>
39 #include <dos/filehandler.h>
41 #include <exec/memory.h>
42 #include <graphics/gfx.h>
43 #include <graphics/view.h>
44 #include <graphics/rpattr.h>
45 #include <workbench/icon.h>
46 #include <workbench/workbench.h>
48 #ifdef __AROS__
49 #include <devices/rawkeycodes.h>
50 #include <clib/alib_protos.h>
51 #else
52 #include <devices_AROS/rawkeycodes.h>
53 #endif
56 #include <proto/exec.h>
57 #include <proto/graphics.h>
58 #include <proto/utility.h>
59 #include <proto/dos.h>
60 #include <proto/icon.h>
61 #include <proto/layers.h>
62 #include <proto/dos.h>
63 #include <proto/iffparse.h>
65 #ifdef __AROS__
66 #include <prefs/prefhdr.h>
67 #include <prefs/wanderer.h>
68 #else
69 #include <prefs_AROS/prefhdr.h>
70 #include <prefs_AROS/wanderer.h>
71 #endif
73 #include <proto/cybergraphics.h>
75 #ifdef __AROS__
76 #include <cybergraphx/cybergraphics.h>
77 #else
78 #include <cybergraphx_AROS/cybergraphics.h>
79 #endif
81 #if defined(__AMIGA__) && !defined(__PPC__)
82 #define NO_INLINE_STDARG
83 #endif
84 #include <proto/intuition.h>
85 #include <proto/muimaster.h>
87 #include <libraries/mui.h>
88 //#include "muimaster_intern.h"
89 //#include "support.h"
90 //#include "imspec.h"
91 #include "iconlist_attributes.h"
92 #include "icon_attributes.h"
93 #include "iconlist.h"
94 #include "icondrawerlist_private.h"
96 #ifndef __AROS__
97 #define DEBUG 1
99 #ifdef DEBUG
100 #define D(x) if (DEBUG) x
101 #ifdef __amigaos4__
102 #define bug DebugPrintF
103 #else
104 #define bug kprintf
105 #endif
106 #else
107 #define D(...)
108 #endif
109 #endif
111 extern struct Library *MUIMasterBase;
114 ///IconDrawerList__ParseContents()
115 /**************************************************************************
116 Read icons in
117 **************************************************************************/
118 static int IconDrawerList__ParseContents(struct IClass *CLASS, Object *obj)
120 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
121 BPTR lock = BNULL, tmplock = BNULL;
122 char filename[256];
123 char namebuffer[512];
124 ULONG list_DisplayFlags = 0;
126 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
128 if (!data->drawer) return 1;
130 lock = Lock(data->drawer, SHARED_LOCK);
132 if (lock)
134 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
135 if (fib)
137 if (Examine(lock, fib))
139 GET(obj, MUIA_IconList_DisplayFlags, &list_DisplayFlags);
140 D(bug("[IconDrawerList] %s: DisplayFlags = 0x%p\n", __PRETTY_FUNCTION__, list_DisplayFlags));
142 while(ExNext(lock, fib))
144 int len = strlen(fib->fib_FileName);
145 struct IconEntry *this_Icon;
147 memset(namebuffer, 0, 512);
148 strcpy(filename, fib->fib_FileName);
150 D(bug("[IconDrawerList] %s: '%s', len = %d\n", __PRETTY_FUNCTION__, filename, len));
152 if (len >= 5)
154 if (!Stricmp(&filename[len-5],".info"))
156 /* Its a .info file .. skip "disk.info" and just ".info" files*/
157 if ((len == 5) || ((len == 9) && (!Strnicmp(filename, "Disk", 4))))
159 D(bug("[IconDrawerList] %s: Skiping file named disk.info or just .info ('%s')\n", __PRETTY_FUNCTION__, filename));
160 continue;
163 strcpy(namebuffer, data->drawer);
164 memset((filename + len - 5), 0, 1); //Remove the .info section
165 AddPart(namebuffer, filename, sizeof(namebuffer));
166 D(bug("[IconDrawerList] %s: Checking for .info files real file '%s'\n", __PRETTY_FUNCTION__, namebuffer));
168 if ((tmplock = Lock(namebuffer, SHARED_LOCK)))
170 /* We have a real file so skip it for now and let it be found seperately */
171 D(bug("[IconDrawerList] %s: File found .. skipping\n", __PRETTY_FUNCTION__));
172 UnLock(tmplock);
173 continue;
178 D(bug("[IconDrawerList] %s: Registering file '%s'\n", __PRETTY_FUNCTION__, filename));
179 strcpy(namebuffer, data->drawer);
180 AddPart(namebuffer, filename, sizeof(namebuffer));
182 this_Icon = NULL;
184 if ((this_Icon = (struct IconEntry *)DoMethod(obj, MUIM_IconList_CreateEntry, (IPTR)namebuffer, (IPTR)filename, (IPTR)fib, (IPTR)NULL, 0, (IPTR)NULL)))
186 D(bug("[IconDrawerList] %s: Icon entry allocated @ 0x%p\n", __PRETTY_FUNCTION__, this_Icon));
187 DoMethod(obj, MUIM_Family_AddTail, (struct Node*)&this_Icon->ie_IconNode);
189 sprintf(namebuffer + strlen(namebuffer), ".info");
190 if ((tmplock = Lock(namebuffer, SHARED_LOCK)))
192 D(bug("[IconDrawerList] %s: File has a .info file .. updating info\n", __PRETTY_FUNCTION__));
193 UnLock(tmplock);
194 if (!(this_Icon->ie_Flags & ICONENTRY_FLAG_HASICON))
195 this_Icon->ie_Flags |= ICONENTRY_FLAG_HASICON;
198 if (list_DisplayFlags & ICONLIST_DISP_SHOWINFO)
200 if ((this_Icon->ie_Flags & ICONENTRY_FLAG_HASICON) && !(this_Icon->ie_Flags & ICONENTRY_FLAG_VISIBLE))
201 this_Icon->ie_Flags |= ICONENTRY_FLAG_VISIBLE;
203 else if (!(this_Icon->ie_Flags & ICONENTRY_FLAG_VISIBLE))
205 this_Icon->ie_Flags |= ICONENTRY_FLAG_VISIBLE;
207 this_Icon->ie_IconNode.ln_Pri = 0;
209 if (fib->fib_DirEntryType == ST_FILE)
211 this_Icon->ie_IconListEntry.type = ST_FILE;
212 D(bug("[IconDrawerList] %s: ST_FILE Entry created\n", __PRETTY_FUNCTION__));
214 else if (fib->fib_DirEntryType == ST_USERDIR)
216 this_Icon->ie_IconListEntry.type = ST_USERDIR;
217 D(bug("[IconDrawerList] %s: ST_USERDIR Entry created\n", __PRETTY_FUNCTION__));
219 else
221 D(bug("[IconDrawerList] %s: Unknown Entry Type created\n", __PRETTY_FUNCTION__));
224 else
226 D(bug("[IconDrawerList] %s: Failed to Register file!!!\n", __PRETTY_FUNCTION__));
231 FreeDosObject(DOS_FIB, fib);
234 UnLock(lock);
237 return 1;
241 ///OM_NEW()
242 /**************************************************************************
243 OM_NEW
244 **************************************************************************/
245 IPTR IconDrawerList__OM_NEW(struct IClass *CLASS, Object *obj, struct opSet *message)
247 struct IconDrawerList_DATA *data = NULL;
248 struct TagItem *tag = NULL,
249 *tags = NULL;
251 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
253 obj = (Object *)DoSuperNewTags(CLASS, obj, NULL,
254 TAG_MORE, (IPTR) message->ops_AttrList);
256 if (!obj) return FALSE;
258 D(bug("[IconDrawerList] obj @ %p\n", obj));
260 SET(obj, MUIA_IconList_DisplayFlags, ICONLIST_DISP_MODEDEFAULT);
261 SET(obj, MUIA_IconList_SortFlags, MUIV_IconList_Sort_ByName);
263 data = INST_DATA(CLASS, obj);
265 /* parse initial taglist */
266 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
268 switch (tag->ti_Tag)
270 case MUIA_IconDrawerList_Drawer:
271 data->drawer = StrDup((char *)tag->ti_Data);
272 break;
276 return (IPTR)obj;
280 ///OM_DISPOSE()
281 /**************************************************************************
282 OM_DISPOSE
283 **************************************************************************/
284 IPTR IconDrawerList__OM_DISPOSE(struct IClass *CLASS, Object *obj, Msg message)
286 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
288 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
290 if (data->drawer)
292 D(bug("[IconDrawerList] %s: Freeing DIR name storage for '%s'\n", __PRETTY_FUNCTION__, data->drawer));
294 FreeVec(data->drawer);
297 return DoSuperMethodA(CLASS, obj, message);
301 ///OM_SET()
302 /**************************************************************************
303 OM_SET
304 **************************************************************************/
305 IPTR IconDrawerList__OM_SET(struct IClass *CLASS, Object *obj, struct opSet *message)
307 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
308 struct TagItem *tag = NULL,
309 *tags = NULL;
311 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
313 /* parse initial taglist */
314 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
316 switch (tag->ti_Tag)
318 case MUIA_IconDrawerList_Drawer:
319 if (data->drawer)
320 FreeVec(data->drawer);
322 data->drawer = StrDup((char*)tag->ti_Data);
323 DoMethod(obj, MUIM_IconList_Update);
324 DoMethod(obj, MUIM_IconList_Sort);
326 break;
330 return DoSuperMethodA(CLASS, obj, (Msg)message);
334 ///OM_GET()
335 /**************************************************************************
336 OM_GET
337 **************************************************************************/
338 IPTR IconDrawerList__OM_GET(struct IClass *CLASS, Object *obj, struct opGet *message)
340 /* small macro to simplify return value storage */
341 #define STORE *(message->opg_Storage)
342 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
344 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
346 switch (message->opg_AttrID)
348 case MUIA_IconDrawerList_Drawer: STORE = (IPTR)data->drawer; return 1;
349 /* TODO: Get the version/revision from our config.. */
350 case MUIA_Version: STORE = (IPTR)1; return 1;
351 case MUIA_Revision: STORE = (IPTR)3; return 1;
354 return DoSuperMethodA(CLASS, obj, (Msg) message);
355 #undef STORE
359 ///MUIM_IconList_Update()
360 /**************************************************************************
361 MUIM_IconList_Update
362 **************************************************************************/
363 IPTR IconDrawerList__MUIM_IconList_Update(struct IClass *CLASS, Object *obj, struct MUIP_IconList_Update *message)
365 //struct IconEntry *node;
367 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
369 DoMethod(obj, MUIM_IconList_Clear);
371 IconDrawerList__ParseContents(CLASS, obj);
373 DoSuperMethodA(CLASS, obj, (Msg) message);
375 return 1;
380 #if WANDERER_BUILTIN_ICONDRAWERLIST
381 BOOPSI_DISPATCHER(IPTR, IconDrawerList_Dispatcher, CLASS, obj, message)
383 #ifdef __AROS__
384 switch (message->MethodID)
385 #else
386 struct IClass *CLASS = cl;
387 Msg message = msg;
389 switch (msg->MethodID)
390 #endif
392 case OM_NEW: return IconDrawerList__OM_NEW(CLASS, obj, (struct opSet *)message);
393 case OM_DISPOSE: return IconDrawerList__OM_DISPOSE(CLASS, obj, message);
394 case OM_SET: return IconDrawerList__OM_SET(CLASS, obj, (struct opSet *)message);
395 case OM_GET: return IconDrawerList__OM_GET(CLASS, obj, (struct opGet *)message);
397 #ifdef __AROS__
398 case MUIM_IconList_Update: return IconDrawerList__MUIM_Update(CLASS, obj, (APTR)message);
399 #else
400 case MUIM_IconList_Update: return IconDrawerList__MUIM_IconList_Update(CLASS, obj, (APTR)message);
401 #endif
403 return DoSuperMethodA(CLASS, obj, message);
405 BOOPSI_DISPATCHER_END
407 #ifdef __AROS__
408 /* Class descriptor. */
409 const struct __MUIBuiltinClass _MUI_IconDrawerList_desc = {
410 MUIC_IconDrawerList,
411 MUIC_IconList,
412 sizeof(struct IconDrawerList_DATA),
413 (void*)IconDrawerList_Dispatcher
415 #endif
416 #endif
418 #ifndef __AROS__
419 struct MUI_CustomClass *initIconDrawerListClass(void)
421 return (struct MUI_CustomClass *) MUI_CreateCustomClass(NULL, NULL, IconList_Class, sizeof(struct IconDrawerList_DATA), ENTRY(IconDrawerList_Dispatcher));
424 #endif