2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <workbench/icon.h>
9 #include <graphics/gfx.h>
10 #include <proto/arossupport.h>
11 #include "icon_intern.h"
13 /*#define OUTPUT_DATA*/
17 struct NewWindow dd_NewWindow
;
23 STATIC STRPTR
StrDupPooled(APTR pool
, STRPTR str
)
26 if (!str
) return NULL
;
27 newstr
= AllocPooled(pool
,strlen(str
)+1);
28 if (newstr
) strcpy(newstr
,str
);
32 STATIC UBYTE
*MemDupPooled(APTR pool
, UBYTE
*src
, ULONG size
)
36 newmem
= AllocPooled(pool
, size
);
37 if (newmem
) memcpy(newmem
, src
, size
);
42 STATIC
struct Image
*ImageDupPooled(APTR pool
, struct Image
*src
)
46 if (!src
) return NULL
;
48 dest
= (struct Image
*)AllocPooled(pool
,sizeof(struct Image
));
54 int plane_pick
= src
->PlanePick
;
57 dest
->NextImage
= NULL
;
59 /* Calc the size all used planes */
60 plane_size
= RASSIZE(src
->Width
,src
->Height
);
63 if (plane_pick
& 1) data_size
+= plane_size
;
67 if ((dest
->ImageData
= AllocPooled(pool
,data_size
)))
69 memcpy(dest
->ImageData
,src
->ImageData
,data_size
);
71 kprintf("plane_pick = %ld\n",src
->PlanePick
);
72 kprintf("width = %ld\n",src
->Width
);
73 kprintf("height = %ld\n",src
->Height
);
75 for (i
=0;i
<data_size
;i
++)
77 kprintf("0x%02lx,",((unsigned char*)src
->ImageData
)[i
]);
78 if (i
%16 == 15) kprintf("\n");
85 /* Something failed so we fail also */
86 FreePooled(pool
,dest
,sizeof(struct Image
));
91 /*****************************************************************************
94 #include <clib/icon_protos.h>
96 AROS_LH2(struct DiskObject
*, DupDiskObjectA
,
99 AROS_LHA(struct DiskObject
*, icon
, A0
),
100 AROS_LHA(struct TagItem
*, tags
, A1
),
103 struct Library
*, IconBase
, 25, Icon
)
123 *****************************************************************************/
128 struct NativeIcon
*mem
;
129 struct DiskObject
*dobj
;
131 if (!icon
) return NULL
;
133 pool
= CreatePool(0,1024,1024);
134 if (!pool
) return NULL
;
136 /* AROS doesn't need the gfx to be placed in chip memory, so we can use pools */
137 mem
= (struct NativeIcon
*)AllocPooled(pool
, sizeof(struct NativeIcon
));
140 memset(mem
, 0, sizeof(*mem
));
145 /* copy the contents */
148 if (GetTagData(ICONDUPA_JustLoadedFromDisk
, FALSE
, tags
) != FALSE
)
150 struct NativeIcon
*srcnativeicon
;
152 srcnativeicon
= NATIVEICON(icon
);
154 mem
->icon35
= srcnativeicon
->icon35
;
156 /* Clone image data */
158 if (srcnativeicon
->icon35
.img1
.imagedata
)
160 mem
->icon35
.img1
.imagedata
= MemDupPooled(pool
,
161 srcnativeicon
->icon35
.img1
.imagedata
,
162 srcnativeicon
->icon35
.width
* srcnativeicon
->icon35
.height
);
164 if (!mem
->icon35
.img1
.imagedata
) goto fail
;
167 if (srcnativeicon
->icon35
.img2
.imagedata
)
169 mem
->icon35
.img2
.imagedata
= MemDupPooled(pool
,
170 srcnativeicon
->icon35
.img2
.imagedata
,
171 srcnativeicon
->icon35
.width
* srcnativeicon
->icon35
.height
);
173 if (!mem
->icon35
.img2
.imagedata
) goto fail
;
176 /* Clone Image Mask */
178 if (srcnativeicon
->icon35
.img1
.mask
)
180 mem
->icon35
.img1
.mask
= MemDupPooled(pool
,
181 srcnativeicon
->icon35
.img1
.mask
,
182 RASSIZE(srcnativeicon
->icon35
.width
, srcnativeicon
->icon35
.height
));
185 if (srcnativeicon
->icon35
.img2
.mask
)
187 mem
->icon35
.img2
.mask
= MemDupPooled(pool
,
188 srcnativeicon
->icon35
.img2
.mask
,
189 RASSIZE(srcnativeicon
->icon35
.width
, srcnativeicon
->icon35
.height
));
194 if (srcnativeicon
->icon35
.img1
.palette
)
196 mem
->icon35
.img1
.palette
= MemDupPooled(pool
,
197 srcnativeicon
->icon35
.img1
.palette
,
198 srcnativeicon
->icon35
.img1
.numcolors
* sizeof(struct ColorRegister
));
199 if (!mem
->icon35
.img1
.palette
) goto fail
;
202 if (srcnativeicon
->icon35
.img2
.palette
&& (srcnativeicon
->icon35
.img2
.flags
& IMAGE35F_HASPALETTE
))
204 mem
->icon35
.img2
.palette
= MemDupPooled(pool
,
205 srcnativeicon
->icon35
.img2
.palette
,
206 srcnativeicon
->icon35
.img2
.numcolors
* sizeof(struct ColorRegister
));
207 if (!mem
->icon35
.img2
.palette
) goto fail
;
209 else if (srcnativeicon
->icon35
.img1
.palette
)
211 /* Both images use same palette which is kept in memory only once */
212 mem
->icon35
.img2
.palette
= mem
->icon35
.img1
.palette
;
215 /* Clone PNGIcon data */
217 mem
->iconPNG
= srcnativeicon
->iconPNG
;
219 if (srcnativeicon
->iconPNG
.filebuffer
)
221 mem
->iconPNG
.filebuffer
= MemDupPooled(pool
,
222 srcnativeicon
->iconPNG
.filebuffer
,
223 srcnativeicon
->iconPNG
.filebuffersize
);
225 if (!mem
->iconPNG
.filebuffer
) goto fail
;
228 if (srcnativeicon
->iconPNG
.img1
)
230 mem
->iconPNG
.img1
= MemDupPooled(pool
,
231 srcnativeicon
->iconPNG
.img1
,
232 srcnativeicon
->iconPNG
.width
* srcnativeicon
->iconPNG
.height
* sizeof(ULONG
));
234 if (!mem
->iconPNG
.img1
) goto fail
;
237 if (srcnativeicon
->iconPNG
.img2
)
239 mem
->iconPNG
.img2
= MemDupPooled(pool
,
240 srcnativeicon
->iconPNG
.img2
,
241 srcnativeicon
->iconPNG
.width
* srcnativeicon
->iconPNG
.height
* sizeof(ULONG
));
243 if (!mem
->iconPNG
.img2
) goto fail
;
246 } /* if (GetTagData(ICONDUPA_JustLoadedFromDisk, FALSE, tags) != FALSE) */
249 kprintf("gadgetwidth = %ld\ngadgetheight = %ld\n",dobj
->do_Gadget
.Width
,dobj
->do_Gadget
.Height
);
252 /* and now the pointers and the rest */
253 #warning TODO: check for errors here
255 if (dobj
->do_DefaultTool
)
257 dobj
->do_DefaultTool
= StrDupPooled(pool
,icon
->do_DefaultTool
);
258 if (!dobj
->do_DefaultTool
) goto fail
;
261 if (dobj
->do_ToolWindow
)
263 dobj
->do_ToolWindow
= StrDupPooled(pool
,icon
->do_ToolWindow
);
264 if (!dobj
->do_ToolWindow
) goto fail
;
267 if (icon
->do_DrawerData
)
271 dobj
->do_DrawerData
= AllocPooled(pool
, sizeof(struct DrawerData
));
272 if (!dobj
->do_DrawerData
) goto fail
;
274 if (((LONG
)icon
->do_Gadget
.UserData
> 0) &&
275 ((LONG
)icon
->do_Gadget
.UserData
<= WB_DISKREVISION
))
277 size
= sizeof(struct DrawerData
);
281 size
= sizeof(struct OldDrawerData
);
284 memset(dobj
->do_DrawerData
, 0, sizeof(struct DrawerData
));
285 memcpy(dobj
->do_DrawerData
, icon
->do_DrawerData
, size
);
288 /* Duplicate the image data */
290 if (icon
->do_Gadget
.GadgetRender
)
292 dobj
->do_Gadget
.GadgetRender
= ImageDupPooled(pool
, (struct Image
*)icon
->do_Gadget
.GadgetRender
);
293 if (!dobj
->do_Gadget
.GadgetRender
) goto fail
;
296 if (icon
->do_Gadget
.SelectRender
)
298 dobj
->do_Gadget
.SelectRender
= ImageDupPooled(pool
, (struct Image
*)icon
->do_Gadget
.SelectRender
);
299 if (!dobj
->do_Gadget
.SelectRender
) goto fail
;
302 /* Duplicate the tool types */
303 if (icon
->do_ToolTypes
)
306 /* Get number of tool types */
307 for (num_tts
= 0;icon
->do_ToolTypes
[num_tts
];num_tts
++);
309 if ((dobj
->do_ToolTypes
= (STRPTR
*)AllocPooled(pool
,sizeof(char*)*(num_tts
+1))))
312 for (i
=0;i
<num_tts
;i
++)
314 dobj
->do_ToolTypes
[i
] = StrDupPooled(pool
,icon
->do_ToolTypes
[i
]);
315 if (!dobj
->do_ToolTypes
[i
]) goto fail
;
317 dobj
->do_ToolTypes
[i
] = NULL
;
325 AddIconToList(mem
, LB(IconBase
));
334 } /* FreeDiskObject */