5 #include <exec/types.h>
6 #include <graphics/gels.h>
7 #include <graphics/rastport.h>
8 #include <intuition/classes.h>
9 #include <intuition/classusr.h>
10 #include <utility/hooks.h>
11 #include <intuition/gadgetclass.h>
12 #include <workbench/workbench.h>
13 #include <workbench/startup.h>
14 #include <dos/dostags.h>
15 #include <dos/datetime.h>
19 #include <proto/dos.h>
20 #include <proto/exec.h>
21 #include <proto/layers.h>
22 #include <proto/intuition.h>
23 #include <proto/graphics.h>
24 #include <proto/utility.h>
25 #include <proto/iconobject.h>
27 #include <proto/scalos.h>
29 #include <clib/alib_protos.h>
32 #include <datatypes/iconobject.h>
33 #include <scalos/scalos.h>
39 #include "scalos_structures.h"
40 #include "functions.h"
41 #include "Variables.h"
43 //----------------------------------------------------------------------------
45 // local data structures
47 //----------------------------------------------------------------------------
51 static size_t CountToolTypeEntries(CONST_STRPTR
*ToolTypeArray
);
52 static size_t GetToolTypeLength(CONST_STRPTR
*ToolTypeArray
);
53 static STRPTR
*scaFindToolType(STRPTR
*ToolTypeArray
, CONST_STRPTR typeName
);
55 //----------------------------------------------------------------------------
57 LONG
SetToolType(Object
*iconObj
, CONST_STRPTR ToolTypeName
, CONST_STRPTR ToolTypeValue
, BOOL SaveIcon
)
59 LONG Result
= RETURN_OK
;
61 STRPTR
*ttClone
= NULL
;
63 d1(kprintf("%s/%s/%ld: iconObj=%08lx ttName=<%s> ttValue=<%s>\n", \
64 __FILE__
, __FUNC__
, __LINE__
, iconObj
, ToolTypeName
, ToolTypeValue
));
67 STRPTR
*ToolTypeArray
= NULL
;
75 GetAttr(IDTA_ToolTypes
, iconObj
, (APTR
) &ToolTypeArray
);
76 GetAttr(DTA_Name
, iconObj
, (APTR
) &iconName
);
78 d1(kprintf("%s/%s/%ld: ToolTypeArray=%08lx iconName=<%s>\n", \
79 __FILE__
, __FUNC__
, __LINE__
, ToolTypeArray
, iconName
));
81 // ToolTypeArray may be NULL if there are no tooltypes attached to the icon!
83 d1(for (ptt
=ToolTypeArray
; *ptt
; ptt
++)\
84 kprintf("%s/%s/%ld: old ToolType=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, *ptt
));
86 length
= 1 + strlen(ToolTypeName
) + 1 + strlen(ToolTypeValue
);
87 newTT
= (STRPTR
) ScalosAlloc(length
);
91 if (strlen(ToolTypeValue
) > 0)
92 snprintf(newTT
, length
, "%s=%s", ToolTypeName
, ToolTypeValue
);
94 stccpy(newTT
, ToolTypeName
, length
);
96 ttClone
= CloneToolTypeArray((CONST_STRPTR
*) ToolTypeArray
, 1);
100 ptt
= scaFindToolType(ttClone
, ToolTypeName
);
103 // overwrite old tooltype
104 d1(kprintf("%s/%s/%ld: ToolType=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, *ptt
));
109 // append new tooltype
110 for (ptt
=ttClone
; *ptt
; ptt
++)
116 for (ptt
=ttClone
; *ptt
; ptt
++)
117 d1(kprintf("%s/%s/%ld: new ToolType=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, *ptt
));
120 IDTA_ToolTypes
, (IPTR
) ttClone
,
125 Result
= PutIconObjectTags(iconObj
, iconName
,
126 ICONA_NoNewImage
, TRUE
,
139 //----------------------------------------------------------------------------
141 LONG
RemoveToolType(Object
*iconObj
, CONST_STRPTR ToolTypeName
, BOOL SaveIcon
)
143 LONG Result
= RETURN_OK
;
144 STRPTR
*ttClone
= NULL
;
146 d1(kprintf("%s/%s/%ld: iconObj=%08lx ttName=<%s> ttValue=<%s>\n", \
147 __FILE__
, __FUNC__
, __LINE__
, iconObj
, ToolTypeName
, ToolTypeValue
));
150 STRPTR
*ToolTypeArray
= NULL
;
157 GetAttr(IDTA_ToolTypes
, iconObj
, (APTR
) &ToolTypeArray
);
158 GetAttr(DTA_Name
, iconObj
, (APTR
) &iconName
);
160 d1(kprintf("%s/%s/%ld: ToolTypeArray=%08lx iconName=<%s>\n", \
161 __FILE__
, __FUNC__
, __LINE__
, ToolTypeArray
, iconName
));
163 if (NULL
== ToolTypeArray
)
166 for (ptt
=ToolTypeArray
; *ptt
; ptt
++)
167 d1(kprintf("%s/%s/%ld: old ToolType=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, *ptt
));
169 ttClone
= CloneToolTypeArray((CONST_STRPTR
*) ToolTypeArray
, 0);
173 ptt
= scaFindToolType(ttClone
, ToolTypeName
);
176 // old tooltype found - remove it
177 d1(kprintf("%s/%s/%ld: ToolType=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, *ptt
));
186 d1(for (ptt
=ttClone
; *ptt
; ptt
++) \
187 kprintf("%s/%s/%ld: new ToolType=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, *ptt
));
190 IDTA_ToolTypes
, (IPTR
) ttClone
,
195 Result
= PutIconObjectTags(iconObj
, iconName
,
196 ICONA_NoNewImage
, TRUE
,
208 //----------------------------------------------------------------------------
210 static size_t CountToolTypeEntries(CONST_STRPTR
*ToolTypeArray
)
214 for (ttCount
=0; ToolTypeArray
&& ToolTypeArray
[ttCount
]; ttCount
++);
219 //----------------------------------------------------------------------------
221 static size_t GetToolTypeLength(CONST_STRPTR
*ToolTypeArray
)
223 size_t Length
= sizeof(STRPTR
);
225 while (ToolTypeArray
&& *ToolTypeArray
)
227 Length
+= sizeof(STRPTR
) + strlen(*ToolTypeArray
) + 1;
234 //----------------------------------------------------------------------------
236 STRPTR
*CloneToolTypeArray(CONST_STRPTR
*ToolTypeArray
, ULONG AdditionalEntries
)
239 STRPTR
*newTT
, *newTTalloc
;
243 d1(kprintf("%s/%s/%ld: AdditionalEntries=%ld\n", __FILE__
, __FUNC__
, __LINE__
, AdditionalEntries
));
245 ttLength
= GetToolTypeLength(ToolTypeArray
) + AdditionalEntries
* sizeof(STRPTR
);
246 ttCount
= CountToolTypeEntries(ToolTypeArray
);
248 d1(kprintf("%s/%s/%ld: ttLength=%ld ttCount=%ld\n", __FILE__
, __FUNC__
, __LINE__
, ttLength
, ttCount
));
250 newTT
= newTTalloc
= ScalosAlloc(ttLength
);
254 stringSpace
= (STRPTR
) &newTT
[1 + ttCount
+ AdditionalEntries
];
256 d1(kprintf("%s/%s/%ld: newTT=%08lx stringSpace=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, newTT
, stringSpace
));
258 while (ToolTypeArray
&& *ToolTypeArray
)
260 *newTT
= stringSpace
;
262 strcpy(stringSpace
, *ToolTypeArray
);
263 stringSpace
+= strlen(stringSpace
) + 1;
269 while (AdditionalEntries
--)
277 //----------------------------------------------------------------------------
279 static STRPTR
*scaFindToolType(STRPTR
*ToolTypeArray
, CONST_STRPTR typeName
)
281 if (NULL
== ToolTypeArray
)
284 while (*ToolTypeArray
)
286 STRPTR lp
= strchr(*ToolTypeArray
, '=');
294 if (CompEnd
!= *ToolTypeArray
)
295 CompEnd
--; // skip "="
296 while (CompEnd
!= *ToolTypeArray
&& ' ' == *CompEnd
)
297 CompEnd
--; // skip all " " before "="
299 // lp = stpblk(++lp); // skip "=" and trailing blanks
301 CompLen
= CompEnd
- *ToolTypeArray
;
305 CompLen
= strlen(*ToolTypeArray
);
309 if (0 == Strnicmp(*ToolTypeArray
, (STRPTR
) typeName
, CompLen
))
311 return ToolTypeArray
;
320 //----------------------------------------------------------------------------