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
= BNULL
, tmplock
= BNULL
;
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, (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__
));
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__
));
221 D(bug("[IconDrawerList] %s: Unknown Entry Type created\n", __PRETTY_FUNCTION__
));
226 D(bug("[IconDrawerList] %s: Failed to Register file!!!\n", __PRETTY_FUNCTION__
));
231 FreeDosObject(DOS_FIB
, fib
);
242 /**************************************************************************
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
,
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
)); )
270 case MUIA_IconDrawerList_Drawer
:
271 data
->drawer
= StrDup((char *)tag
->ti_Data
);
281 /**************************************************************************
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__
));
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
);
302 /**************************************************************************
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
,
311 D(bug("[IconDrawerList]: %s()\n", __PRETTY_FUNCTION__
));
313 /* parse initial taglist */
314 for (tags
= message
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
318 case MUIA_IconDrawerList_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
);
330 return DoSuperMethodA(CLASS
, obj
, (Msg
)message
);
335 /**************************************************************************
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
);
359 ///MUIM_IconList_Update()
360 /**************************************************************************
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
);
380 #if WANDERER_BUILTIN_ICONDRAWERLIST
381 BOOPSI_DISPATCHER(IPTR
, IconDrawerList_Dispatcher
, CLASS
, obj
, message
)
384 switch (message
->MethodID
)
386 struct IClass
*CLASS
= cl
;
389 switch (msg
->MethodID
)
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
);
398 case MUIM_IconList_Update
: return IconDrawerList__MUIM_Update(CLASS
, obj
, (APTR
)message
);
400 case MUIM_IconList_Update
: return IconDrawerList__MUIM_IconList_Update(CLASS
, obj
, (APTR
)message
);
403 return DoSuperMethodA(CLASS
, obj
, message
);
405 BOOPSI_DISPATCHER_END
408 /* Class descriptor. */
409 const struct __MUIBuiltinClass _MUI_IconDrawerList_desc
= {
412 sizeof(struct IconDrawerList_DATA
),
413 (void*)IconDrawerList_Dispatcher
419 struct MUI_CustomClass
*initIconDrawerListClass(void)
421 return (struct MUI_CustomClass
*) MUI_CreateCustomClass(NULL
, NULL
, IconList_Class
, sizeof(struct IconDrawerList_DATA
), ENTRY(IconDrawerList_Dispatcher
));