2 Copyright 2002-2009, The AROS Development Team. All rights reserved.
7 #include "../portable_macros.h"
8 #define WANDERER_BUILTIN_ICONDRAWERLIST 1
11 #include <aros/debug.h>
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
28 #define DRAWICONSTATE DrawIconStateA
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>
49 #include <devices/rawkeycodes.h>
50 #include <clib/alib_protos.h>
52 #include <devices_AROS/rawkeycodes.h>
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>
66 #include <prefs/prefhdr.h>
67 #include <prefs/wanderer.h>
69 #include <prefs_AROS/prefhdr.h>
70 #include <prefs_AROS/wanderer.h>
73 #include <proto/cybergraphics.h>
76 #include <cybergraphx/cybergraphics.h>
78 #include <cybergraphx_AROS/cybergraphics.h>
81 #if defined(__AMIGA__) && !defined(__PPC__)
82 #define NO_INLINE_STDARG
84 #include <proto/intuition.h>
85 #include <proto/muimaster.h>
87 #include <libraries/mui.h>
88 //#include "muimaster_intern.h"
89 //#include "support.h"
91 #include "iconlist_attributes.h"
92 #include "icon_attributes.h"
94 #include "icondrawerlist_private.h"
100 #define D(x) if (DEBUG) x
102 #define bug DebugPrintF
111 extern struct Library
*MUIMasterBase
;
114 ///IconDrawerList__ParseContents()
115 /**************************************************************************
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
;
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
);
134 struct FileInfoBlock
*fib
= AllocDosObject(DOS_FIB
, NULL
);
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
));
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
));
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__
));
178 D(bug("[IconDrawerList] %s: Registering file '%s'\n", __PRETTY_FUNCTION__
, filename
));
179 strcpy(namebuffer
, data
->drawer
);
180 AddPart(namebuffer
, filename
, sizeof(namebuffer
));
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__
));
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__
));
220 D(bug("[IconDrawerList] %s: Unknown Entry Type created\n", __PRETTY_FUNCTION__
));
225 D(bug("[IconDrawerList] %s: Failed to Register file!!!\n", __PRETTY_FUNCTION__
));
230 FreeDosObject(DOS_FIB
, fib
);
241 /**************************************************************************
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
,
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
)); )
264 case MUIA_IconDrawerList_Drawer
:
265 data
->drawer
= StrDup((char *)tag
->ti_Data
);
269 D(bug("[IconDrawerList] obj = %ld\n", obj
));
275 /**************************************************************************
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__
));
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
);
296 /**************************************************************************
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
,
305 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__
));
307 /* parse initial taglist */
308 for (tags
= message
->ops_AttrList
; (tag
= NextTagItem((const struct TagItem
**)&tags
)); )
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
);
322 return DoSuperMethodA(CLASS
, obj
, (Msg
)message
);
327 /**************************************************************************
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;
349 ///MUIM_IconList_Update()
350 /**************************************************************************
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
);
377 #if WANDERER_BUILTIN_ICONDRAWERLIST
378 BOOPSI_DISPATCHER(IPTR
, IconDrawerList_Dispatcher
, CLASS
, obj
, message
)
381 switch (message
->MethodID
)
383 struct IClass
*CLASS
= cl
;
386 switch (msg
->MethodID
)
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
);
395 case MUIM_IconList_Update
: return IconDrawerList__MUIM_Update(CLASS
, obj
, (APTR
)message
);
397 case MUIM_IconList_Update
: return IconDrawerList__MUIM_IconList_Update(CLASS
, obj
, (APTR
)message
);
400 return DoSuperMethodA(CLASS
, obj
, message
);
402 BOOPSI_DISPATCHER_END
405 /* Class descriptor. */
406 const struct __MUIBuiltinClass _MUI_IconDrawerList_desc
= {
409 sizeof(struct IconDrawerList_DATA
),
410 (void*)IconDrawerList_Dispatcher
416 struct MUI_CustomClass
*initIconDrawerListClass(void)
418 return (struct MUI_CustomClass
*) MUI_CreateCustomClass(NULL
, NULL
, IconList_Class
, sizeof(struct IconDrawerList_DATA
), ENTRY(IconDrawerList_Dispatcher
));