forwarding build fix when MUIA_Scrollgroup_AutoBars is defined (NicJA).
[AROS-Contrib.git] / scalos / main / Backdrop.c
blobccfed00da84a462ca510c30c7f6f6993fe66ef31
1 // Backdrop.c
2 // $Date$
3 // $Revision$
4 // 04 Sep 2004 15:33:26
7 #include <exec/types.h>
8 #include <graphics/gels.h>
9 #include <graphics/rastport.h>
10 #include <intuition/classes.h>
11 #include <intuition/classusr.h>
12 #include <utility/hooks.h>
13 #include <intuition/gadgetclass.h>
14 #include <workbench/workbench.h>
15 #include <workbench/startup.h>
16 #include <datatypes/pictureclass.h>
17 #include <dos/dos.h>
18 #include <dos/dostags.h>
19 #include <dos/exall.h>
21 #define __USE_SYSBASE
23 #include <proto/dos.h>
24 #include <proto/exec.h>
25 #include <proto/layers.h>
26 #include <proto/graphics.h>
27 #include <proto/intuition.h>
28 #include <proto/iconobject.h>
29 #include <proto/utility.h>
30 #include <proto/gadtools.h>
31 #include <proto/datatypes.h>
32 #include "debug.h"
33 #include <proto/scalos.h>
35 #include <clib/alib_protos.h>
37 #include <defs.h>
38 #include <datatypes/iconobject.h>
39 #include <scalos/scalos.h>
40 #include <string.h>
41 #include <stdio.h>
42 #include <stdarg.h>
43 #include <limits.h>
45 #include "scalos_structures.h"
46 #include "functions.h"
47 #include "Variables.h"
49 //----------------------------------------------------------------------------
51 // local Data definitions
53 //----------------------------------------------------------------------------
55 // local functions
57 static LONG BackdropWriteList(struct BackDropList *bdl);
58 static BOOL BackdropInternalAddLine(struct BackDropList *bdl, CONST_STRPTR NewLine, LONG PosX, LONG PosY);
59 static struct ChainedLine *BackdropAllocChainedLine(CONST_STRPTR TextLine);
60 static void BackdropFreeChainedLine(struct ChainedLine *cnl);
61 static void BackdropRemoveObsoleteEntriesFromBackdropFile(struct BackDropList *bdl);
62 static void BackdropRemoveDuplicateEntriesFromBackdropFile(struct BackDropList *bdl);
63 static void BackdropRedrawMainIconObject(struct internalScaWindowTask *iwtMain, Object *IconObj);
65 //----------------------------------------------------------------------------
67 // local Data
69 //----------------------------------------------------------------------------
71 void BackDropInitList(struct BackDropList *bdl)
73 NewList(&bdl->bdl_LinesList);
74 bdl->bdl_Loaded = FALSE;
75 bdl->bdl_Changed = FALSE;
76 bdl->bdl_Filtered = FALSE;
77 bdl->bdl_NotPresent = FALSE;
78 bdl->bdl_Initialized = TRUE;
82 LONG BackdropLoadList(struct BackDropList *bdl)
84 const size_t LineSize = 300;
85 LONG Result = RETURN_OK;
86 char *Line;
87 BPTR fh;
89 BackDropInitList(bdl);
91 ShortcutAddLines(bdl); // add left-out icons from Ambient shortcuts
93 fh = Open(".backdrop", MODE_OLDFILE);
94 d1(kprintf("%s/%s/%ld: fh=%08lx\n", __FILE__, __FUNC__, __LINE__, fh));
95 if ((BPTR)NULL == fh)
97 Result = IoErr();
98 if (ERROR_OBJECT_NOT_FOUND == Result)
100 bdl->bdl_NotPresent = TRUE;
101 Result = RETURN_OK;
104 return Result;
107 Line = ScalosAlloc(LineSize);
108 if (NULL == Line)
110 Close(fh);
111 return ERROR_NO_FREE_STORE;
114 bdl->bdl_Loaded = TRUE;
116 while (FGets(fh, Line, LineSize))
118 if ('\n' == Line[strlen(Line) - 1]) // strip trailing LF
119 Line[strlen(Line) - 1] = '\0';
121 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, Line));
123 if (strlen(Line) >= 1)
125 BackdropAddLine(bdl, Line, NO_ICON_POSITION, NO_ICON_POSITION);
129 ScalosFree(Line);
131 if (!Close(fh))
132 return IoErr();
134 return Result;
138 void BackdropFreeList(struct BackDropList *bdl)
140 struct ChainedLine *cnl;
142 if (! bdl->bdl_Initialized)
143 return;
145 while ((cnl = (struct ChainedLine *) RemHead(&bdl->bdl_LinesList)))
147 BackdropFreeChainedLine(cnl);
152 void BackdropFilterList(struct BackDropList *bdl, BPTR dirLock)
154 struct ChainedLine *cnl;
155 BPTR oldDir;
156 STRPTR Path;
158 d1(kprintf("%s/%s/%ld: START bdl=%08lx\n", __FILE__, __FUNC__, __LINE__, bdl));
159 debugLock_d1(dirLock);
161 if (BNULL == dirLock)
162 return;
164 if (bdl->bdl_Filtered)
165 return;
167 Path = AllocPathBuffer();
168 if (NULL == Path)
169 return;
171 oldDir = CurrentDir(dirLock);
173 if (!bdl->bdl_Loaded && !bdl->bdl_NotPresent)
175 BPTR RootDirLock;
177 do {
178 RootDirLock = Lock(":", ACCESS_READ);
179 debugLock_d1(RootDirLock);
180 if (BNULL == RootDirLock)
181 break;
183 // change to root directory of icon drawer
184 CurrentDir(RootDirLock);
186 if (RETURN_OK != BackdropLoadList(bdl))
187 break;
188 } while (0);
190 CurrentDir(dirLock);
192 if (RootDirLock)
193 UnLock(RootDirLock);
196 bdl->bdl_Filtered = TRUE;
198 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
199 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail; )
201 BPTR tmpLock;
202 STRPTR lp;
203 struct ChainedLine *cnlNext = (struct ChainedLine *) cnl->cnl_Node.ln_Succ;;
205 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
207 stccpy(Path, cnl->cnl_Line, Max_PathLen);
209 // remove file part
210 lp = PathPart(Path);
211 if (lp)
212 *lp = '\0';
214 tmpLock = Lock(Path, ACCESS_READ);
215 debugLock_d1(tmpLock);
216 if (tmpLock)
218 if (LOCK_SAME != ScaSameLock(tmpLock, dirLock))
220 // delete entry from .backdrop
221 d1(kprintf("%s/%s/%ld: Filter Line <%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
223 Remove(&cnl->cnl_Node);
225 BackdropFreeChainedLine(cnl);
227 UnLock(tmpLock);
230 cnl = cnlNext;
233 FreePathBuffer(Path);
234 CurrentDir(oldDir);
236 d1(kprintf("%s/%s/%ld: END bdl=%08lx\n", __FILE__, __FUNC__, __LINE__, bdl));
240 static LONG BackdropWriteList(struct BackDropList *bdl)
242 struct ChainedLine *cnl;
243 LONG Result = RETURN_OK;
244 BPTR fh;
246 d1(kprintf("%s/%s/%ld: bdl=%08lx\n", __FILE__, __FUNC__, __LINE__, bdl));
248 // remove obsolete entries which refer to non-existing icons
249 BackdropRemoveObsoleteEntriesFromBackdropFile(bdl);
251 BackdropRemoveDuplicateEntriesFromBackdropFile(bdl);
253 if (!bdl->bdl_Changed)
254 return RETURN_OK; // No changes
256 fh = Open(".backdrop", MODE_NEWFILE);
257 if ((BPTR)NULL == fh)
258 return IoErr();
260 while ((cnl = (struct ChainedLine *) RemHead(&bdl->bdl_LinesList)) && RETURN_OK == Result)
262 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
264 if (-1 == FPrintf(fh, "%s\n", (IPTR) cnl->cnl_Line))
265 Result = IoErr();
268 Close(fh);
270 bdl->bdl_Changed = FALSE;
272 return Result;
276 BOOL BackdropAddLine(struct BackDropList *bdl, CONST_STRPTR NewLine, LONG PosX, LONG PosY)
278 struct ChainedLine *cnl;
280 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
281 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail;
282 cnl = (struct ChainedLine *) cnl->cnl_Node.ln_Succ )
284 if (0 == Stricmp(NewLine, cnl->cnl_Line))
286 // Duplicate line, ignore it silently
287 return TRUE;
291 return BackdropInternalAddLine(bdl, NewLine, PosX, PosY);
295 static BOOL BackdropInternalAddLine(struct BackDropList *bdl, CONST_STRPTR NewLine, LONG PosX, LONG PosY)
297 BOOL Success = FALSE;
298 struct ChainedLine *cnl;
300 cnl = BackdropAllocChainedLine(NewLine);
301 if (cnl)
303 AddTail(&bdl->bdl_LinesList, (struct Node *) &cnl->cnl_Node);
304 bdl->bdl_Changed = TRUE;
305 cnl->cnl_PosX = PosX;
306 cnl->cnl_PosY = PosY;
307 Success = TRUE;
310 return Success;
314 BOOL BackdropRemoveLine(struct BackDropList *bdl, BPTR iconLock)
316 struct ChainedLine *cnl;
317 BOOL Found = FALSE;
318 STRPTR Path;
320 d1(kprintf("%s/%s/%ld: bsl=%08lx\n", __FILE__, __FUNC__, __LINE__, bdl));
321 debugLock_d1(iconLock);
323 Path = AllocPathBuffer();
324 if (NULL == Path)
325 return FALSE;
327 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
328 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail; )
330 BPTR tmpLock;
331 struct ChainedLine *cnlNext = (struct ChainedLine *) cnl->cnl_Node.ln_Succ;
333 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
335 stccpy(Path, cnl->cnl_Line, Max_PathLen);
336 SafeStrCat(Path, ".info", Max_PathLen);
338 tmpLock = Lock(Path, ACCESS_READ);
339 if (tmpLock)
341 if (LOCK_SAME == ScaSameLock(tmpLock, iconLock))
343 // delete entry from .backdrop
344 d1(kprintf("%s/%s/%ld: Delete Line <%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
346 Found = bdl->bdl_Changed = TRUE;
348 Remove(&cnl->cnl_Node);
350 BackdropFreeChainedLine(cnl);
352 UnLock(tmpLock);
355 cnl = cnlNext;
358 FreePathBuffer(Path);
360 return Found;
364 static struct ChainedLine *BackdropAllocChainedLine(CONST_STRPTR TextLine)
366 struct ChainedLine *cnl = ScalosAlloc(sizeof(struct ChainedLine));
368 if (NULL == cnl)
369 return NULL;
371 cnl->cnl_PosX = cnl->cnl_PosY = NO_ICON_POSITION;
372 cnl->cnl_Line = AllocCopyString(TextLine);
374 return cnl;
378 static void BackdropFreeChainedLine(struct ChainedLine *cnl)
380 if (cnl->cnl_Line)
381 FreeCopyString(cnl->cnl_Line); // allocated by AllocCopyString()
383 ScalosFree(cnl);
387 // rewrite ".backdrop" file
388 // <in> is only used to access the volume's root directory
389 BOOL RewriteBackdrop(struct ScaIconNode *in)
391 BOOL Success = FALSE;
392 BPTR rootDirLock;
393 BPTR oldDir = CurrentDir(in->in_Lock);
395 d1(kprintf("%s/%s/%ld: in=<%s>\n", __FILE__, __FUNC__, __LINE__, GetIconName(in)));
397 rootDirLock = Lock(":", ACCESS_READ);
398 debugLock_d1(rootDirLock);
399 if (rootDirLock)
401 struct BackDropList bdl;
403 CurrentDir(rootDirLock);
405 d1(kprintf("%s/%s/%ld: rootDirLock OK\n", __FILE__, __FUNC__, __LINE__));
407 if (RETURN_OK == BackdropLoadList(&bdl))
409 d1(kprintf("%s/%s/%ld: LoadBackdropFile OK - GO BackdropWriteList(&bdl)\n", __FILE__, __FUNC__, __LINE__));
411 // Write .backdrop if it has any changes
412 BackdropWriteList(&bdl);
414 Success = TRUE;
417 BackdropFreeList(&bdl);
419 UnLock(rootDirLock);
422 CurrentDir(oldDir);
424 return Success;
428 // adjust ".backdrop" for changed name of object <oLock>
429 // <oLock> is Lock to object.
430 // <in> is the old backdrop icon
431 ULONG AdjustBackdropRenamed(BPTR oLock, struct ScaIconNode *in)
433 CONST_STRPTR OldPathStart;
434 STRPTR NewPathStart;
435 STRPTR OldPath = NULL;
436 STRPTR NewPath;
437 ULONG Result;
438 BPTR oldDir = NOT_A_LOCK;
439 BPTR NewParentDir = (BPTR)NULL, rootLock = (BPTR)NULL;
440 struct BackDropList bdl;
441 struct ChainedLine *cnl;
442 BOOL WasChanged = FALSE;
444 d1(kprintf("%s/%s/%ld: oLock=%08lx OldPath=<%s>\n", __FILE__, __FUNC__, __LINE__, oLock, OldPath));
446 BackDropInitList(&bdl);
448 do {
449 NewPath = AllocPathBuffer();
450 if (NULL == NewPath)
452 Result = ERROR_NO_FREE_STORE;
453 break;
456 OldPath = AllocPathBuffer();
457 if (NULL == OldPath)
459 Result = ERROR_NO_FREE_STORE;
460 break;
463 if (!NameFromLock(in->in_Lock, OldPath, Max_PathLen-1))
465 Result = IoErr();
466 break;
469 if (!AddPart(OldPath, in->in_Name, Max_PathLen-1))
471 Result = IoErr();
472 break;
475 NewParentDir = ParentDir(oLock);
476 if ((BPTR)NULL == NewParentDir)
478 Result = IoErr();
479 break;
482 if (!NameFromLock(oLock, NewPath, Max_PathLen-1))
484 Result = IoErr();
485 break;
488 OldPathStart = strchr(OldPath, ':');
489 if (NULL == OldPathStart)
490 OldPathStart = OldPath;
492 NewPathStart = strchr(NewPath, ':');
493 if (NULL == NewPathStart)
494 NewPathStart = NewPath;
496 StripIconExtension(NewPath);
498 d1(kprintf("%s/%s/%ld: OldPath=<%s> NewPath=<%s>\n", __FILE__, __FUNC__, __LINE__, OldPath, NewPath));
499 d1(kprintf("%s/%s/%ld: OldPathStart=<%s> NewPathStart=<%s>\n", __FILE__, __FUNC__, __LINE__, OldPathStart, NewPathStart));
501 oldDir = CurrentDir(NewParentDir);
503 rootLock = Lock(":", ACCESS_READ);
505 CurrentDir(oldDir);
506 oldDir = NOT_A_LOCK;
508 if ((BPTR)NULL == rootLock)
510 Result = IoErr();
511 break;
514 oldDir = CurrentDir(rootLock);
516 Result = BackdropLoadList(&bdl);
517 if (RETURN_OK != Result)
518 break;
520 for (cnl = (struct ChainedLine *) bdl.bdl_LinesList.lh_Head;
521 RETURN_OK == Result && cnl != (struct ChainedLine *) &bdl.bdl_LinesList.lh_Tail;
522 cnl = (struct ChainedLine *) cnl->cnl_Node.ln_Succ)
524 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
526 if (0 == Stricmp((STRPTR) OldPathStart, cnl->cnl_Line))
528 // changed entry found
529 FreeCopyString(cnl->cnl_Line);
530 cnl->cnl_Line = AllocCopyString(NewPathStart);
531 bdl.bdl_Changed = WasChanged = TRUE;
535 BackdropWriteList(&bdl);
536 } while (0);
538 BackdropFreeList(&bdl);
540 if (WasChanged)
542 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
543 struct ExtGadget *gg = (struct ExtGadget *) in->in_Icon;
544 struct ScaUpdateIcon_IW siw;
545 struct ScaWindowStruct *sw;
546 WORD x, y;
548 siw.ui_iw_Lock = NewParentDir;
549 siw.ui_iw_Name = FilePart(NewPath);
550 //siw.ui_IconType = ICONTYPE_NONE;
552 d1(KPrintF("%s/%s/%ld: Lock=%08lx Name=<%s>\n", __FILE__, __FUNC__, __LINE__, siw.ui_iw_Lock, siw.ui_iw_Name));
554 x = gg->LeftEdge;
555 y = gg->TopEdge;
557 DoMethod(iwtMain->iwt_WindowTask.mt_MainObject, SCCM_DeviceWin_RemIcon, in);
559 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
561 AddBackdropIcon(siw.ui_iw_Lock, siw.ui_iw_Name, x, y);
563 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
565 // remove icon from owning drawer window
566 // search owning drawer window by Lock
567 SCA_LockWindowList(SCA_LockWindowList_Shared);
569 for (sw=winlist.wl_WindowStruct; sw; sw = (struct ScaWindowStruct *) sw->ws_Node.mln_Succ)
571 if (sw->ws_Lock &&
572 LOCK_SAME == ScaSameLock(sw->ws_Lock, siw.ui_iw_Lock))
574 // owning drawer window found
575 struct internalScaWindowTask *iwt = (struct internalScaWindowTask *) sw->ws_WindowTask;
577 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
579 DoMethod(iwt->iwt_WindowTask.mt_MainObject,
580 SCCM_IconWin_RemIcon,
581 siw.ui_iw_Lock,
582 siw.ui_iw_Name);
584 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
587 SCA_UnLockWindowList();
590 if (OldPath)
591 FreePathBuffer(OldPath);
592 if (NewPath)
593 FreePathBuffer(NewPath);
594 if (IS_VALID_LOCK(oldDir))
595 CurrentDir(oldDir);
596 if (NewParentDir)
597 UnLock(NewParentDir);
598 if (rootLock)
599 UnLock(rootLock);
601 return Result;
605 struct ScaIconNode *AddBackdropIcon(BPTR iconDirLock, CONST_STRPTR iconName, WORD PosX, WORD PosY)
607 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
608 struct ScaIconNode *inMain;
609 struct DevProc *devproc;
610 BOOL IconAlreadyPresent = FALSE;
612 d1(KPrintF("%s/%s/%ld: START iconName=<%s> x=%ld y=%ld\n", __FILE__, __FUNC__, __LINE__, iconName, PosX, PosY));
613 debugLock_d1(iconDirLock);
616 ScalosLockIconListExclusive(iwtMain);
618 for (inMain = iwtMain->iwt_WindowTask.wt_IconList; inMain; inMain=(struct ScaIconNode *) inMain->in_Node.mln_Succ)
620 d1(KPrintF("%s/%s/%ld: in_Name=%08lx\n", __FILE__, __FUNC__, __LINE__, inMain->in_Name));
622 if (inMain->in_Lock && (LOCK_SAME == SameLock(inMain->in_Lock, iconDirLock))
623 && inMain->in_Name && 0 == Stricmp((STRPTR) iconName, inMain->in_Name))
625 IconAlreadyPresent = TRUE;
626 d1(KPrintF("%s/%s/%ld: iconName=<%> inMain->in_Name=<%s> IconAlreadyPresent=[%ld]\n", __FILE__, __FUNC__, __LINE__, \
627 iconName, inMain->in_Name, IconAlreadyPresent));
631 ScalosUnLockIconList(iwtMain);
633 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
635 // Abort here if we already have a backdrop icon with same lock and name
636 if (IconAlreadyPresent)
638 d1(KPrintF("%s/%s/%ld: icon already present: iconName=<%s>\n", __FILE__, __FUNC__, __LINE__, iconName));
639 return NULL;
642 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
644 // !! PosX and PosY have to be concatenated from 2 WORD into 1 LONG parameter !!
646 // add icon to desktop window
647 inMain = (struct ScaIconNode *) DoMethod(iwtMain->iwt_WindowTask.mt_MainObject,
648 SCCM_IconWin_AddIcon,
649 SCCM_ADDICON_MAKEXY(PosX, PosY),
650 iconDirLock,
651 iconName);
653 d1(kprintf("%s/%s/%ld: iconName=<%> PosX=%ld PosY=%ld pos=%08lx\n", __FILE__, __FUNC__, __LINE__, iconName, PosX, PosY, (((UWORD) PosX) << 16) | ((UWORD) PosY)));
655 devproc = GetDeviceProc(":", NULL);
656 if (NULL == devproc)
658 d1(KPrintF("%s/%s/%ld: GetDeviceProc failed iconName=<%s>\n", __FILE__, __FUNC__, __LINE__, iconName));
659 return NULL;
662 ScalosLockIconListExclusive(iwtMain);
664 d1(kprintf("%s/%s/%ld: inMain=%08lx\n", __FILE__, __FUNC__, __LINE__, inMain));
665 d1(kprintf("%s/%s/%ld: devproc=%08lx Port=%08lx\n", __FILE__, __FUNC__, __LINE__, devproc, devproc->dvp_Port));
666 debugLock_d1(iconDirLock);
668 if (inMain)
670 BOOL VolumeIsWritable;
672 d1(kprintf("%s/%s/%ld: inMain=%08lx in_Icon=%08lx in_Lock=%08lx\n", \
673 __FILE__, __FUNC__, __LINE__, inMain, inMain->in_Icon, inMain->in_Lock));
675 VolumeIsWritable = ClassIsDiskWritable(iconDirLock);
677 d1(kprintf("%s/%s/%ld: VolumeIsWritable=%ld\n", __FILE__, __FUNC__, __LINE__, VolumeIsWritable));
678 #if 0
679 // Do not set ICONOVERLAYF_LeftOut here, icon was perhaps just dropped!
680 // Check if is a real permanent backdrop icon before.
681 SetAttrs(inMain->in_Icon,
682 IDTA_OverlayType, ICONOVERLAYF_LeftOut,
683 TAG_END);
684 #endif
685 if (VolumeIsWritable)
687 struct BackDropList bdl;
689 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
691 // Check if is a real permanent backdrop icon before to set ICONOVERLAYF_LeftOut Overlay type flag.
692 BackDropInitList(&bdl);
695 if (IsPermanentBackDropIcon(iwtMain, &bdl, iconDirLock, GetIconName(inMain)))
697 d1(KPrintF("%s/%s/%ld: PermanentBackDropIcon=<%s>\n", __FILE__, __FUNC__, __LINE__, GetIconName(inMain)));
699 SetAttrs(inMain->in_Icon,
700 IDTA_OverlayType, ICONOVERLAYF_LeftOut,
701 TAG_END);
703 inMain->in_SupportFlags |= INF_SupportsPutAway;
704 inMain->in_SupportFlags &= ~INF_SupportsLeaveOut;
706 d1(KPrintF("%s/%s/%ld: Permanent BackDrop Icon=<%s> ICONOVERLAYF_LeftOut is SET - Icon Supportflags UPDATED!\n", \
707 __FILE__, __FUNC__, __LINE__, GetIconName(inMain)));
709 BackdropRedrawMainIconObject(iwtMain, inMain->in_Icon);
711 else
713 d1(kprintf("%s/%s/%ld: Not Permanent BackDrop Icon=<%s> ICONOVERLAYF_LeftOut NOT SET - Icon Supportflags UPDATED!\n",\
714 __FILE__, __FUNC__, __LINE__, GetIconName(inMain)));
716 inMain->in_SupportFlags &= ~INF_SupportsPutAway;
717 inMain->in_SupportFlags |= INF_SupportsLeaveOut;
720 BackdropFreeList(&bdl);
722 else
724 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
725 inMain->in_SupportFlags &= ~INF_SupportsPutAway;
726 inMain->in_SupportFlags &= ~INF_SupportsLeaveOut;
729 CreateSbiForIcon(inMain);
732 ScalosUnLockIconList(iwtMain);
734 FreeDeviceProc(devproc);
736 d1(kprintf("%s/%s/%ld: END inMain=%08lx\n", __FILE__, __FUNC__, __LINE__, inMain));
738 return inMain;
742 struct ScaIconNode *FindBackdropIcon(BPTR dirLock, CONST_STRPTR iconName)
744 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
745 struct ScaIconNode *in, *inFound = NULL;
747 if (NULL == iwtMain)
749 d1(kprintf("%s/%s/%ld: iwtMain=%08lx\n", __FILE__, __FUNC__, __LINE__, iwtMain));
750 return inFound;
753 d1(KPrintF("%s/%s/%ld: iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwtMain));
755 ScalosLockIconListShared(iwtMain);
757 for (in=iwtMain->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
759 if (in->in_Lock &&
760 LOCK_SAME == ScaSameLock(in->in_Lock, dirLock) &&
761 0 == Stricmp(iconName, GetIconName(in)))
763 d1(kprintf("%s/%s/%ld: iwtMain=%08lx in=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwtMain, in, GetIconName(in)));
764 inFound = in;
765 break;
769 if (NULL == inFound)
770 ScalosUnLockIconList(iwtMain);
772 d1(kprintf("%s/%s/%ld: inFound=%08lx\n", __FILE__, __FUNC__, __LINE__, inFound));
774 return inFound;
778 struct ScaIconNode *FindBackdropIconExclusive(BPTR dirLock, CONST_STRPTR iconName)
780 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
781 struct ScaIconNode *in, *inFound = NULL;
783 if (NULL == iwtMain)
785 d1(kprintf("%s/%s/%ld: iwtMain=%08lx\n", __FILE__, __FUNC__, __LINE__, iwtMain));
786 return inFound;
789 d1(KPrintF("%s/%s/%ld: iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwtMain));
791 ScalosLockIconListExclusive(iwtMain);
793 for (in=iwtMain->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
795 if (LOCK_SAME == ScaSameLock(in->in_Lock, dirLock) &&
796 0 == Stricmp(iconName, GetIconName(in)))
798 d1(kprintf("%s/%s/%ld: iwtMain=%08lx in=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwtMain, in, GetIconName(in)));
799 inFound = in;
800 break;
804 if (NULL == inFound)
805 ScalosUnLockIconList(iwtMain);
807 d1(kprintf("%s/%s/%ld: inFound=%08lx\n", __FILE__, __FUNC__, __LINE__, inFound));
809 return inFound;
813 static void BackdropRemoveObsoleteEntriesFromBackdropFile(struct BackDropList *bdl)
815 char *IconPath;
816 struct ChainedLine *cnl;
818 IconPath = AllocPathBuffer();
819 if (NULL == IconPath)
820 return;
822 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
823 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail; )
825 struct ChainedLine *cnlNext = (struct ChainedLine *) cnl->cnl_Node.ln_Succ;
826 BPTR fLock;
827 LONG LockResult;
829 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
831 // clean up .backdrop
832 // check if icon exists that this .backdrop line refers to
833 stccpy(IconPath, cnl->cnl_Line, Max_PathLen - 1);
834 SafeStrCat(IconPath, ".info", Max_PathLen - 1);
836 d1(kprintf("%s/%s/%ld: IconPath=<%s>\n", __FILE__, __FUNC__, __LINE__, IconPath));
838 fLock = Lock(IconPath, ACCESS_READ);
839 if ((BPTR)NULL == fLock)
841 LockResult = IoErr();
843 else
845 LockResult = RETURN_OK;
846 UnLock(fLock);
849 d1(kprintf("%s/%s/%ld: LockResult=%ld\n", __FILE__, __FUNC__, __LINE__, LockResult));
851 if (ERROR_OBJECT_NOT_FOUND == LockResult)
853 d1(kprintf("%s/%s/%ld: LockResult=%ld - GO Remove <%s> \n", __FILE__, __FUNC__, __LINE__, LockResult, cnl->cnl_Line));
854 Remove(&cnl->cnl_Node);
855 BackdropFreeChainedLine(cnl);
856 bdl->bdl_Changed = TRUE;
859 cnl = cnlNext;
862 FreePathBuffer(IconPath);
865 //----------------------------------------------------------------------------
867 static void BackdropRemoveDuplicateEntriesFromBackdropFile(struct BackDropList *bdl)
869 char *IconPath;
870 struct ChainedLine *cnl;
872 IconPath = AllocPathBuffer();
873 if (NULL == IconPath)
874 return;
876 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
877 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail;
878 cnl = (struct ChainedLine *) cnl->cnl_Node.ln_Succ )
880 ULONG Removed = 0;
881 struct ChainedLine *cnl2;
883 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
885 for (cnl2 = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
886 cnl2 != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail; )
888 struct ChainedLine *cnl2Next = (struct ChainedLine *) cnl2->cnl_Node.ln_Succ;
890 if ((cnl2 != cnl) && (0 == Stricmp(cnl2->cnl_Line, cnl->cnl_Line)) )
892 // Remove Duplicate line
893 d1(kprintf("%s/%s/%ld: GO Remove <%s> \n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
894 Remove(&cnl2->cnl_Node);
895 BackdropFreeChainedLine(cnl2);
896 bdl->bdl_Changed = TRUE;
897 Removed++;
900 cnl2 = cnl2Next;
902 if (Removed)
903 cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
906 FreePathBuffer(IconPath);
909 //----------------------------------------------------------------------------
910 void DoLeaveOutIcon(struct internalScaWindowTask *iwt, BPTR DirLock,
911 CONST_STRPTR IconName, WORD x, WORD y)
913 struct BackDropList bdl;
914 BPTR oldDir = NOT_A_LOCK;
915 BPTR rootLock = (BPTR)NULL;
916 char *lp, *DirName = NULL;
918 d1(KPrintF("%s/%s/%ld: START Icon=<%s> Lock=%08lx\n", __FILE__, __FUNC__, __LINE__, IconName, DirLock));
919 debugLock_d1(DirLock);
921 BackDropInitList(&bdl);
923 do {
924 if (IsPermanentBackDropIcon(iwt, &bdl, DirLock, IconName))
925 break; // this is already a backdrop icon
927 d1(KPrintF("%s/%s/%ld: ws_Lock=%08lx DirLock=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock, DirLock));
929 DirName = AllocPathBuffer();
930 if (NULL == DirName)
931 break;
933 d1(KPrintF("%s/%s/%ld: DirName=%08lx\n", __FILE__, __FUNC__, __LINE__, DirName));
935 if (!NameFromLock(DirLock, DirName, Max_PathLen - 1))
936 break;
938 d1(KPrintF("%s/%s/%ld: DirName=<%s>\n", __FILE__, __FUNC__, __LINE__, DirName));
940 if (!AddPart(DirName, (STRPTR) IconName, Max_PathLen - 1))
941 break;
943 d1(KPrintF("%s/%s/%ld: DirName = <%s>\n", __FILE__, __FUNC__, __LINE__, DirName));
945 oldDir = CurrentDir(DirLock);
947 rootLock = Lock(":", ACCESS_READ);
948 if ((BPTR)NULL == rootLock)
949 break;
951 CurrentDir(oldDir);
952 oldDir = NOT_A_LOCK;
953 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
955 if ((BPTR)NULL == rootLock)
956 break;
958 oldDir = CurrentDir(rootLock);
959 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
961 if (RETURN_OK != BackdropLoadList(&bdl))
962 break;
964 lp = strchr(DirName, ':');
965 if (NULL == lp)
966 lp = DirName;
968 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
970 if (!BackdropAddLine(&bdl, lp, x, y))
971 break;
973 ShortcutAddEntry(DirName, x, y);
975 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
977 BackdropWriteList(&bdl);
979 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
981 if (iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock)
983 d1(KPrintF("%s/%s/%ld: AddBackdropIcon(%08lx, %s, x, y)\n", __FILE__, __FUNC__, __LINE__, \
984 iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock, IconName));
986 AddBackdropIcon(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock,
987 IconName, x, y);
989 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
991 // Special handling for "view all" textwindows.
992 // here both object and icon are separate entries, which must be removed both!
993 if (!IsIwtViewByIcon(iwt) &&
994 IsShowAll(iwt->iwt_WindowTask.mt_WindowStruct))
996 STRPTR IconInfoName = ScalosAlloc(1 + strlen(IconName) + strlen(".info"));
998 if (IconInfoName)
1000 strcpy(IconInfoName, IconName);
1001 strcat(IconInfoName, ".info");
1003 // remove associated ".info" icon from owning drawer window
1004 DoMethod(iwt->iwt_WindowTask.mt_MainObject,
1005 SCCM_IconWin_RemIcon,
1006 iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock,
1007 IconInfoName);
1011 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1013 // remove icon from owning drawer window
1014 DoMethod(iwt->iwt_WindowTask.mt_MainObject,
1015 SCCM_IconWin_RemIcon,
1016 iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock,
1017 IconName);
1019 else
1021 // For icon dropped on desktop:
1022 // If ScaIconNode lock and name = DirLock and IconName then
1023 // update INF_SupportsPutAway and INF_SupportsLeaveOut flags.
1025 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
1026 struct ScaIconNode *in;
1028 ScalosLockIconListShared(iwtMain);
1030 for (in = iwtMain->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
1032 if (LOCK_SAME == ScaSameLock(in->in_Lock, DirLock) &&
1033 0 == Stricmp(IconName, GetIconName(in)))
1035 d1(KPrintF("%s/%s/%ld: in_Lock=%08lx DirLock=%08lx in_Name=<%s> IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, \
1036 in->in_Lock, DirLock, GetIconName(in), IconName));
1038 CurrentDir(oldDir);
1039 oldDir = CurrentDir(DirLock);
1040 in->in_SupportFlags |= INF_SupportsPutAway;
1041 in->in_SupportFlags &= ~INF_SupportsLeaveOut;
1043 SetAttrs(in->in_Icon,
1044 IDTA_OverlayType, ICONOVERLAYF_LeftOut,
1045 TAG_END);
1047 d1(KPrintF("%s/%s/%ld: ICONOVERLAYF_LeftOut is SET IconName=<%s>\n", __FILE__, __FUNC__, __LINE__, GetIconName(in)));
1048 BackdropRedrawMainIconObject(iwtMain, in->in_Icon);
1049 break;
1053 ScalosUnLockIconList(iwtMain);
1056 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1057 } while (0);
1059 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1061 BackdropFreeList(&bdl);
1063 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1065 if (IS_VALID_LOCK(oldDir))
1066 CurrentDir(oldDir);
1067 if (rootLock)
1068 UnLock(rootLock);
1069 if (DirName)
1070 FreePathBuffer(DirName);
1072 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
1075 //----------------------------------------------------------------------------
1077 BOOL IsPermanentBackDropIcon(struct internalScaWindowTask *iwt, struct BackDropList *bdl,
1078 BPTR fLock, CONST_STRPTR FileName)
1080 BOOL IsBackdrop = FALSE;
1082 debugLock_d1(fLock);
1083 d1(KPrintF("%s/%s/%ld: bdl=%08lx Loaded=%ld FileName=<%s>\n", \
1084 __FILE__, __FUNC__, __LINE__, bdl, bdl->bdl_Loaded, FileName));
1086 if (!bdl->bdl_Loaded && !bdl->bdl_NotPresent)
1088 BPTR oldDir;
1089 BPTR DirLock;
1091 do {
1092 oldDir = CurrentDir(fLock);
1094 DirLock = Lock(":", ACCESS_READ);
1095 debugLock_d1(DirLock);
1096 if ((BPTR)NULL == DirLock)
1097 break;
1099 // change to root directory of icon drawer
1100 CurrentDir(DirLock);
1102 if (RETURN_OK != BackdropLoadList(bdl))
1103 break;
1104 } while (0);
1106 CurrentDir(oldDir);
1107 if (DirLock)
1108 UnLock(DirLock);
1111 d1(kprintf("%s/%s/%ld: bdl=%08lx Loaded=%ld NotPresent=%ld bdl_Filtered=%ld\n", \
1112 __FILE__, __FUNC__, __LINE__, bdl, bdl->bdl_Loaded, bdl->bdl_NotPresent, bdl->bdl_Filtered));
1114 if (bdl->bdl_Loaded)
1116 if (bdl->bdl_Filtered)
1118 struct ChainedLine *cnl;
1120 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
1121 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail;
1122 cnl = (struct ChainedLine *) cnl->cnl_Node.ln_Succ)
1124 STRPTR lp = FilePart(cnl->cnl_Line);
1126 d1(kprintf("%s/%s/%ld: lp=<%s>\n", __FILE__, __FUNC__, __LINE__, lp));
1128 if (0 == Stricmp(FileName, lp))
1130 // entry found
1131 d1(kprintf("%s/%s/%ld: Line=<%s> IsBackdrop=[ %ld ]\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line, IsBackdrop));
1132 IsBackdrop = TRUE;
1133 break;
1137 else
1139 char *IconPath;
1140 struct ChainedLine *cnl;
1141 STRPTR PathStart;
1143 do {
1144 IconPath = AllocPathBuffer();
1145 if (NULL == IconPath)
1146 break;
1148 if (!NameFromLock(fLock, IconPath, Max_PathLen-1))
1149 break;
1151 if (!AddPart(IconPath, (STRPTR) FileName, Max_PathLen-1))
1152 break;
1154 d1(kprintf("%s/%s/%ld: IconPath=<%s>\n", __FILE__, __FUNC__, __LINE__, IconPath));
1156 PathStart = strchr(IconPath, ':');
1157 if (NULL == PathStart)
1158 PathStart = IconPath;
1160 for (cnl = (struct ChainedLine *) bdl->bdl_LinesList.lh_Head;
1161 cnl != (struct ChainedLine *) &bdl->bdl_LinesList.lh_Tail;
1162 cnl = (struct ChainedLine *) cnl->cnl_Node.ln_Succ)
1164 d1(kprintf("%s/%s/%ld: Line=<%s>\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line));
1166 if (0 == Stricmp((STRPTR) PathStart, cnl->cnl_Line))
1168 // entry found
1169 d1(kprintf("%s/%s/%ld: Line=<%s> IsBackdrop=[ %ld ]\n", __FILE__, __FUNC__, __LINE__, cnl->cnl_Line, IsBackdrop));
1170 IsBackdrop = TRUE;
1171 break;
1174 } while (0);
1176 if (IconPath)
1177 FreePathBuffer(IconPath);
1181 d1(KPrintF("%s/%s/%ld: IsBackdrop=%ld\n", __FILE__, __FUNC__, __LINE__, IsBackdrop));
1183 return IsBackdrop;
1186 //----------------------------------------------------------------------------
1188 void PutAwayIcon(struct internalScaWindowTask *iwt,
1189 BPTR iconDirLock, CONST_STRPTR IconName, BOOL RemovePermanent)
1191 BPTR oldDir;
1192 BPTR iconLock = (BPTR)NULL;
1193 BPTR rootLock = (BPTR)NULL;
1194 struct BackDropList bdl;
1195 STRPTR Path = NULL;
1196 struct ScaUpdateIcon_IW UpdateIcon = { (BPTR)NULL, NULL, ICONTYPE_NONE };
1198 BackDropInitList(&bdl);
1200 d1(KPrintF("%s/%s/%ld: Icon=<%s>\n", __FILE__, __FUNC__, __LINE__, IconName));
1201 debugLock_d1(iconDirLock);
1203 do {
1204 debugLock_d1(iconDirLock);
1206 oldDir = CurrentDir(iconDirLock);
1208 if (!IsPermanentBackDropIcon(iwt, &bdl, iconDirLock, IconName))
1210 // +jmc+ : This is not a backdrop icon(icon dropped) then remove object from main window.
1211 if (iwt->iwt_WindowTask.mt_WindowStruct == iInfos.xii_iinfos.ii_MainWindowStruct)
1213 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
1214 struct ScaIconNode *in;
1216 UpdateIcon.ui_iw_Name = AllocCopyString(IconName);
1218 ScalosLockIconListExclusive(iwtMain);
1219 for (in = iwtMain->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
1221 if (in->in_Lock
1222 && LOCK_SAME == SameLock(in->in_Lock, iconDirLock)
1223 && 0 == Stricmp(IconName, GetIconName(in)))
1225 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_DeviceWin_RemIcon, in);
1226 d1(KPrintF("%s/%s/%ld: Not Permanent BackDrop Icon=<%s> removed from desktop\n", __FILE__, __FUNC__, __LINE__, IconName));
1227 break;
1230 ScalosUnLockIconList(iwtMain);
1232 break;
1235 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1237 Path = AllocPathBuffer();
1238 if (NULL == Path)
1239 break;
1241 stccpy(Path, IconName, Max_PathLen);
1242 SafeStrCat(Path, ".info", Max_PathLen);
1244 iconLock = Lock(Path, ACCESS_READ);
1245 d1(KPrintF("%s/%s/%ld: IconName=<%s> iconLock=%08lx\n", __FILE__, __FUNC__, __LINE__, IconName, iconLock));
1246 if ((BPTR)NULL == iconLock)
1247 break;
1249 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1251 if (RemovePermanent)
1253 rootLock = Lock(":", ACCESS_READ);
1254 if ((BPTR)NULL == rootLock)
1255 break;
1257 CurrentDir(oldDir);
1259 oldDir = CurrentDir(rootLock);
1261 BackdropRemoveLine(&bdl, iconLock);
1263 ShortcutRemoveEntry(iconLock);
1265 CurrentDir(rootLock);
1267 if (bdl.bdl_Changed)
1268 BackdropWriteList(&bdl);
1271 if (iwt->iwt_WindowTask.mt_WindowStruct == iInfos.xii_iinfos.ii_MainWindowStruct)
1273 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
1274 struct ScaIconNode *in;
1276 UpdateIcon.ui_iw_Name = AllocCopyString(IconName);
1278 // remove icon from main window
1279 ScalosLockIconListExclusive(iwtMain);
1280 for (in = iwtMain->iwt_WindowTask.wt_IconList; in; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
1282 if (in->in_Lock
1283 && LOCK_SAME == SameLock(in->in_Lock, iconDirLock)
1284 && 0 == Stricmp(IconName, GetIconName(in)))
1286 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_DeviceWin_RemIcon, in);
1287 d1(KPrintF("%s/%s/%ld: Permanent BackDrop Icon=<%s> removed from desktop - Icon SupportsFalgs UPDATED!\n", \
1288 __FILE__, __FUNC__, __LINE__, IconName));
1289 break;
1292 ScalosUnLockIconList(iwtMain);
1295 d1(KPrintF("%s/%s/%ld: Changed=%ld\n", __FILE__, __FUNC__, __LINE__, bdl.bdl_Changed));
1296 } while (0);
1298 d1(KPrintF("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
1300 BackdropFreeList(&bdl);
1302 if (Path)
1303 FreePathBuffer(Path);
1304 if (UpdateIcon.ui_iw_Name)
1305 FreeCopyString(UpdateIcon.ui_iw_Name);
1306 if (IS_VALID_LOCK(oldDir))
1307 CurrentDir(oldDir);
1308 if (UpdateIcon.ui_iw_Lock)
1309 UnLock(UpdateIcon.ui_iw_Lock);
1310 if (iconLock)
1311 UnLock(iconLock);
1312 if (rootLock)
1313 UnLock(rootLock);
1317 static void BackdropRedrawMainIconObject(struct internalScaWindowTask *iwtMain, Object *IconObj)
1319 struct SM_RedrawIconObj *sMsg;
1321 sMsg = (struct SM_RedrawIconObj *) SCA_AllocMessage(MTYP_RedrawIconObj, 0);
1322 d1(KPrintF("%s/%s/%ld: sMsg=%08lx\n", __FILE__, __FUNC__, __LINE__, sMsg));
1323 if (sMsg)
1325 sMsg->smrio_IconObject = IconObj;
1326 sMsg->smrio_Flags = SMRIOFLAGF_IconListLocked;
1327 PutMsg(iwtMain->iwt_WindowTask.wt_IconPort,
1328 &sMsg->ScalosMessage.sm_Message);
1333 // Wait up to 2 seconds for completion of backdrop icon generation on desktop
1334 BOOL BackdropWait(BPTR dirLock)
1336 struct internalScaWindowTask *iwtMain = (struct internalScaWindowTask *) iInfos.xii_iinfos.ii_MainWindowStruct->ws_WindowTask;
1337 struct ScaIconNode *in;
1338 BOOL Found = FALSE;
1339 ULONG n = 20;
1341 if (NULL == iwtMain)
1343 d1(kprintf("%s/%s/%ld: iwtMain=%08lx\n", __FILE__, __FUNC__, __LINE__, iwtMain));
1344 return Found;
1346 if (BNULL == dirLock)
1348 d1(kprintf("%s/%s/%ld: dirLock=0\n", __FILE__, __FUNC__, __LINE__));
1349 return Found;
1352 d1(KPrintF("%s/%s/%ld: START iwtMain=%08lx\n", __FILE__, __FUNC__, __LINE__, iwtMain));
1354 do {
1355 ScalosLockIconListShared(iwtMain);
1357 for (in=iwtMain->iwt_WindowTask.wt_IconList; in && !Found; in = (struct ScaIconNode *) in->in_Node.mln_Succ)
1359 if (in->in_DeviceIcon)
1361 BPTR DeviceIconLock = DiskInfoLock(in);
1363 if (DeviceIconLock)
1365 LONG IsSameLock;
1367 IsSameLock = ScaSameLock(DeviceIconLock, dirLock);
1369 if (LOCK_SAME_VOLUME == IsSameLock || LOCK_SAME == IsSameLock)
1371 d1(kprintf("%s/%s/%ld: Found Device Icon in=<%s> di_Flags=%08lx\n", \
1372 __FILE__, __FUNC__, __LINE__, GetIconName(in), \
1373 in->in_DeviceIcon->di_Flags));
1374 Found = in->in_DeviceIcon->di_Flags & DIBF_BackdropReadComplete;
1377 UnLock(DeviceIconLock);
1382 ScalosUnLockIconList(iwtMain);
1384 if (!Found)
1385 Delay(5); // wait 100 ms
1387 } while (!Found && (n-- > 0));
1390 d1(kprintf("%s/%s/%ld: END Found=%ld\n", __FILE__, __FUNC__, __LINE__, Found));
1392 return Found;