fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / scalos / main / ScanDirText.c
blob7225e6e3b1ed881a8c7cb762607f4ee6c8e19748
1 // ScanDir.c
2 // $Date$
3 // $Revision$
4 // $Id$
6 #include <exec/types.h>
7 #include <intuition/classes.h>
8 #include <intuition/classusr.h>
9 #include <utility/hooks.h>
10 #include <intuition/gadgetclass.h>
11 #include <datatypes/pictureclass.h>
12 #include <dos/dos.h>
13 #include <dos/dostags.h>
14 #include <dos/exall.h>
16 #define __USE_SYSBASE
18 #include <proto/dos.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/iconobject.h>
22 #include <proto/utility.h>
23 #include <proto/gadtools.h>
24 #include <proto/datatypes.h>
25 #include "debug.h"
26 #include <proto/scalos.h>
28 #include <clib/alib_protos.h>
30 #include <defs.h>
31 #include <datatypes/iconobject.h>
32 #include <scalos/scalos.h>
34 #include <DefIcons.h>
36 #include <string.h>
37 #include <stdio.h>
38 #include <stdarg.h>
40 #include "scalos_structures.h"
41 #include "locale.h"
42 #include "functions.h"
43 #include "Variables.h"
45 //----------------------------------------------------------------------------
47 // local data definitions
49 //----------------------------------------------------------------------------
51 // local functions
53 static BOOL IsBackDropIconTextWindow(struct internalScaWindowTask *iwt, struct BackDropList *bdl,
54 BPTR fLock, CONST_STRPTR FileName, IPTR pos);
55 static enum ScanDirResult TextCheckCleanup(struct ReadIconListControl *rilc);
56 static enum ScanDirResult GenerateTextIcons(struct ReadIconListControl *rilc, BOOL Final);
57 static struct ScaIconNode *GetTextIcon(struct internalScaWindowTask *iwt,
58 struct Hook *ColumnChangeHook, struct IconScanEntry *ise,
59 struct BackDropList *bdl, const struct ReadIconListData *rild);
60 static void ResolveLink(struct ReadIconListData *rild);
61 // static LONG ReExamine(struct ReadIconListData *rild);
63 //----------------------------------------------------------------------------
65 // local data
67 //----------------------------------------------------------------------------
69 // public data items
71 //----------------------------------------------------------------------------
73 /// TextWindowReadIcon
74 // Result : Success
75 struct ScaIconNode *TextWindowReadIcon(struct internalScaWindowTask *iwt,
76 CONST_STRPTR Name, struct ScaReadIconArg *ria)
78 struct ScaIconNode *in = NULL;
79 ULONG err;
80 T_ExamineData *fib = NULL;
81 BPTR oldDir = NOT_A_LOCK;
82 BPTR dirLock;
83 BOOL VolumeIsWritable;
84 BOOL ScanDirSemaphoreLocked = FALSE;
85 struct ReadIconListControl rilc;
87 do {
88 BPTR iLock;
89 IPTR pos;
90 BOOL hasIcon = FALSE;
91 struct ReadIconListData rild;
93 d1(KPrintF("%s/%s/%ld: Name=<%s> ria=%08lx iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, Name, ria, iwt));
95 if (!RilcInit(&rilc, iwt))
96 break;
98 if (NULL == iwt->iwt_WindowTask.wt_Window)
99 break;
101 BackdropWait(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock);
103 if (!AttemptSemaphoreNoNest(&iwt->iwt_ScanDirSemaphore))
104 break;
106 ScanDirSemaphoreLocked = TRUE;
108 if (!IsShowAll(iwt->iwt_WindowTask.mt_WindowStruct) && 0 != IsIconName(Name))
110 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
111 break;
114 if (!ScalosExamineBegin(&fib))
116 d1(kprintf("%s/%s/%ld: ScalosExamineBegin failed\n", __FILE__, __FUNC__, __LINE__));
117 break;
120 if (ria && ria->ria_Lock)
121 dirLock = ria->ria_Lock;
122 else
123 dirLock = iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock;
125 debugLock_d1(dirLock);
126 if ((BPTR)NULL == dirLock)
127 break;
129 VolumeIsWritable = ClassIsDiskWritable(dirLock);
131 oldDir = CurrentDir(dirLock);
133 err = RETURN_OK;
134 iLock = Lock((STRPTR) Name, ACCESS_READ);
135 if (BNULL == iLock)
137 err = IoErr();
138 d1(kprintf("%s/%s/%ld: Lock returned %ld\n", __FILE__, __FUNC__, __LINE__, err));
140 else
142 if (!ScalosExamineLock(iLock, &fib))
143 err = IoErr();
144 UnLock(iLock);
146 d1(kprintf("%s/%s/%ld: ScalosExamineLock returned %ld\n", __FILE__, __FUNC__, __LINE__, err));
149 if (ERROR_OBJECT_IN_USE == err)
150 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_ScheduleUpdate);
152 rild.rild_SoloIcon = FALSE;
154 if (ERROR_OBJECT_NOT_FOUND == err)
156 // object doesn't exist - check if associated icon is there
157 BOOL iconExists = FALSE;
158 STRPTR iconName = AllocPathBuffer();
160 d1(kprintf("%s/%s/%ld: iconName=%08lx\n", __FILE__, __FUNC__, __LINE__, iconName));
162 if (iconName)
164 BPTR iLock;
166 stccpy(iconName, Name, Max_PathLen);
167 SafeStrCat(iconName, ".info", Max_PathLen);
169 iLock = Lock(iconName, ACCESS_READ);
170 if (iLock)
172 rild.rild_SoloIcon = TRUE;
173 ScalosExamineLock(iLock, &fib);
174 iconExists = TRUE;
175 UnLock(iLock);
178 FreePathBuffer(iconName);
181 if (!iconExists)
183 break;
186 stccpy(rild.rild_Name, ScalosExamineGetName(fib), sizeof(rild.rild_Name));
188 else if (RETURN_OK != err)
190 stccpy(rild.rild_Name, Name, sizeof(rild.rild_Name));
192 else
194 // Success
195 stccpy(rild.rild_Name, ScalosExamineGetName(fib), sizeof(rild.rild_Name));
198 if (NULL == fib)
200 break;
203 stccpy(rild.rild_Comment, ScalosExamineGetComment(fib), sizeof(rild.rild_Comment));
204 rild.rild_OwnerUID = ScalosExamineGetDirUID(fib);
205 rild.rild_OwnerGID = ScalosExamineGetDirGID(fib);
206 rild.rild_Protection = ScalosExamineGetProtection(fib);
207 rild.rild_DateStamp = *ScalosExamineGetDate(fib);
208 rild.rild_Type = ScalosExamineGetDirEntryType(fib);
209 rild.rild_Size64 = ScalosExamineGetSize(fib);
210 rild.rild_DiskWriteProtected = !VolumeIsWritable;
211 rild.rild_CheckOverlap = TRUE;
213 if (IsFileHidden(rild.rild_Name, rild.rild_Protection))
215 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
216 break;
219 //ReExamine(&rild);
221 d1(kprintf("%s/%s/%ld: rild_Name=<%s>\n", __FILE__, __FUNC__, __LINE__, rild.rild_Name));
223 // this might be a softlink?
224 if (IsSoftLink(Name))
226 stccpy(rild.rild_Name, Name, sizeof(rild.rild_Name));
227 rild.rild_Type = ST_SOFTLINK;
228 d1(kprintf("%s/%s/%ld: ST_SOFTLINK rild_Name=<%s>\n", __FILE__, __FUNC__, __LINE__, rild.rild_Name));
231 pos = IsIconName(rild.rild_Name);
233 rild.rild_TypeNode = DefIconsIdentify(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock, rild.rild_Name,
234 ria ? ria->ria_IconType : ICONTYPE_NONE);
236 d1(kprintf("%s/%s/%ld: Name=<%s> pos=%08lx\n", __FILE__, __FUNC__, __LINE__, rild.rild_Name, pos));
238 // Read Text Icon
239 d1(kprintf("%s/%s/%ld: Name=<%s>\n", __FILE__, __FUNC__, __LINE__, rild.rild_Name));
241 if (IsShowAllType(iwt->iwt_OldShowType))
243 in = GetTextIcon(iwt, &iwt->iwt_ColumnWidthChangeHook, NULL, &rilc.rilc_BackdropList, &rild);
245 d1(kprintf("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
247 if (0 != pos && ~0 != pos)
249 // rild.rild_Name IS an icon
250 hasIcon = TRUE;
252 else
254 // we need to check whether an icon (.info) is present
255 STRPTR IconFileName = AllocPathBuffer();
257 if (IconFileName)
259 BPTR IconLock;
261 stccpy(IconFileName, rild.rild_Name, MAX_FileName);
262 SafeStrCat(IconFileName, ".info", MAX_FileName);
263 if ((IconLock = Lock(IconFileName, ACCESS_READ)))
265 hasIcon = TRUE;
266 UnLock(IconLock);
268 FreePathBuffer(IconFileName);
272 if (in && 0 == pos)
274 ClassSetDefaultIconFlags(in, !hasIcon);
275 d1(kprintf("%s/%s/%ld: in=<%s> pos=%08lx hasIcon=%ld\n", \
276 __FILE__, __FUNC__, __LINE__, GetIconName(in), pos, hasIcon));
279 else
281 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
283 if (rild.rild_SoloIcon && 0 != pos && ~0 != pos)
285 // strip ".info" from name
286 *((char *) pos) = '\0';
289 in = GetTextIcon(iwt, &iwt->iwt_ColumnWidthChangeHook, NULL, &rilc.rilc_BackdropList, &rild);
290 hasIcon = TRUE;
292 d1(kprintf("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
295 d1(KPrintF("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
297 if (in)
299 in->in_SupportFlags |= INF_SupportsOpen | INF_SupportsCopy | INF_SupportsInformation;
301 d1(KPrintF("%s/%s/%ld: in=%08lx hasIcon=%ld VolumeIsWritable=%ld\n", __FILE__, __FUNC__, __LINE__, in, hasIcon, VolumeIsWritable));
303 if (hasIcon)
304 in->in_SupportFlags |= INF_SupportsSnapshot | INF_SupportsUnSnapshot;
306 if (VolumeIsWritable)
308 if (hasIcon)
309 in->in_SupportFlags |= INF_SupportsSnapshot | INF_SupportsUnSnapshot;
311 if (IsPermanentBackDropIcon(iwt, &rilc.rilc_BackdropList, dirLock, GetIconName(in)))
313 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
314 in->in_SupportFlags |= INF_SupportsPutAway;
315 in->in_SupportFlags &= ~INF_SupportsLeaveOut;
317 else
319 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
320 in->in_SupportFlags &= ~INF_SupportsPutAway;
321 in->in_SupportFlags |= INF_SupportsLeaveOut;
324 else
326 in->in_SupportFlags &= ~(INF_SupportsSnapshot | INF_SupportsUnSnapshot);
329 if (!hasIcon)
330 in->in_SupportFlags &= ~INF_SupportsLeaveOut;
332 if (0 != pos)
333 in->in_SupportFlags &= ~(INF_SupportsSnapshot | INF_SupportsUnSnapshot | INF_SupportsLeaveOut);
335 d1(KPrintF("%s/%s/%ld: in=<%s> supportFlags=%08lx hasIcon=%ld pos=%lu\n", \
336 __FILE__, __FUNC__, __LINE__, GetIconName(in), in->in_SupportFlags, hasIcon, pos));
338 in->in_FileType = rild.rild_TypeNode;
340 SetIconSupportsFlags(in, VolumeIsWritable);
342 if (!DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_TextWin_InsertIcon, in))
344 // SCCM_TextWin_InsertIcon failed
345 struct ScaIconNode *IconList = NULL;
347 SCA_MoveIconNode(&iwt->iwt_WindowTask.wt_IconList, &IconList, in);
348 FreeIconList(iwt, &IconList);
351 } while (0);
353 RilcCleanup(&rilc);
355 if (ScanDirSemaphoreLocked)
356 ScalosReleaseSemaphore(&iwt->iwt_ScanDirSemaphore);
358 if (IS_VALID_LOCK(oldDir))
359 CurrentDir(oldDir);
360 ScalosExamineEnd(&fib);
362 d1(KPrintF("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
364 return in;
368 /// IsBackDropIconTextWindow
369 static BOOL IsBackDropIconTextWindow(struct internalScaWindowTask *iwt, struct BackDropList *bdl,
370 BPTR fLock, CONST_STRPTR FileName, IPTR pos)
372 BOOL Result;
374 if (0 != pos && ~0 != pos)
376 // FileName is an icon, generate name for non-icon
377 STRPTR ObjectName = AllocCopyString(FileName);
379 if (NULL == ObjectName)
381 Result = ScanDirIsBackDropIcon(iwt, bdl, fLock, FileName);
383 else
385 ObjectName[((STRPTR) pos) - FileName] = '\0';
387 Result = ScanDirIsBackDropIcon(iwt, bdl, fLock, ObjectName);
388 FreeCopyString(ObjectName);
391 else
393 Result = ScanDirIsBackDropIcon(iwt, bdl, fLock, FileName);
396 return Result;
400 /// TextCheckCleanup
401 static enum ScanDirResult TextCheckCleanup(struct ReadIconListControl *rilc)
403 enum ScanDirResult sdResult = SCANDIR_OK;
405 if (rilc->rilc_CleanupCount++ > 20)
407 struct internalScaWindowTask *iwt = rilc->rilc_WindowTask;
409 rilc->rilc_CleanupCount = 0;
411 d1(kprintf("%s/%s/%ld: IconList=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt->iwt_WindowTask.wt_LateIconList));
413 ScanDirUpdateStatusBarText(iwt, rilc->rilc_TotalFound);
416 return sdResult;
420 /// GenerateTextIcons
421 static enum ScanDirResult GenerateTextIcons(struct ReadIconListControl *rilc, BOOL Final)
423 struct internalScaWindowTask *iwt = rilc->rilc_WindowTask;
424 struct IconScanEntry *ise;
425 enum ScanDirResult sdResult;
428 d1(KPrintF("%s/%s/%ld: START Final=%ld\n", __FILE__, __FUNC__, __LINE__, Final));
430 // build links between icons and objects
431 sdResult = LinkIconScanList(rilc);
432 if (SCANDIR_OK != sdResult)
433 return sdResult;
435 if (Final)
437 while ((ise = (struct IconScanEntry *) RemTail(&rilc->rilc_UnlinkedIconScanList)))
439 // Move all remaining unlinked icons from rilc_UnlinkedIconScanList to rilc_IconScanList
440 Remove(&ise->ise_Node);
441 AddTail(&rilc->rilc_IconScanList, &ise->ise_Node);
445 for (ise = (struct IconScanEntry *) rilc->rilc_IconScanList.lh_Head;
446 SCANDIR_OK == sdResult && ise != (struct IconScanEntry *) &rilc->rilc_IconScanList.lh_Tail;
447 ise = (struct IconScanEntry *) ise->ise_Node.ln_Succ)
449 BOOL ShowEntry = TRUE;
451 if (ise->ise_Flags & ISEFLG_Used)
452 continue;
454 if (rilc->rilc_OrigViewByType != iwt->iwt_WindowTask.mt_WindowStruct->ws_Viewmodes)
455 break;
457 if (!Final && NULL == ise->ise_ObjPtr && NULL == ise->ise_IconPtr)
458 continue;
460 d1(kprintf("%s/%s/%ld: ise=<%s> Flags=%08lx ObjPtr=%08lx IconPtr=%08lx\n", \
461 __FILE__, __FUNC__, __LINE__, ise->ise_Fib.fib_FileName, ise->ise_Flags, ise->ise_ObjPtr, ise->ise_IconPtr));
463 if (!IsShowAllType(iwt->iwt_OldShowType))
465 ShowEntry = (NULL == ise->ise_ObjPtr); // Icon w/o object
467 if (WBDISK == ise->ise_IconType)
468 ShowEntry = FALSE; // don't show WBDISK icons
471 if (IsFileHidden(ise->ise_Fib.fib_FileName, ise->ise_Fib.fib_Protection))
472 ShowEntry = FALSE;
474 if (ShowEntry)
476 struct ScaIconNode *in;
477 struct ReadIconListData rild;
479 rild.rild_DiskWriteProtected = !rilc->rilc_DiskWritable;
481 ScanDirFillRildFromIse(&rild, ise);
483 if (!IsShowAllType(iwt->iwt_OldShowType))
485 if (0 != ise->ise_Pos && ~0 != ise->ise_Pos)
487 // strip ".info" from name
488 STRPTR ppos = rild.rild_Name + ((STRPTR) ise->ise_Pos - (STRPTR) ise->ise_Fib.fib_FileName);
490 *ppos = '\0';
493 if (NULL == ise->ise_ObjPtr)
495 // icon w/o associated object
496 rild.rild_Size64 = MakeU64(0);
497 rild.rild_SoloIcon = TRUE;
499 d1(kprintf("%s/%s/%ld: ise=<%s> Flags=%08lx ObjPtr=%08lx IconPtr=%08lx SOLOicon\n", \
500 __FILE__, __FUNC__, __LINE__, ise->ise_Fib.fib_FileName, ise->ise_Flags, ise->ise_ObjPtr, ise->ise_IconPtr));
504 in = GetTextIcon(iwt, NULL, ise, &rilc->rilc_BackdropList, &rild);
506 d1(kprintf("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
508 if (in)
510 if (!(ise->ise_Flags & ISEFLG_IsIcon) && NULL == ise->ise_IconPtr)
512 ClassSetDefaultIconFlags(in, TRUE);
513 d1(kprintf("%s/%s/%ld: ise=<%s> Flags=%08lx ObjPtr=%08lx IconPtr=%08lx SOLOicon\n", \
514 __FILE__, __FUNC__, __LINE__, ise->ise_Fib.fib_FileName, ise->ise_Flags, ise->ise_ObjPtr, ise->ise_IconPtr));
517 d1(KPrintF("%s/%s/%ld: Name=<%s> rild_IconType=%ld\n", \
518 __FILE__, __FUNC__, __LINE__, rild.rild_Name, rild.rild_IconType));
520 SetIconSupportsFlags(in, rilc->rilc_DiskWritable);
524 if (iwt->iwt_WindowTask.mt_MainObject)
526 if (rilc->rilc_WindowTask->iwt_AbortScanDir)
527 sdResult = SCANDIR_ABORT;
528 else if (DoMethod(rilc->rilc_WindowTask->iwt_WindowTask.mt_MainObject, SCCM_CheckForMessages) )
529 sdResult = SCANDIR_WINDOW_CLOSING;
532 ise->ise_Flags |= ISEFLG_Used;
535 for (ise = (struct IconScanEntry *) rilc->rilc_NonIconScanList.lh_Head;
536 SCANDIR_OK == sdResult && ise != (struct IconScanEntry *) &rilc->rilc_NonIconScanList.lh_Tail;
537 ise = (struct IconScanEntry *) ise->ise_Node.ln_Succ)
539 BOOL ShowEntry = TRUE;
541 if (ise->ise_Flags & ISEFLG_Used)
542 continue;
544 if (!Final && NULL == ise->ise_ObjPtr && NULL == ise->ise_IconPtr)
545 continue;
547 d1(kprintf("%s/%s/%ld: ise=<%s> Flags=%08lx ObjPtr=%08lx IconPtr=%08lx\n", \
548 __FILE__, __FUNC__, __LINE__, ise->ise_Fib.fib_FileName, ise->ise_Flags, ise->ise_ObjPtr, ise->ise_IconPtr));
550 if (!IsShowAllType(iwt->iwt_OldShowType))
552 ShowEntry = (NULL != ise->ise_IconPtr); // Object with icon
555 if (IsFileHidden(ise->ise_Fib.fib_FileName, ise->ise_Fib.fib_Protection))
556 ShowEntry = FALSE;
558 if (ShowEntry)
560 struct ScaIconNode *in;
561 struct ReadIconListData rild;
563 rild.rild_DiskWriteProtected = !rilc->rilc_DiskWritable;
565 ScanDirFillRildFromIse(&rild, ise);
567 in = GetTextIcon(iwt, NULL, ise, &rilc->rilc_BackdropList, &rild);
569 d1(kprintf("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
571 if (in)
573 if (NULL == ise->ise_IconPtr)
574 ClassSetDefaultIconFlags(in, TRUE);
576 d1(KPrintF("%s/%s/%ld: Name=<%s> rild_IconType=%ld\n", \
577 __FILE__, __FUNC__, __LINE__, rild.rild_Name, rild.rild_IconType));
579 SetIconSupportsFlags(in, rilc->rilc_DiskWritable);
583 if (iwt->iwt_WindowTask.mt_MainObject)
585 if (rilc->rilc_WindowTask->iwt_AbortScanDir)
586 sdResult = SCANDIR_ABORT;
587 else if (DoMethod(rilc->rilc_WindowTask->iwt_WindowTask.mt_MainObject, SCCM_CheckForMessages) )
588 sdResult = SCANDIR_WINDOW_CLOSING;
591 ise->ise_Flags |= ISEFLG_Used;
594 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
596 return sdResult;
600 /// ReadTextWindowIconList
601 // Result :
602 // ==0 Success
603 // !=0 Failure
604 enum ScanDirResult ReadTextWindowIconList(struct internalScaWindowTask *iwt)
606 struct ReadIconListControl rilc;
607 enum ScanDirResult sdResult;
608 enum ScanDirResult Result;
609 ULONG Flags = REDRAWF_DontRefreshWindowFrame;
611 d1(KPrintF("\n" "%s/%s/%ld: START iwt=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt));
613 if (!RilcInit(&rilc, iwt))
614 return SCANDIR_FAIL_ABORT;
616 rilc.rilc_OrigViewByType = iwt->iwt_WindowTask.mt_WindowStruct->ws_Viewmodes;
617 rilc.rilc_TotalFound = 0;
619 if (!AttemptSemaphoreNoNest(&iwt->iwt_UpdateSemaphore))
620 return 0;
622 LockWindow(iwt);
624 ScalosLockIconListExclusive(iwt);
625 FreeIconList(iwt, &iwt->iwt_WindowTask.wt_IconList);
626 FreeIconList(iwt, &iwt->iwt_WindowTask.wt_LateIconList);
627 ScalosUnLockIconList(iwt);
629 iwt->iwt_AbortScanDir = FALSE;
631 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_Redraw, Flags);
633 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_SetVirtSize,
634 SETVIRTF_AdjustRightSlider | SETVIRTF_AdjustBottomSlider);
636 BackdropWait(iwt->iwt_WindowTask.mt_WindowStruct->ws_Lock);
638 // limit <wt_XOffset> and <wt_YOffset> to positive values
639 if (iwt->iwt_WindowTask.wt_XOffset < 0)
640 iwt->iwt_WindowTask.wt_XOffset = 0;
641 if (iwt->iwt_WindowTask.wt_YOffset < 0)
642 iwt->iwt_WindowTask.wt_YOffset = 0;
644 d1(kprintf("%s/%s/%ld: xOffset=%ld yOffset=%ld\n", __FILE__, __FUNC__, __LINE__, iwt->iwt_WindowTask.wt_XOffset, iwt->iwt_WindowTask.wt_YOffset));
646 sdResult = GetFileList(&rilc, TextCheckCleanup, CurrentPrefs.pref_UseExAll, TRUE, FALSE);
648 d1(kprintf("%s/%s/%ld: sdResult=%ld\n", __FILE__, __FUNC__, __LINE__, sdResult));
650 switch (sdResult)
652 case SCANDIR_VIEWMODE_CHANGE:
653 case SCANDIR_FINISHED:
654 Result = SCANDIR_OK; // Success
655 break;
656 default: // Failure
657 d1(kprintf("%s/%s/%ld: sdResult=%ld\n", __FILE__, __FUNC__, __LINE__, sdResult));
658 Result = sdResult;
659 break;
662 d1(kprintf("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
664 if (rilc.rilc_OrigViewByType == iwt->iwt_WindowTask.mt_WindowStruct->ws_Viewmodes)
666 struct Hook SortHook;
668 ScalosLockIconListExclusive(iwt);
670 SETHOOKFUNC(SortHook, GetTextIconSortFunction(iwt));
671 SortHook.h_Data = NULL;
673 sdResult = GenerateTextIcons(&rilc, TRUE);
675 d1(kprintf("%s/%s/%ld: IconList=%08lx SortFunc=%08lx\n", __FILE__, __FUNC__, __LINE__, iwt->iwt_WindowTask.wt_IconList, SortHook.h_Entry));
677 if (SCANDIR_OK != sdResult)
679 Result = sdResult;
681 else
683 if (SortHook.h_Entry)
684 SCA_SortNodes((struct ScalosNodeList *) &iwt->iwt_WindowTask.wt_IconList, &SortHook, SCA_SortType_Best);
686 if (iwt->iwt_WindowTask.wt_Window)
688 ReposTextIcons2(iwt);
690 d1(kprintf("%s/%s/%ld: before RefreshIcons()\n", __FILE__, __FUNC__, __LINE__));
691 RefreshIcons(iwt, NULL);
695 ScalosUnLockIconList(iwt);
698 RilcCleanup(&rilc);
700 ScalosReleaseSemaphore(&iwt->iwt_UpdateSemaphore);
702 UnLockWindow(iwt);
704 if (rilc.rilc_OrigViewByType != iwt->iwt_WindowTask.mt_WindowStruct->ws_Viewmodes)
705 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_Update);
707 SetMenuOnOff(iwt);
709 d1(KPrintF("%s/%s/%ld: END iwt=%08lx <%s>\n", __FILE__, __FUNC__, __LINE__, iwt, iwt->iwt_WinTitle));
711 return Result;
715 /// GetTextIcon
716 static struct ScaIconNode *GetTextIcon(struct internalScaWindowTask *iwt,
717 struct Hook *ColumnChangeHook, struct IconScanEntry *ise,
718 struct BackDropList *bdl, const struct ReadIconListData *rild)
720 Object *TextIconObj;
721 struct ScaIconNode *in = NULL;
722 BOOL isLink;
723 BPTR currentDirLock;
724 ULONG TextStyle = FS_NORMAL;
725 ULONG pos;
726 struct ReadIconListData rildClone;
728 d1(kprintf("%s/%s/%ld: Name=<%s> Type=%ld\n", __FILE__, __FUNC__, __LINE__, rild->rild_Name, rild->rild_Type));
729 d1(kprintf("%s/%s/%ld: Comment=<%s>\n", __FILE__, __FUNC__, __LINE__, rild->rild_Comment));
731 if (NULL == rild->rild_Name || '\0' == *rild->rild_Name)
732 return NULL;
734 isLink = (ST_SOFTLINK == rild->rild_Type) || (ST_LINKDIR == rild->rild_Type) ||
735 (ST_LINKFILE == rild->rild_Type) || IsSoftLink(rild->rild_Name);
737 d1(KPrintF("%s/%s/%ld: <%s> Type=%ld isLink=%ld\n", __FILE__, __FUNC__, __LINE__, rild->rild_Name, rild->rild_IconType, isLink));
738 d1(KPrintF("%s/%s/%ld: <%s> comment=<%s>\n", __FILE__, __FUNC__, __LINE__, rild->rild_Name, rild->rild_Comment));
740 d1(KPrintF("%s/%s/%ld: rild_Size64=%08lx-%08lx\n", __FILE__, __FUNC__, __LINE__, \
741 ULONG64_HIGH(rild->rild_Size64), ULONG64_LOW(rild->rild_Size64)));
743 currentDirLock = CurrentDir((BPTR)NULL);
744 CurrentDir(currentDirLock);
746 pos = IsIconName(rild->rild_Name);
748 if (IsBackDropIconTextWindow(iwt, bdl, currentDirLock, rild->rild_Name, pos))
750 return NULL;
753 if (ST_SOFTLINK == rild->rild_Type)
755 rildClone = *rild;
756 rild = &rildClone;
757 ResolveLink(&rildClone);
760 if (isLink)
761 TextStyle = CurrentPrefs.pref_LinkTextStyle;
763 // Notice:
764 // IDTA_TextMode is always IDTV_TextMode_Normal,
765 // for shadowed drawing (ICONOBJ_USERFLAGF_DrawShadowed), IDTV_TextMode_Shadow is used.
767 TextIconObj = NewObject(TextIconClass, NULL,
768 TIDTA_ReadIconListData, (IPTR) rild,
769 TIDTA_WidthArray, (IPTR) iwt->iwt_WidthArray,
770 TIDTA_TextStyle, TextStyle,
771 TIDTA_Font, (IPTR) iwt->iwt_IconFont,
772 TIDTA_TTFont, (IPTR) &iwt->iwt_IconTTFont,
773 TIDTA_IconType, (0 != pos) ? WB_TEXTICON_TOOL : (IPTR) rild->rild_IconType,
774 TIDTA_TypeNode, (IPTR) rild->rild_TypeNode,
775 TIDTA_WindowTask, (IPTR) iwt,
776 // TIDTA_IconObject, (IPTR) (ise ? ise->ise_IconObj : NULL),
777 TIDTA_SoloIcon, rild->rild_SoloIcon,
778 IDTA_InnerBottom, CurrentPrefs.pref_ImageBorders.Bottom,
779 IDTA_InnerRight, CurrentPrefs.pref_ImageBorders.Right,
780 IDTA_InnerTop, CurrentPrefs.pref_ImageBorders.Top,
781 IDTA_InnerLeft, CurrentPrefs.pref_ImageBorders.Left,
782 IDTA_Text, (IPTR) rild->rild_Name,
783 IDTA_HalfShinePen, PalettePrefs.pal_PensList[PENIDX_HSHINEPEN],
784 IDTA_HalfShadowPen, PalettePrefs.pal_PensList[PENIDX_HSHADOWPEN],
785 IDTA_FrameTypeSel, CurrentPrefs.pref_FrameTypeSel,
786 IDTA_FrameType, CurrentPrefs.pref_FrameType,
787 IDTA_TextSkip, CurrentPrefs.pref_TextSkip,
788 IDTA_MultiLineText, (IPTR) CurrentPrefs.pref_IconTextMuliLine,
789 TIDTA_TextPenFileNormal, PalettePrefs.pal_PensList[PENIDX_FILETEXT],
790 TIDTA_TextPenFileSelected, PalettePrefs.pal_PensList[PENIDX_FILETEXTSEL],
791 IDTA_TextPenShadow, PalettePrefs.pal_PensList[PENIDX_ICONTEXTSHADOWPEN],
792 IDTA_TextPenOutline, PalettePrefs.pal_PensList[PENIDX_ICONTEXTOUTLINEPEN],
793 TIDTA_TextPenDrawerNormal, PalettePrefs.pal_PensList[PENIDX_DRAWERTEXT],
794 TIDTA_TextPenDrawerSelected, PalettePrefs.pal_PensList[PENIDX_DRAWERTEXTSEL],
795 IDTA_TextMode, IDTV_TextMode_Normal,
796 IDTA_TextDrawMode, FontPrefs.fprf_TextDrawMode,
797 IDTA_TextStyle, isLink ? CurrentPrefs.pref_LinkTextStyle : FS_NORMAL,
798 IDTA_SupportedIconTypes, CurrentPrefs.pref_SupportedIconTypes,
799 TIDTA_ColumnWidthChangeHook, (IPTR) ColumnChangeHook,
800 TIDTA_SelectNameOnly, CurrentPrefs.pref_SelectTextIconName,
801 TAG_END);
803 d1(KPrintF("%s/%s/%ld: TextIconObj=%08lx Name=<%s> rild_IconType=%ld\n", __FILE__, __FUNC__, __LINE__, TextIconObj, rild->rild_Name, rild->rild_IconType));
805 if (TextIconObj)
807 if (ise)
808 ise->ise_IconObj = NULL; // IconObject will be freed when TextIconObj is disposed!
810 in = SCA_AllocIconNode(&iwt->iwt_WindowTask.wt_IconList);
812 d1(kprintf("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
813 if (in)
815 in->in_Icon = TextIconObj;
817 GetAttr(TIDTA_IconType, TextIconObj, (IPTR *) &in->in_FileType);
819 SetIconName(TextIconObj, in);
820 d1(kprintf("%s/%s/%ld: in_Name=<%s> %08lx\n", __FILE__, __FUNC__, __LINE__, in->in_Name, in->in_Name));
822 switch (rild->rild_Type)
824 case ST_FILE:
825 case ST_LINKFILE:
826 case ST_PIPEFILE:
827 in->in_Flags |= INF_File;
828 break;
829 case ST_SOFTLINK:
830 if (rild->rild_Type < 0)
831 in->in_Flags |= INF_File;
832 break;
833 default:
834 if (rild->rild_Type < 0)
835 in->in_Flags |= INF_File;
836 break;
839 in->in_Flags |= INF_TextIcon;
840 in->in_Flags |= INF_Sticky;
842 if (rild->rild_DiskWriteProtected)
843 in->in_Flags |= INF_VolumeWriteProtected;
845 in->in_SupportFlags = INF_SupportsOpen | INF_SupportsCopy | INF_SupportsInformation;
847 if (!rild->rild_DiskWriteProtected)
849 if (IsPermanentBackDropIcon(iwt, bdl, currentDirLock, rild->rild_Name))
851 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
852 in->in_SupportFlags |= INF_SupportsPutAway;
853 in->in_SupportFlags &= ~INF_SupportsLeaveOut;
855 else
857 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
858 in->in_SupportFlags &= ~INF_SupportsPutAway;
859 in->in_SupportFlags |= INF_SupportsLeaveOut;
863 if (0 != pos)
864 in->in_SupportFlags &= ~(INF_SupportsSnapshot | INF_SupportsUnSnapshot | INF_SupportsLeaveOut);
866 if (!(rild->rild_Protection & FIBF_DELETE))
867 in->in_SupportFlags |= INF_SupportsDelete;
868 if (!(rild->rild_Protection & FIBF_WRITE))
869 in->in_SupportFlags |= INF_SupportsRename;
871 d1(kprintf("%s/%s/%ld: in=<%s> supportFlags=%08lx pos=%lu\n", \
872 __FILE__, __FUNC__, __LINE__, GetIconName(in), in->in_SupportFlags, pos));
874 in->in_FileDateStamp = rild->rild_DateStamp;
875 in->in_FileSize = ULONG64_LOW(rild->rild_Size64);
877 DateStamp(&in->in_DateStamp);
879 d1(kprintf("%s/%s/%ld: <%s> Protection=%08lx SupportFlags=%08lx\n", \
880 __FILE__, __FUNC__, __LINE__, rild->rild_Name, rild->rild_Protection, in->in_SupportFlags));
882 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
884 DoMethod(iwt->iwt_WindowTask.mt_MainObject, SCCM_IconWin_LayoutIcon,
885 in->in_Icon, IOLAYOUTF_NormalImage | IOLAYOUTF_SelectedImage);
889 d1(kprintf("%s/%s/%ld: in=%08lx\n", __FILE__, __FUNC__, __LINE__, in));
891 return in;
895 /// ResolveLink
896 static void ResolveLink(struct ReadIconListData *rild)
898 BPTR LinkLock;
899 T_ExamineData *fib = NULL;
901 do {
902 LinkLock = Lock(rild->rild_Name, ACCESS_READ);
903 d1(kprintf("%s/%s/%ld: LinkLock=%08lx\n", __FILE__, __FUNC__, __LINE__, LinkLock));
904 if ((BPTR)NULL == LinkLock)
905 break;
907 debugLock_d1(LinkLock);
909 if (!ScalosExamineBegin(&fib))
910 break;
912 d1(kprintf("%s/%s/%ld: fib=%08lx\n", __FILE__, __FUNC__, __LINE__, fib));
914 if (!ScalosExamineLock(LinkLock, &fib))
915 break;
917 rild->rild_Type = ScalosExamineGetDirEntryType(fib);
918 rild->rild_Size64 = ScalosExamineGetSize(fib);
919 rild->rild_Protection = ScalosExamineGetProtection(fib);
920 rild->rild_DateStamp = *ScalosExamineGetDate(fib);
921 stccpy(rild->rild_Comment, ScalosExamineGetComment(fib), sizeof(rild->rild_Comment));
923 d1(kprintf("%s/%s/%ld: Name=<%s> Type=%ld\n", __FILE__, __FUNC__, __LINE__, \
924 rild->rild_Name, rild->rild_Type));
925 } while (0);
927 ScalosExamineEnd(&fib);
928 if (LinkLock)
929 UnLock(LinkLock);
933 /// ReExamine
934 #if 0
935 static LONG ReExamine(struct ReadIconListData *rild)
937 T_ExamineData *fib;
938 BPTR fLock = (BPTR)NULL;
939 BOOL Result = RETURN_OK;
941 do {
942 if (!ScalosExamineBegin(&fib))
944 Result = IoErr();
945 break;
948 fLock = Lock(rild->rild_Name, ACCESS_READ);
949 if ((BPTR)NULL == fLock)
951 Result = IoErr();
952 break;
955 if (!ScalosExamineLock(fLock, &fib))
957 Result = IoErr();
958 break;
961 rild->rild_Type = ScalosExamineGetDirEntryType(fib);
962 rild->rild_Protection = ScalosExamineGetProtection(fib);
963 rild->rild_Size64 = ScalosExamineGetSize(fib);
964 rild->rild_DateStamp = *ScalosExamineGetDate(fib);
966 stccpy(rild->rild_Comment, ScalosExamineGetComment(fib), sizeof(rild->rild_Comment));
967 stccpy(rild->rild_Name, ScalosExamineGetName(fib), sizeof(rild->rild_Name));
968 } while (0);
970 ScalosExamineEnd(&fib);
971 if (fLock)
972 UnLock(fLock);
974 return Result;
976 #endif