6 #include <exec/types.h>
7 #include <graphics/gels.h>
8 #include <graphics/rastport.h>
9 #include <intuition/classes.h>
10 #include <intuition/classusr.h>
11 #include <utility/hooks.h>
12 #include <intuition/gadgetclass.h>
13 #include <workbench/workbench.h>
14 #include <workbench/startup.h>
15 #include <dos/dostags.h>
16 #include <dos/datetime.h>
20 #include <proto/dos.h>
21 #include <proto/exec.h>
22 #include <proto/layers.h>
23 #include <proto/intuition.h>
24 #include <proto/graphics.h>
25 #include <proto/utility.h>
26 #include <proto/iconobject.h>
28 #include <proto/scalos.h>
30 #include <clib/alib_protos.h>
33 #include <datatypes/iconobject.h>
34 #include <scalos/scalos.h>
40 #include "scalos_structures.h"
41 #include "functions.h"
42 #include "Variables.h"
44 //----------------------------------------------------------------------------
46 // local data structures
48 //----------------------------------------------------------------------------
52 // remapping of SCA_OpenIconWindow() tags to ws_Flags values
53 static const struct TagItem FlagMapTable
[] =
55 { SCA_Iconify
, WSV_FlagF_Iconify
},
56 { SCA_NoStatusBar
, WSV_FlagF_NoStatusBar
},
57 { SCA_NoActivateWindow
, WSV_FlagF_NoActivateWindow
},
58 { SCA_BrowserMode
, WSV_FlagF_BrowserMode
},
59 { SCA_CheckOverlappingIcons
, WSV_FlagF_CheckOverlappingIcons
},
60 { SCA_DdPopupWindow
, WSV_FlagF_DdPopupWindow
},
64 // remapping of SCA_OpenIconWindow() tags to ws_MoreFlags values
65 static const struct TagItem MoreFlagMapTable
[] =
67 { SCA_NoControlBar
, WSV_MoreFlagF_NoControlBar
},
71 //----------------------------------------------------------------------------
75 static Object
*ReadDeviceIconObject(CONST_STRPTR Path
);
76 static Object
*FindIconInScalosWindows(BPTR Lock
, CONST_STRPTR IconName
,
77 struct ScaWindowStruct
**wsLocked
, BOOL
*windowListLocked
);
78 static Object
*FindIconInDeviceWindow(CONST_STRPTR IconName
,
79 struct ScaWindowStruct
**wsLocked
, BOOL
*windowListLocked
);
80 static BOOL
MatchDeviceIcon(CONST_STRPTR SearchPath
, struct ScaIconNode
*in
);
81 static BOOL
MatchPath(CONST_STRPTR VolPath
, CONST_STRPTR DevIconPath
);
83 //----------------------------------------------------------------------------
85 // implementation of SCA_OpenIconWindow()
87 LIBFUNC_P2(BOOL
, sca_OpenIconWindow
,
88 A0
, struct TagItem
*, TagList
,
89 A6
, struct ScalosBase
*, ScalosBase
, 0)
91 Object
*IconObj
= NULL
;
92 Object
*allocIconObj
= NULL
;
93 struct MsgPort
*allocMsgPort
= NULL
;
94 struct ScaWindowStruct
*wsNew
= NULL
;
95 struct ScaWindowStruct
*dummyList
= NULL
;
96 struct SM_StartWindow
*msgStart
= NULL
;
98 struct ScaWindowStruct
*wsIconListLocked
= NULL
;
99 BOOL WindowListLocked
= FALSE
;
103 d1(KPrintF("%s/%s/%ld: START\n", __FILE__
, __FUNC__
, __LINE__
));
106 STATIC_PATCHFUNC(WindowTask
)
107 struct ScaWindowStruct
*ws
;
108 struct ScaWindowStruct
**ReturnWs
;
109 struct IBox
*WindowRect
;
110 struct ScaIconNode
*in
;
111 struct MsgPort
*ReplyPort
;
119 ReturnWs
= (struct ScaWindowStruct
**) GetTagData(SCA_WindowStruct
, (IPTR
)NULL
, TagList
);
120 d1(KPrintF("%s/%s/%ld: ReturnWs=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, ReturnWs
));
122 in
= (struct ScaIconNode
*) GetTagData(SCA_IconNode
, (IPTR
)NULL
, TagList
);
124 IconObj
= in
->in_Icon
;
126 IconObj
= (Object
*) GetTagData(SCA_IconObject
, (IPTR
) IconObj
, TagList
);
128 d1(KPrintF("%s/%s/%ld: in=%08lx IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, in
, IconObj
));
130 WindowFlags
= GetTagData(SCA_Flags
, 0, TagList
);
132 ReplyPort
= (struct MsgPort
*) GetTagData(SCA_MessagePort
, (IPTR
)NULL
, TagList
);
133 d1(KPrintF("%s/%s/%ld: ReplyPort=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, ReplyPort
));
134 if (NULL
== ReplyPort
)
135 ReplyPort
= allocMsgPort
= CreateMsgPort();
136 if (NULL
== ReplyPort
)
139 wsNew
= (struct ScaWindowStruct
*) SCA_AllocStdNode((struct ScalosNodeList
*)(APTR
) &dummyList
, NTYP_WindowStruct
);
143 wsNew
->ws_Left
= CurrentPrefs
.pref_DefWindowBox
.Left
;
144 wsNew
->ws_Top
= CurrentPrefs
.pref_DefWindowBox
.Top
;
145 wsNew
->ws_Width
= CurrentPrefs
.pref_DefWindowBox
.Width
;
146 wsNew
->ws_Height
= CurrentPrefs
.pref_DefWindowBox
.Height
;
148 wsNew
->ws_WindowOpacityActive
= CurrentPrefs
.pref_ActiveWindowTransparency
;
149 wsNew
->ws_WindowOpacityInactive
= CurrentPrefs
.pref_InactiveWindowTransparency
;
151 wsNew
->ws_IconSizeConstraints
= CurrentPrefs
.pref_IconSizeConstraints
;
152 wsNew
->ws_IconScaleFactor
= CurrentPrefs
.pref_IconScaleFactor
;
154 Path
= (STRPTR
) GetTagData(SCA_Path
, (IPTR
)NULL
, TagList
);
155 d1(KPrintF("%s/%s/%ld: Path=%08lx <%s>\n", __FILE__
, __FUNC__
, __LINE__
, Path
, Path
? Path
: (STRPTR
) ""));
160 wsNew
->ws_Lock
= Lock(Path
, ACCESS_READ
);
161 debugLock_d1(wsNew
->ws_Lock
);
162 if ((BPTR
)NULL
== wsNew
->ws_Lock
)
165 wsNew
->ws_Name
= GetWsNameFromLock(wsNew
->ws_Lock
);
166 d1(KPrintF("%s/%s/%ld: ws_Name=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Name
));
168 IconObj
= FunctionsFindIconObjectForPath(Path
, &WindowListLocked
,
169 &wsIconListLocked
, &allocIconObj
);
171 parentLock
= ParentDir(wsNew
->ws_Lock
);
172 debugLock_d1(parentLock
);
179 // this is a root window
180 wsNew
->ws_Flags
|= WSV_FlagF_RootWindow
;
184 d1(KPrintF("%s/%s/%ld: IconObj=%08lx ws_Name=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
, wsNew
->ws_Name
));
186 WindowRect
= (struct IBox
*) GetTagData(SCA_WindowRect
, (IPTR
)NULL
, TagList
);
187 d1(KPrintF("%s/%s/%ld: WindowRect=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, WindowRect
));
188 if (NULL
== WindowRect
)
189 GetAttr(IDTA_WindowRect
, IconObj
, (APTR
) &WindowRect
);
191 d1(kprintf("%s/%s/%ld: WindowRect=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, WindowRect
));
194 wsNew
->ws_Left
= WindowRect
->Left
;
195 wsNew
->ws_Top
= WindowRect
->Top
;
196 wsNew
->ws_Width
= WindowRect
->Width
;
197 wsNew
->ws_Height
= WindowRect
->Height
;
200 wsNew
->ws_xoffset
= wsNew
->ws_yoffset
= 0;
201 wsNew
->ws_Viewmodes
= GetTagData(SCA_ViewModes
, IDTV_ViewModes_Default
, TagList
);
203 wsNew
->ws_ThumbnailView
= CurrentPrefs
.pref_ShowThumbnails
;
205 // determine default pattern number
206 if (IsViewByIcon(wsNew
->ws_Viewmodes
))
207 wsNew
->ws_PatternNumber
= PATTERNNR_IconWindowDefault
; // default icon window pattern no.
209 wsNew
->ws_PatternNumber
= PATTERNNR_TextWindowDefault
; // default text window pattern no.
211 wsNew
->ws_ThumbnailsLifetimeDays
= CurrentPrefs
.pref_ThumbnailMaxAge
;
213 wsNew
->ws_Flags
= PackBoolTags(wsNew
->ws_Flags
, TagList
, (struct TagItem
*) FlagMapTable
);
214 wsNew
->ws_MoreFlags
= PackBoolTags(wsNew
->ws_MoreFlags
, TagList
, (struct TagItem
*) MoreFlagMapTable
);
216 d1(KPrintF("%s/%s/%ld: ws_Flags=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Flags
));
220 struct IconWindowProperties iwp
;
222 iwp
.iwp_SortOrder
= wsNew
->ws_SortOrder
;
223 iwp
.iwp_ThumbnailView
= wsNew
->ws_ThumbnailView
;
224 iwp
.iwp_ThumbnailsLifetimeDays
= wsNew
->ws_ThumbnailsLifetimeDays
;
225 iwp
.iwp_ShowAll
= wsNew
->ws_ViewAll
;
226 iwp
.iwp_Viewmodes
= wsNew
->ws_Viewmodes
;
227 iwp
.iwp_PatternNumber
= wsNew
->ws_PatternNumber
;
228 iwp
.iwp_CheckOverlap
= (wsNew
->ws_Flags
& WSV_FlagF_CheckOverlappingIcons
) != 0;
229 iwp
.iwp_XOffset
= iwp
.iwp_YOffset
= 0;
230 iwp
.iwp_OpacityActive
= wsNew
->ws_WindowOpacityActive
;
231 iwp
.iwp_OpacityInactive
= wsNew
->ws_WindowOpacityInactive
;
232 iwp
.iwp_IconSizeConstraints
= wsNew
->ws_IconSizeConstraints
;
233 iwp
.iwp_IconScaleFactor
= wsNew
->ws_IconScaleFactor
;
235 FunctionsGetSettingsFromIconObject(&iwp
, IconObj
);
237 wsNew
->ws_SortOrder
= iwp
.iwp_SortOrder
;
238 wsNew
->ws_ViewAll
= iwp
.iwp_ShowAll
;
239 wsNew
->ws_ThumbnailsLifetimeDays
= iwp
.iwp_ThumbnailsLifetimeDays
;
240 wsNew
->ws_PatternNumber
= iwp
.iwp_PatternNumber
;
241 wsNew
->ws_Viewmodes
= iwp
.iwp_Viewmodes
;
242 wsNew
->ws_ThumbnailView
= iwp
.iwp_ThumbnailView
;
243 wsNew
->ws_WindowOpacityActive
= iwp
.iwp_OpacityActive
;
244 wsNew
->ws_WindowOpacityInactive
= iwp
.iwp_OpacityInactive
;
245 wsNew
->ws_IconSizeConstraints
= iwp
.iwp_IconSizeConstraints
;
246 wsNew
->ws_IconScaleFactor
= iwp
.iwp_IconScaleFactor
;
248 if (iwp
.iwp_NoStatusBar
)
249 wsNew
->ws_Flags
|= WSV_FlagF_NoStatusBar
;
250 if (iwp
.iwp_NoControlBar
)
251 wsNew
->ws_MoreFlags
|= WSV_MoreFlagF_NoControlBar
;
252 if (iwp
.iwp_BrowserMode
)
253 wsNew
->ws_Flags
|= WSV_FlagF_BrowserMode
;
255 if (iwp
.iwp_CheckOverlap
)
256 wsNew
->ws_Flags
|= WSV_FlagF_CheckOverlappingIcons
;
258 wsNew
->ws_Flags
&= ~WSV_FlagF_CheckOverlappingIcons
;
261 // SCA_ShowAllMode and SCA_ShowAllFiles tags explicitly given
262 // take precedence over window/icon settings
263 wsNew
->ws_ViewAll
= GetTagData(SCA_ShowAllMode
, wsNew
->ws_ViewAll
, TagList
);
264 if (NULL
== FindTagItem(SCA_ShowAllMode
, TagList
)
265 && FindTagItem(SCA_ShowAllFiles
, TagList
))
267 wsNew
->ws_ViewAll
= GetTagData(SCA_ShowAllFiles
, FALSE
, TagList
)
268 ? DDFLAGS_SHOWALL
: DDFLAGS_SHOWDEFAULT
;
271 if (IsShowAll(wsNew
))
272 wsNew
->ws_Flags
|= WSV_FlagF_ShowAllFiles
;
274 wsNew
->ws_Flags
&= ~WSV_FlagF_ShowAllFiles
;
276 wsNew
->ws_xoffset
= GetTagData(SCA_XOffset
, wsNew
->ws_xoffset
, TagList
);
277 wsNew
->ws_yoffset
= GetTagData(SCA_YOffset
, wsNew
->ws_yoffset
, TagList
);
279 wsNew
->ws_PatternNumber
= GetTagData(SCA_PatternNumber
, wsNew
->ws_PatternNumber
, TagList
);
280 wsNew
->ws_PatternNode
= GetPatternNode(wsNew
->ws_PatternNumber
, NULL
);
282 wsNew
->ws_Viewmodes
= GetTagData(SCA_ViewModes
, wsNew
->ws_Viewmodes
, TagList
);
284 wsNew
->ws_WindowOpacityActive
= GetTagData(SCA_TransparencyActive
, wsNew
->ws_WindowOpacityActive
, TagList
);
285 wsNew
->ws_WindowOpacityInactive
= GetTagData(SCA_TransparencyInactive
, wsNew
->ws_WindowOpacityInactive
, TagList
);
287 d1(kprintf("%s/%s/%ld: ws_ViewModes=%ld\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Viewmodes
));
288 d1(KPrintF("%s/%s/%ld: ws_Flags=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Flags
));
290 if (IsViewByIcon(wsNew
->ws_Viewmodes
))
291 wsNew
->ms_ClassName
= (STRPTR
) "IconWindow.sca";
293 wsNew
->ms_ClassName
= (STRPTR
) "TextWindow.sca";
295 wsNew
->ms_ClassName
= (STRPTR
) GetTagData(SCA_ClassName
, (IPTR
) wsNew
->ms_ClassName
, TagList
);
297 wsNew
->ms_Class
= (Class
*) GetTagData(SCA_Class
, (IPTR
)NULL
, TagList
);
299 wsNew
->ms_ClassName
= NULL
;
301 if ((BPTR
)NULL
== wsNew
->ws_Lock
)
303 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
307 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
314 if (NULL
== in
->in_Name
)
317 wsNew
->ws_Name
= AllocCopyString(in
->in_Name
);
318 if (NULL
== wsNew
->ws_Name
)
321 oldDir
= CurrentDir(in
->in_Lock
);
323 wsNew
->ws_Lock
= Lock(in
->in_Name
, ACCESS_READ
);
327 if ((BPTR
)NULL
== wsNew
->ws_Lock
)
332 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
334 if (in
->in_DeviceIcon
)
336 wsNew
->ws_Lock
= DiskInfoLock(in
);
337 debugLock_d1(wsNew
->ws_Lock
);
338 if ((BPTR
)NULL
== wsNew
->ws_Lock
)
341 wsNew
->ws_Name
= AllocCopyString(in
->in_DeviceIcon
->di_Volume
);
342 d1(kprintf("%s/%s/%ld: ws_Name=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Name
));
343 if (NULL
== wsNew
->ws_Name
)
346 StripTrailingColon(wsNew
->ws_Name
);
348 wsNew
->ws_Flags
|= WSV_FlagF_RootWindow
;
353 if (NULL
== in
->in_Name
)
356 wsNew
->ws_Lock
= Lock(in
->in_Name
, ACCESS_READ
);
357 debugLock_d1(wsNew
->ws_Lock
);
358 if ((BPTR
)NULL
== wsNew
->ws_Lock
)
361 wsNew
->ws_Name
= AllocCopyString(in
->in_Name
);
362 d1(kprintf("%s/%s/%ld: ws_Name=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Name
));
363 if (NULL
== wsNew
->ws_Name
)
371 STRPTR iconName
= NULL
;
374 d1(kprintf("%s/%s/%ld: IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
));
379 GetAttr(DTA_Name
, IconObj
, (APTR
) &iconName
);
380 if (NULL
== iconName
)
382 if ('\0' == *iconName
)
385 d1(kprintf("%s/%s/%ld: iconName=<%s> \n", __FILE__
, __FUNC__
, __LINE__
, iconName
));
387 GetAttr(IDTA_Type
, IconObj
, &IconType
);
389 if (':' == iconName
[strlen(iconName
) - 1])
392 d1(kprintf("%s/%s/%ld: IconType=%ld\n", __FILE__
, __FUNC__
, __LINE__
, IconType
));
394 if (WBDISK
== IconType
)
396 wsNew
->ws_Name
= AllocCopyString(iconName
);
398 if (NULL
== wsNew
->ws_Name
)
401 StripTrailingColon(wsNew
->ws_Name
);
403 wsNew
->ws_Flags
|= WSV_FlagF_RootWindow
;
407 wsNew
->ws_Name
= AllocCopyString(FilePart(iconName
));
408 if (NULL
== wsNew
->ws_Name
)
412 wsNew
->ws_Lock
= Lock(iconName
, ACCESS_READ
);
413 debugLock_d1(wsNew
->ws_Lock
);
414 if ((BPTR
)NULL
== wsNew
->ws_Lock
)
419 d1(kprintf("%s/%s/%ld: ws_Name=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Name
));
421 if (wsIconListLocked
)
423 d1(kprintf("\n" "%s/%s/%ld: wsLocked=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsIconListLocked
));
424 ScalosReleaseSemaphore(wsIconListLocked
->ws_WindowTask
->wt_IconSemaphore
);
425 wsIconListLocked
= NULL
;
427 if (WindowListLocked
)
429 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
430 SCA_UnLockWindowList();
431 WindowListLocked
= FALSE
;
434 if (wsNew
->ws_Flags
& WSV_FlagF_RootWindow
)
435 clp
= CurrentPrefs
.pref_MainWindowTitle
;
437 clp
= CurrentPrefs
.pref_StandardWindowTitle
;
439 wsNew
->ws_Title
= AllocCopyString((STRPTR
) GetTagData(SCA_WindowTitle
, (IPTR
) clp
, TagList
));
440 if (NULL
== wsNew
->ws_Title
)
444 SCA_LockWindowList(SCA_LockWindowList_Shared
);
446 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
447 debugLock_d1(wsNew
->ws_Lock
);
449 for (ws
=winlist
.wl_WindowStruct
; !Found
&& ws
; ws
= (struct ScaWindowStruct
*) ws
->ws_Node
.mln_Succ
)
451 if (ws
!= wsNew
&& ws
->ws_Lock
&&
452 LOCK_SAME
== ScaSameLock(wsNew
->ws_Lock
, ws
->ws_Lock
))
456 if (ws
->ws_Flags
& WSV_FlagF_Iconify
)
458 struct ScalosMessage
*msg
= SCA_AllocMessage(MTYP_UnIconify
, 0);
462 d1(kprintf("%s/%s/%ld: PutMsg iwt=%08lx Msg=%08lx \n", __FILE__
, __FUNC__
, __LINE__
, ws
->ws_WindowTask
, &msg
->sm_Message
));
463 PutMsg(ws
->ws_MessagePort
, &msg
->sm_Message
);
470 ActivateWindow(ws
->ws_Window
);
471 WindowToFront(ws
->ws_Window
);
477 d1(kprintf("%s/%s/%ld: Found=%ld\n", __FILE__
, __FUNC__
, __LINE__
, Found
));
479 SCA_UnLockWindowList();
483 // requested Scalos window for drawer is already open
488 msgStart
= (struct SM_StartWindow
*) SCA_AllocMessage(MTYP_StartWindow
, 0);
489 d1(kprintf("%s/%s/%ld: msgStart=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, msgStart
));
490 if (NULL
== msgStart
)
493 msgStart
->ScalosMessage
.sm_Message
.mn_ReplyPort
= ReplyPort
;
494 msgStart
->WindowStruct
= wsNew
;
496 length
= 50 + strlen(wsNew
->ws_Name
);
498 wsNew
->ws_WindowTaskName
= ScalosAlloc(length
);
499 if (wsNew
->ws_WindowTaskName
)
501 TaskName
= wsNew
->ws_WindowTaskName
;
503 ScaFormatStringMaxLength(TaskName
, length
,
504 "Scalos_Window_Task <%s>", (IPTR
) wsNew
->ws_Name
);
508 TaskName
= (STRPTR
) "Scalos_Window_Task";
511 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
513 wsNew
->ws_Task
= CreateNewProcTags(
515 NP_StackSize
, CurrentPrefs
.pref_DefaultStackSize
,
518 NP_CommandName
, (IPTR
) TaskName
,
519 NP_Name
, (IPTR
) TaskName
,
520 NP_Entry
, (IPTR
) PATCH_NEWFUNC(WindowTask
),
521 NP_CurrentDir
, wsNew
->ws_Lock
,
522 NP_Path
, DupWBPathList(),
525 d1(kprintf("%s/%s/%ld: ws_Task=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsNew
->ws_Task
));
526 if (NULL
== wsNew
->ws_Task
)
529 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
531 PutMsg(&wsNew
->ws_Task
->pr_MsgPort
, &msgStart
->ScalosMessage
.sm_Message
);
532 msgStart
= NULL
; // no SCA_FreeMessage()
534 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
536 if (WindowFlags
& SCAF_OpenWindow_ScalosPort
)
538 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
539 WaitReply(ReplyPort
, NULL
, MTYP_StartWindow
);
543 BOOL Finished
= FALSE
;
544 struct ScalosMessage
*ReplyMsg
;
549 ReplyMsg
= (struct ScalosMessage
*) GetMsg(ReplyPort
);
551 d1(kprintf("%s/%s/%ld: MessageType=%ld\n", __FILE__
, __FUNC__
, __LINE__
, ReplyMsg
->sm_MessageType
));
553 if (ReplyMsg
&& ID_IMSG
== ReplyMsg
->sm_Signature
554 && MTYP_StartWindow
== ReplyMsg
->sm_MessageType
)
556 SCA_FreeMessage(ReplyMsg
);
562 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
567 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
573 if (wsIconListLocked
)
575 d1(kprintf("\n" "%s/%s/%ld: wsLocked=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, wsIconListLocked
));
576 ScalosReleaseSemaphore(wsIconListLocked
->ws_WindowTask
->wt_IconSemaphore
);
578 if (WindowListLocked
)
580 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
581 SCA_UnLockWindowList();
585 SCA_FreeMessage(&msgStart
->ScalosMessage
);
587 DisposeIconObject(allocIconObj
);
591 UnLock(wsNew
->ws_Lock
);
593 FreeCopyString(wsNew
->ws_Name
);
595 SCA_FreeAllNodes((struct ScalosNodeList
*)(APTR
) &dummyList
);
598 DeleteMsgPort(allocMsgPort
);
600 d1(kprintf("%s/%s/%ld: Success=%ld\n", __FILE__
, __FUNC__
, __LINE__
, Success
));
607 BPTR
DiskInfoLock(const struct ScaIconNode
*in
)
609 return Lock(in
->in_DeviceIcon
->di_Device
, ACCESS_READ
);
613 static Object
*ReadDeviceIconObject(CONST_STRPTR Path
)
615 Object
*IconObj
= NULL
;
617 struct DosList
*dList
;
620 internalName
= AllocPathBuffer();
621 if (NULL
== internalName
)
624 stccpy(internalName
, Path
, Max_PathLen
);
625 StripTrailingColon(internalName
);
627 d1(kprintf("%s/%s/%ld: Path=<%s> internalName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, Path
, internalName
));
629 dList
= LockDosList(LDF_ASSIGNS
| LDF_DEVICES
| LDF_VOLUMES
| LDF_READ
);
630 if ((dList
= FindDosEntry(dList
, internalName
, LDF_ASSIGNS
| LDF_DEVICES
| LDF_VOLUMES
)))
632 // First, try to get "VOLNAME:disk" icon
634 d1(kprintf("%s/%s/%ld: FOUND internalName=<%s> Type=%ld\n", __FILE__
, __FUNC__
, __LINE__
, internalName
, dList
->dol_Type
));
636 stccpy(internalName
, Path
, Max_PathLen
- 5);
637 AddPart(internalName
, "disk", Max_PathLen
);
639 d1(kprintf("%s/%s/%ld: internalName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, internalName
));
641 IconObj
= NewIconObjectTags(internalName
,
642 IDTA_SizeConstraints
, (IPTR
) &CurrentPrefs
.pref_IconSizeConstraints
,
643 IDTA_ScalePercentage
, CurrentPrefs
.pref_IconScaleFactor
,
645 d1(kprintf("%s/%s/%ld: IconObj=%08lx internalName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
, internalName
));
647 if (NULL
== IconObj
&& CurrentPrefs
.pref_DefIconPath
)
649 CONST_STRPTR DeviceName
= NULL
;
651 switch (dList
->dol_Type
)
656 IconObj
= NewIconObjectTags(Path
,
657 IDTA_SizeConstraints
, (IPTR
) &CurrentPrefs
.pref_IconSizeConstraints
,
658 IDTA_ScalePercentage
, CurrentPrefs
.pref_IconScaleFactor
,
669 // no "VOLNAME:disk" icon found
670 // try "ENV:sys/def_DEVNAME"
672 // get Device name from volume name, e.g. "RAM" from "Ram Disk"
673 struct Task
*SigTask
= (struct Task
*) dList
->dol_Task
->mp_SigTask
;
676 DeviceName
= SigTask
->tc_Node
.ln_Name
;
681 if (NULL
== IconObj
&& DeviceName
)
683 stccpy(internalName
, CurrentPrefs
.pref_DefIconPath
, Max_PathLen
);
685 AddPart(internalName
, "def_", Max_PathLen
- 1);
687 SafeStrCat(internalName
, DeviceName
, Max_PathLen
- 1);
688 StripTrailingColon(internalName
);
689 SafeStrCat(internalName
, "disk", Max_PathLen
- 1);
691 // if XXX is our device name, then
692 // look for "ENVARC:sys/def_XXXdisk"
694 d1(kprintf("%s/%s/%ld: DeviceName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, internalName
));
696 IconObj
= NewIconObjectTags(internalName
,
697 IDTA_SizeConstraints
, (IPTR
) &CurrentPrefs
.pref_IconSizeConstraints
,
698 IDTA_ScalePercentage
, CurrentPrefs
.pref_IconScaleFactor
,
704 UnLockDosList(LDF_ASSIGNS
| LDF_VOLUMES
| LDF_DEVICES
| LDF_READ
);
708 FreePathBuffer(internalName
);
714 static Object
*FindIconInScalosWindows(BPTR Lock
, CONST_STRPTR IconName
,
715 struct ScaWindowStruct
**wsLocked
, BOOL
*windowListLocked
)
717 struct ScaWindowStruct
*ws
;
720 *windowListLocked
= FALSE
;
722 SCA_LockWindowList(SCA_LockWindowList_Shared
);
724 for (ws
=winlist
.wl_WindowStruct
; ws
; ws
= (struct ScaWindowStruct
*) ws
->ws_Node
.mln_Succ
)
726 d1(kprintf("\n" "%s/%s/%ld: ws=%08lx <%s>\n", __FILE__
, __FUNC__
, __LINE__
, ws
, ws
->ws_Name
));
727 debugLock_d1(ws
->ws_Lock
);
729 if (LOCK_SAME
== SameLock(ws
->ws_Lock
, Lock
))
731 struct internalScaWindowTask
*iwt
= (struct internalScaWindowTask
*) ws
->ws_WindowTask
;
732 struct ScaIconNode
*in
;
734 d1(kprintf("\n" "%s/%s/%ld: found ws=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, ws
));
736 ScalosLockIconListShared(iwt
);
738 for (in
= iwt
->iwt_WindowTask
.wt_IconList
; in
; in
= (struct ScaIconNode
*) in
->in_Node
.mln_Succ
)
740 CONST_STRPTR Name
= GetIconName(in
);
742 if (Name
&& 0 == Stricmp((STRPTR
) IconName
, (STRPTR
) Name
))
745 *windowListLocked
= TRUE
;
747 d1(kprintf("\n" "%s/%s/%ld: ws=%08lx in=%08lx <%s> Icon=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, ws
, in
, Name
, in
->in_Icon
));
753 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
755 ScalosUnLockIconList(iwt
);
760 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
762 SCA_UnLockWindowList();
764 d1(kprintf("\n" "%s/%s/%ld: not found\n", __FILE__
, __FUNC__
, __LINE__
));
770 static Object
*FindIconInDeviceWindow(CONST_STRPTR IconName
,
771 struct ScaWindowStruct
**wsLocked
, BOOL
*windowListLocked
)
773 struct internalScaWindowTask
*iwt
;
774 struct ScaIconNode
*in
;
776 *windowListLocked
= FALSE
;
778 d1(KPrintF("\n" "%s/%s/%ld: IconName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, IconName
));
779 d1(KPrintF("\n" "%s/%s/%ld: ii_MainWindowStruct=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, iInfos
.xii_iinfos
.ii_MainWindowStruct
));
781 while (NULL
== iInfos
.xii_iinfos
.ii_MainWindowStruct
782 || NULL
== iInfos
.xii_iinfos
.ii_MainWindowStruct
->ws_WindowTask
)
784 d1(KPrintF("\n" "%s/%s/%ld: Wait for ii_MainWindowStruct=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, iInfos
.xii_iinfos
.ii_MainWindowStruct
));
787 iwt
= (struct internalScaWindowTask
*) iInfos
.xii_iinfos
.ii_MainWindowStruct
->ws_WindowTask
;
789 d1(KPrintF("\n" "%s/%s/%ld: wt_IconSemaphore=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, iwt
->iwt_WindowTask
.wt_IconSemaphore
));
791 while (NULL
== iwt
->iwt_WindowTask
.wt_IconSemaphore
&& !iwt
->iwt_CloseWindow
)
793 d1(KPrintF("\n" "%s/%s/%ld: Wait for wt_IconSemaphore=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, iwt
->iwt_WindowTask
.wt_IconSemaphore
));
797 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
798 ScalosLockIconListShared(iwt
);
800 *wsLocked
= iwt
->iwt_WindowTask
.mt_WindowStruct
;
802 for (in
= iwt
->iwt_WindowTask
.wt_IconList
; in
; in
= (struct ScaIconNode
*) in
->in_Node
.mln_Succ
)
804 if (MatchDeviceIcon(IconName
, in
))
806 d1(KPrintF("\n" "%s/%s/%ld: iwt=%08lx in=%08lx <%s> Icon=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, iwt
, in
, IconName
, in
->in_Icon
));
811 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
813 ScalosUnLockIconList(iwt
);
817 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
818 d1(kprintf("\n" "%s/%s/%ld: not found\n", __FILE__
, __FUNC__
, __LINE__
));
823 // ----------------------------------------------------------
825 STRPTR
GetWsNameFromLock(BPTR WsLock
)
828 STRPTR WsName
= NULL
;
833 allocPath
= AllocPathBuffer();
834 if (NULL
== allocPath
)
837 if (!NameFromLock(WsLock
, allocPath
, Max_PathLen
- 1))
840 lp
= FilePart(allocPath
);
841 d1(kprintf("%s/%s/%ld: FilePart=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, lp
));
844 WsName
= AllocCopyString(lp
);
850 WsName
= AllocCopyString(allocPath
);
854 StripTrailingColon(WsName
);
859 FreePathBuffer(allocPath
);
864 // ----------------------------------------------------------
866 static BOOL
MatchDeviceIcon(CONST_STRPTR SearchPath
, struct ScaIconNode
*in
)
868 if (NULL
== in
->in_DeviceIcon
)
871 return (BOOL
) (MatchPath(SearchPath
, in
->in_DeviceIcon
->di_Volume
)
872 || MatchPath(SearchPath
, in
->in_DeviceIcon
->di_Device
)
873 || MatchPath(SearchPath
, GetIconName(in
)));
877 static BOOL
MatchPath(CONST_STRPTR VolPath
, CONST_STRPTR DevIconPath
)
883 size_t len
= strlen(VolPath
);
884 size_t diLen
= strlen(DevIconPath
);
886 if (':' == DevIconPath
[diLen
- 1])
887 Match
= 0 == Stricmp(VolPath
, DevIconPath
);
889 Match
= (diLen
+ 1 == len
) && 0 == Strnicmp(VolPath
, DevIconPath
, len
);
895 // ----------------------------------------------------------
897 Object
*FunctionsFindIconObjectForPath(CONST_STRPTR Path
, BOOL
*WindowListLocked
,
898 struct ScaWindowStruct
**wsIconListLocked
, Object
**allocIconObj
)
900 Object
*IconObj
= NULL
;
902 BPTR parentLock
= BNULL
;
903 BPTR oldDir
= NOT_A_LOCK
;
904 STRPTR FullPath
= NULL
;
907 d1(KPrintF("%s/%s/%ld: START Path=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, Path
));
909 pLock
= Lock(Path
, ACCESS_READ
);
914 FullPath
= AllocPathBuffer();
915 if (NULL
== FullPath
)
918 if (!NameFromLock(pLock
, FullPath
, Max_PathLen
- 1))
921 d1(KPrintF("%s/%s/%ld: FullPath=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, FullPath
));
923 oldDir
= CurrentDir(pLock
);
924 parentLock
= ParentDir(pLock
);
925 debugLock_d1(parentLock
);
928 d1(KPrintF("%s/%s/%ld: Drawer window\n", __FILE__
, __FUNC__
, __LINE__
));
930 IconObj
= FindIconInScalosWindows(parentLock
, FullPath
,
931 wsIconListLocked
, WindowListLocked
);
933 d1(KPrintF("%s/%s/%ld: IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
));
936 CurrentDir(parentLock
);
938 IconObj
= *allocIconObj
= NewIconObjectTags(FullPath
,
939 IDTA_SizeConstraints
, (IPTR
) &CurrentPrefs
.pref_IconSizeConstraints
,
940 IDTA_ScalePercentage
, CurrentPrefs
.pref_IconScaleFactor
,
943 d1(KPrintF("%s/%s/%ld: IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
));
946 IconObj
= (Object
*) DoMethod(iInfos
.xii_iinfos
.ii_MainWindowStruct
->ws_WindowTask
->mt_MainObject
,
947 SCCM_IconWin_GetDefIcon
,
953 d1(KPrintF("%s/%s/%ld: IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
));
959 // this is a root window
960 d1(KPrintF("%s/%s/%ld: Root window\n", __FILE__
, __FUNC__
, __LINE__
));
962 IconObj
= FindIconInDeviceWindow(FullPath
,
963 wsIconListLocked
, WindowListLocked
);
965 d1(KPrintF("%s/%s/%ld: IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
));
968 IconObj
= *allocIconObj
= ReadDeviceIconObject(FullPath
);
972 if (IS_VALID_LOCK(oldDir
))
977 FreePathBuffer(FullPath
);
981 d1(KPrintF("%s/%s/%ld: END IconObj=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, IconObj
));
986 // ----------------------------------------------------------
988 void FunctionsGetSettingsFromIconObject(struct IconWindowProperties
*iwp
, Object
*IconObj
)
995 GetAttr(IDTA_ViewModes
, IconObj
, &ViewBy
);
996 GetAttr(IDTA_Flags
, IconObj
, &ddFlags
);
998 iwp
->iwp_Viewmodes
= TranslateViewModesFromIcon(ViewBy
);
1000 d1(KPrintF("%s/%s/%ld: ddFlags=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, ddFlags
));
1002 switch (ddFlags
& DDFLAGS_SHOWMASK
)
1004 case DDFLAGS_SHOWDEFAULT
:
1005 iwp
->iwp_ShowAll
= DDFLAGS_SHOWDEFAULT
;
1007 case DDFLAGS_SHOWICONS
:
1008 iwp
->iwp_ShowAll
= DDFLAGS_SHOWICONS
;
1010 case DDFLAGS_SHOWALL
:
1012 iwp
->iwp_ShowAll
= DDFLAGS_SHOWALL
;
1016 switch (ddFlags
& DDFLAGS_SORTMASK
)
1018 case DDFLAGS_SORTDEFAULT
:
1020 iwp
->iwp_SortOrder
= SortOrder_Default
;
1022 case DDFLAGS_SORTASC
:
1023 iwp
->iwp_SortOrder
= SortOrder_Ascending
;
1025 case DDFLAGS_SORTDESC
:
1026 iwp
->iwp_SortOrder
= SortOrder_Descending
;
1031 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_PATTERNNO", &tt
))
1033 DoMethod(IconObj
, IDTM_GetToolTypeValue
, tt
, &lDummy
);
1034 iwp
->iwp_PatternNumber
= (UWORD
) lDummy
;
1035 d1(KPrintF("%s/%s/%ld: iwp->iwp_PatternNumber=%lu\n", __FILE__
, __FUNC__
, __LINE__
, iwp
->iwp_PatternNumber
));
1039 // determine default pattern number
1040 if (IsViewByIcon(iwp
->iwp_Viewmodes
))
1041 iwp
->iwp_PatternNumber
= PATTERNNR_IconWindowDefault
; // default icon window pattern no.
1043 iwp
->iwp_PatternNumber
= PATTERNNR_TextWindowDefault
; // default text window pattern no.
1048 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_CHECKOVERLAP", &tt
))
1050 DoMethod(IconObj
, IDTM_GetToolTypeValue
, tt
, &lDummy
);
1051 iwp
->iwp_CheckOverlap
= lDummy
;
1052 d1(KPrintF("%s/%s/%ld: iwp_CheckOverlap=%ld\n", __FILE__
, __FUNC__
, __LINE__
, iwp
->iwp_CheckOverlap
));
1056 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_THUMBNAILS", &tt
))
1058 d1(KPrintF("%s/%s/%ld: tt=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, tt
));
1059 while (*tt
&& '=' != *tt
)
1065 if (0 == Stricmp(tt
, "NEVER"))
1066 iwp
->iwp_ThumbnailView
= THUMBNAILS_Never
;
1067 else if (0 == Stricmp(tt
, "ALWAYS"))
1068 iwp
->iwp_ThumbnailView
= THUMBNAILS_Always
;
1069 else if (0 == Stricmp(tt
, "ASDEFAULT"))
1070 iwp
->iwp_ThumbnailView
= THUMBNAILS_AsDefault
;
1072 d1(KPrintF("%s/%s/%ld: iwp->iwp_ThumbnailView=%lu\n", __FILE__
, __FUNC__
, __LINE__
, iwp
->iwp_ThumbnailView
));
1076 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_THUMBNAIL_LIFETIME", &tt
))
1078 DoMethod(IconObj
, IDTM_GetToolTypeValue
, tt
, &lDummy
);
1079 iwp
->iwp_ThumbnailsLifetimeDays
= lDummy
;
1082 iwp
->iwp_NoStatusBar
= FALSE
;
1084 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_NOSTATUSBAR", &tt
))
1086 iwp
->iwp_NoStatusBar
= TRUE
;
1089 iwp
->iwp_NoControlBar
= FALSE
;
1091 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_NOCONTROLBAR", &tt
))
1093 iwp
->iwp_NoControlBar
= TRUE
;
1096 iwp
->iwp_BrowserMode
= FALSE
;
1098 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_BROWSERMODE", &tt
))
1100 iwp
->iwp_BrowserMode
= TRUE
;
1103 GetAttr(IDTA_WinCurrentX
, IconObj
, &lDummy
);
1104 iwp
->iwp_XOffset
= (WORD
) lDummy
;
1106 GetAttr(IDTA_WinCurrentY
, IconObj
, &lDummy
);
1107 iwp
->iwp_YOffset
= (WORD
) lDummy
;
1110 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_ACTIVETRANSPARENCY", &tt
))
1112 DoMethod(IconObj
, IDTM_GetToolTypeValue
, tt
, (ULONG
*) &lDummy
);
1113 iwp
->iwp_OpacityActive
= (UWORD
) lDummy
;
1114 d1(KPrintF("%s/%s/%ld: iwp->iwp_OpacityActive=%lu\n", __FILE__
, __FUNC__
, __LINE__
, iwp
->iwp_OpacityActive
));
1118 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_INACTIVETRANSPARENCY", &tt
))
1120 DoMethod(IconObj
, IDTM_GetToolTypeValue
, tt
, (ULONG
*) &lDummy
);
1121 iwp
->iwp_OpacityInactive
= (UWORD
) lDummy
;
1122 d1(KPrintF("%s/%s/%ld: iwp->iwp_OpacityInactive=%lu\n", __FILE__
, __FUNC__
, __LINE__
, iwp
->iwp_OpacityInactive
));
1126 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_ICONSCALEFACTOR", &tt
))
1128 DoMethod(IconObj
, IDTM_GetToolTypeValue
, tt
, (ULONG
*) &lDummy
);
1129 iwp
->iwp_IconScaleFactor
= lDummy
;
1131 if (iwp
->iwp_IconScaleFactor
< IDTA_ScalePercentage_MIN
)
1132 iwp
->iwp_IconScaleFactor
= IDTA_ScalePercentage_MIN
;
1133 else if (iwp
->iwp_IconScaleFactor
> IDTA_ScalePercentage_MAX
)
1134 iwp
->iwp_IconScaleFactor
= IDTA_ScalePercentage_MAX
;
1136 d1(KPrintF("%s/%s/%ld: iwp_IconScaleFactor=%lu\n", __FILE__
, __FUNC__
, __LINE__
, iwp
->iwp_IconScaleFactor
));
1140 if (DoMethod(IconObj
, IDTM_FindToolType
, "SCALOS_ICONSIZECONSTRAINTS", &tt
))
1142 LONG IconSizeMin
, IconSizeMax
;
1145 d1(KPrintF("%s/%s/%ld: tt=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, tt
));
1146 while (*tt
&& '=' != *tt
)
1149 if (2 == sscanf(tt
, "=%ld,%ld", &long1
, &long2
))
1151 IconSizeMin
= long1
;
1152 IconSizeMax
= long2
;
1153 if ((IconSizeMax
> 128) || (IconSizeMax
< 0))
1154 IconSizeMax
= SHRT_MAX
;
1155 if ((IconSizeMin
< 0) || (IconSizeMin
>= IconSizeMax
))
1158 iwp
->iwp_IconSizeConstraints
.MinX
= iwp
->iwp_IconSizeConstraints
.MinY
= IconSizeMin
;
1159 iwp
->iwp_IconSizeConstraints
.MaxX
= iwp
->iwp_IconSizeConstraints
.MaxY
= IconSizeMax
;
1161 d1(KPrintF("%s/%s/%ld: IconSizeMin=%ld IconSizeMax=%ld\n", __FILE__
, __FUNC__
, __LINE__
, IconSizeMin
, IconSizeMax
));
1165 // ----------------------------------------------------------