define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / workbench / system / Wanderer / Classes / icondrawerlist.c
blob071990779cf4817a79da5cdd5f67f95e5971b667
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 = NULL, tmplock = NULL;
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)))
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 data = INST_DATA(CLASS, obj);
262 /* parse initial taglist */
263 for (tags = message->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
265 switch (tag->ti_Tag)
267 case MUIA_IconDrawerList_Drawer:
268 data->drawer = StrDup((char *)tag->ti_Data);
269 break;
273 return (IPTR)obj;
277 ///OM_DISPOSE()
278 /**************************************************************************
279 OM_DISPOSE
280 **************************************************************************/
281 IPTR IconDrawerList__OM_DISPOSE(struct IClass *CLASS, Object *obj, Msg message)
283 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
285 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
287 if (data->drawer)
289 D(bug("[IconDrawerList] %s: Freeing DIR name storage for '%s'\n", __PRETTY_FUNCTION__, data->drawer));
291 FreeVec(data->drawer);
294 return DoSuperMethodA(CLASS, obj, message);
298 ///OM_SET()
299 /**************************************************************************
300 OM_SET
301 **************************************************************************/
302 IPTR IconDrawerList__OM_SET(struct IClass *CLASS, Object *obj, struct opSet *message)
304 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
305 struct TagItem *tag = NULL,
306 *tags = NULL;
308 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
310 /* parse initial taglist */
311 for (tags = message->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
313 switch (tag->ti_Tag)
315 case MUIA_IconDrawerList_Drawer:
316 if (data->drawer)
317 FreeVec(data->drawer);
319 data->drawer = StrDup((char*)tag->ti_Data);
320 DoMethod(obj, MUIM_IconList_Update);
322 break;
326 return DoSuperMethodA(CLASS, obj, (Msg)message);
330 ///OM_GET()
331 /**************************************************************************
332 OM_GET
333 **************************************************************************/
334 IPTR IconDrawerList__OM_GET(struct IClass *CLASS, Object *obj, struct opGet *message)
336 /* small macro to simplify return value storage */
337 #define STORE *(message->opg_Storage)
338 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
340 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
342 switch (message->opg_AttrID)
344 case MUIA_IconDrawerList_Drawer: STORE = (IPTR)data->drawer; return 1;
345 #warning "TODO: Get the version/revision from our config.."
346 case MUIA_Version: STORE = (IPTR)1; return 1;
347 case MUIA_Revision: STORE = (IPTR)3; return 1;
350 return DoSuperMethodA(CLASS, obj, (Msg) message);
351 #undef STORE
355 ///MUIM_IconList_Update()
356 /**************************************************************************
357 MUIM_IconList_Update
358 **************************************************************************/
359 IPTR IconDrawerList__MUIM_IconList_Update(struct IClass *CLASS, Object *obj, struct MUIP_IconList_Update *message)
361 //struct IconEntry *node;
363 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
365 DoMethod(obj, MUIM_IconList_Clear);
367 IconDrawerList__ParseContents(CLASS, obj);
369 /*_Sort takes care of icon placement and redrawing for us*/
370 DoMethod(obj, MUIM_IconList_Sort);
372 DoSuperMethodA(CLASS, obj, (Msg) message);
374 return 1;
379 #if WANDERER_BUILTIN_ICONDRAWERLIST
380 BOOPSI_DISPATCHER(IPTR, IconDrawerList_Dispatcher, CLASS, obj, message)
382 #ifdef __AROS__
383 switch (message->MethodID)
384 #else
385 struct IClass *CLASS = cl;
386 Msg message = msg;
388 switch (msg->MethodID)
389 #endif
391 case OM_NEW: return IconDrawerList__OM_NEW(CLASS, obj, (struct opSet *)message);
392 case OM_DISPOSE: return IconDrawerList__OM_DISPOSE(CLASS, obj, message);
393 case OM_SET: return IconDrawerList__OM_SET(CLASS, obj, (struct opSet *)message);
394 case OM_GET: return IconDrawerList__OM_GET(CLASS, obj, (struct opGet *)message);
396 #ifdef __AROS__
397 case MUIM_IconList_Update: return IconDrawerList__MUIM_Update(CLASS, obj, (APTR)message);
398 #else
399 case MUIM_IconList_Update: return IconDrawerList__MUIM_IconList_Update(CLASS, obj, (APTR)message);
400 #endif
402 return DoSuperMethodA(CLASS, obj, message);
404 BOOPSI_DISPATCHER_END
406 #ifdef __AROS__
407 /* Class descriptor. */
408 const struct __MUIBuiltinClass _MUI_IconDrawerList_desc = {
409 MUIC_IconDrawerList,
410 MUIC_IconList,
411 sizeof(struct IconDrawerList_DATA),
412 (void*)IconDrawerList_Dispatcher
414 #endif
415 #endif
417 #ifndef __AROS__
418 struct MUI_CustomClass *initIconDrawerListClass(void)
420 return (struct MUI_CustomClass *) MUI_CreateCustomClass(NULL, NULL, IconList_Class, sizeof(struct IconDrawerList_DATA), ENTRY(IconDrawerList_Dispatcher));
423 #endif