Some compiler warnings removed.
[cake.git] / workbench / system / Wanderer / Classes / icondrawerlist.c
blob3f749c1c5ad1e79df81fd06e46ceb625510b6102
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));
188 sprintf(namebuffer + strlen(namebuffer), ".info");
189 if ((tmplock = Lock(namebuffer, SHARED_LOCK)))
191 D(bug("[IconDrawerList] %s: File has a .info file .. updating info\n", __PRETTY_FUNCTION__));
192 UnLock(tmplock);
193 if (!(this_Icon->ile_Flags & ICONENTRY_FLAG_HASICON))
194 this_Icon->ile_Flags |= ICONENTRY_FLAG_HASICON;
197 if (list_DisplayFlags & ICONLIST_DISP_SHOWINFO)
199 if ((this_Icon->ile_Flags & ICONENTRY_FLAG_HASICON) && !(this_Icon->ile_Flags & ICONENTRY_FLAG_VISIBLE))
200 this_Icon->ile_Flags |= ICONENTRY_FLAG_VISIBLE;
202 else if (!(this_Icon->ile_Flags & ICONENTRY_FLAG_VISIBLE))
204 this_Icon->ile_Flags |= ICONENTRY_FLAG_VISIBLE;
206 this_Icon->ile_IconNode.ln_Pri = 0;
208 if (fib->fib_DirEntryType == ST_FILE)
210 this_Icon->ile_IconListEntry.type = ST_FILE;
211 D(bug("[IconDrawerList] %s: ST_FILE Entry created\n", __PRETTY_FUNCTION__));
213 else if (fib->fib_DirEntryType == ST_USERDIR)
215 this_Icon->ile_IconListEntry.type = ST_USERDIR;
216 D(bug("[IconDrawerList] %s: ST_USERDIR Entry created\n", __PRETTY_FUNCTION__));
218 else
220 D(bug("[IconDrawerList] %s: Unknown Entry Type created\n", __PRETTY_FUNCTION__));
223 else
225 D(bug("[IconDrawerList] %s: Failed to Register file!!!\n", __PRETTY_FUNCTION__));
230 FreeDosObject(DOS_FIB, fib);
233 UnLock(lock);
236 return 1;
240 ///OM_NEW()
241 /**************************************************************************
242 OM_NEW
243 **************************************************************************/
244 IPTR IconDrawerList__OM_NEW(struct IClass *CLASS, Object *obj, struct opSet *message)
246 struct IconDrawerList_DATA *data = NULL;
247 struct TagItem *tag = NULL,
248 *tags = NULL;
250 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
252 obj = (Object *)DoSuperNewTags(CLASS, obj, NULL,
253 TAG_MORE, (IPTR) message->ops_AttrList);
255 if (!obj) return FALSE;
257 data = INST_DATA(CLASS, obj);
259 /* parse initial taglist */
260 for (tags = message->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
262 switch (tag->ti_Tag)
264 case MUIA_IconDrawerList_Drawer:
265 data->drawer = StrDup((char *)tag->ti_Data);
266 break;
269 D(bug("[IconDrawerList] obj = %ld\n", obj));
270 return (IPTR)obj;
274 ///OM_DISPOSE()
275 /**************************************************************************
276 OM_DISPOSE
277 **************************************************************************/
278 IPTR IconDrawerList__OM_DISPOSE(struct IClass *CLASS, Object *obj, Msg message)
280 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
282 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
284 if (data->drawer)
286 D(bug("[IconDrawerList] %s: Freeing DIR name storage for '%s'\n", __PRETTY_FUNCTION__, data->drawer));
288 FreeVec(data->drawer);
291 return DoSuperMethodA(CLASS, obj, message);
295 ///OM_SET()
296 /**************************************************************************
297 OM_SET
298 **************************************************************************/
299 IPTR IconDrawerList__OM_SET(struct IClass *CLASS, Object *obj, struct opSet *message)
301 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
302 struct TagItem *tag = NULL,
303 *tags = NULL;
305 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
307 /* parse initial taglist */
308 for (tags = message->ops_AttrList; (tag = NextTagItem((const struct TagItem **)&tags)); )
310 switch (tag->ti_Tag)
312 case MUIA_IconDrawerList_Drawer:
313 if (data->drawer) FreeVec(data->drawer);
315 data->drawer = StrDup((char*)tag->ti_Data);
316 DoMethod(obj, MUIM_IconList_Update);
318 break;
322 return DoSuperMethodA(CLASS, obj, (Msg)message);
326 ///OM_GET()
327 /**************************************************************************
328 OM_GET
329 **************************************************************************/
330 IPTR IconDrawerList__OM_GET(struct IClass *CLASS, Object *obj, struct opGet *message)
332 /* small macro to simplify return value storage */
333 #define STORE *(message->opg_Storage)
334 struct IconDrawerList_DATA *data = INST_DATA(CLASS, obj);
336 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
338 switch (message->opg_AttrID)
340 case MUIA_IconDrawerList_Drawer: STORE = (IPTR)data->drawer; return 1;
343 if (DoSuperMethodA(CLASS, obj, (Msg) message)) return 1;
344 return 0;
345 #undef STORE
349 ///MUIM_IconList_Update()
350 /**************************************************************************
351 MUIM_IconList_Update
352 **************************************************************************/
353 IPTR IconDrawerList__MUIM_IconList_Update(struct IClass *CLASS, Object *obj, struct MUIP_IconList_Update *message)
355 //struct IconEntry *node;
357 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__));
359 DoSuperMethodA(CLASS, obj, (Msg) message);
361 DoMethod(obj, MUIM_IconList_Clear);
363 /* If not in setup do nothing */
364 #warning "TODO: Handle MADF_SETUP"
365 // if (!(_flags(obj) & MADF_SETUP)) return 1;
367 IconDrawerList__ParseContents(CLASS, obj);
369 /*_Sort takes care of icon placement and redrawing for us*/
370 DoMethod(obj, MUIM_IconList_Sort);
372 return 1;
377 #if WANDERER_BUILTIN_ICONDRAWERLIST
378 BOOPSI_DISPATCHER(IPTR, IconDrawerList_Dispatcher, CLASS, obj, message)
380 #ifdef __AROS__
381 switch (message->MethodID)
382 #else
383 struct IClass *CLASS = cl;
384 Msg message = msg;
386 switch (msg->MethodID)
387 #endif
389 case OM_NEW: return IconDrawerList__OM_NEW(CLASS, obj, (struct opSet *)message);
390 case OM_DISPOSE: return IconDrawerList__OM_DISPOSE(CLASS, obj, message);
391 case OM_SET: return IconDrawerList__OM_SET(CLASS, obj, (struct opSet *)message);
392 case OM_GET: return IconDrawerList__OM_GET(CLASS, obj, (struct opGet *)message);
394 #ifdef __AROS__
395 case MUIM_IconList_Update: return IconDrawerList__MUIM_Update(CLASS, obj, (APTR)message);
396 #else
397 case MUIM_IconList_Update: return IconDrawerList__MUIM_IconList_Update(CLASS, obj, (APTR)message);
398 #endif
400 return DoSuperMethodA(CLASS, obj, message);
402 BOOPSI_DISPATCHER_END
404 #ifdef __AROS__
405 /* Class descriptor. */
406 const struct __MUIBuiltinClass _MUI_IconDrawerList_desc = {
407 MUIC_IconDrawerList,
408 MUIC_IconList,
409 sizeof(struct IconDrawerList_DATA),
410 (void*)IconDrawerList_Dispatcher
412 #endif
413 #endif
415 #ifndef __AROS__
416 struct MUI_CustomClass *initIconDrawerListClass(void)
418 return (struct MUI_CustomClass *) MUI_CreateCustomClass(NULL, NULL, IconList_Class, sizeof(struct IconDrawerList_DATA), ENTRY(IconDrawerList_Dispatcher));
421 #endif